meancrazy / linqpadodata4 Goto Github PK
View Code? Open in Web Editor NEWOData v4 LINQPad dynamic driver
License: MIT License
OData v4 LINQPad dynamic driver
License: MIT License
I'm unable to add a new connection pointing to an OData 4 endpoint using Windows Authentication. The driver fails with a WebException: Failed to access the metadata document.
After debugging the driver, it appears that the issue is at
. The web request is created with no credentials.Also at
LINQPadOData4/OData4DynamicDriver.cs
Line 148 in 5ef3628
Here is an example of the fix (code not tested):
var customResolver = new XmlSecureResolver(new XmlUrlResolver(), metadataUri.ToString())
{
Credentials = GetCredentials(cxInfo)
};
using (var reader = XmlReader.Create(metadataUri.ToString(), new XmlReaderSettings() { XmlResolver = customResolver }))
{
}
When using this extension I receive an error "The SSL connection could not be established, see inner exception". We recently moved from Odata v3 to Odata v4. It worked fine with Odata v3. I can access the service in other tools like Postman without issue. Here is the exception from the LinqPad log.
6.13.13 (X64) 2021-04-27T09:29:22.3089468-04:00 Error opening DataContext
RemoteException - WebException - The SSL connection could not be established, see inner exception.
Source=OData4.LINQPadDriver
-OData4.LINQPadDriver.Templates.ODataT4CodeGenerator+CodeGenerationContext System.IO.Stream GetEdmxStreamFromUri(System.Uri, OData4.LINQPadDriver.ConnectionProperties) offset: 0x11C
-OData4.LINQPadDriver.Templates.ODataT4CodeGenerator+CodeGenerationContext System.String GetEdmxStringFromMetadataPath(System.Uri, OData4.LINQPadDriver.ConnectionProperties) offset: 0x2
-OData4.LINQPadDriver.Templates.ODataT4CodeGenerator System.String TransformText() offset: 0x63
-OData4.LINQPadDriver.DynamicDriver System.Collections.Generic.List`1[LINQPad.Extensibility.DataContext.ExplorerItem] GetSchemaAndBuildAssembly(LINQPad.Extensibility.DataContext.IConnectionInfo, System.Reflection.AssemblyName, System.String ByRef, System.String ByRef) offset: 0x43
-LINQPad.Extensibility.DataContext.DynamicDataContextDriver LINQPad.Extensibility.DataContext.DynamicSchemaResult GetSchemaAndBuildAssemblyInternal(System.String, System.String) offset: 0x28
INNER: HttpRequestException - The SSL connection could not be established, see inner exception.
Source=System.Net.Http
-System.Net.Http.ConnectHelper+<EstablishSslConnectionAsyncCore>d__4 Void MoveNext() offset: 0x138
-System.Runtime.ExceptionServices.ExceptionDispatchInfo Void Throw() offset: 0x11
-System.Runtime.CompilerServices.TaskAwaiter Void ThrowForNonSuccess(System.Threading.Tasks.Task) offset: 0x26
-System.Runtime.CompilerServices.TaskAwaiter Void HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) offset: 0x28
-System.Threading.Tasks.ValueTask`1 TResult get_Result() offset: 0x1B
-System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1+ConfiguredValueTaskAwaiter TResult GetResult() offset: 0x0
-System.Net.Http.HttpConnectionPool+<ConnectAsync>d__82 Void MoveNext() offset: 0x344
-System.Runtime.ExceptionServices.ExceptionDispatchInfo Void Throw() offset: 0x11
-System.Runtime.CompilerServices.TaskAwaiter Void ThrowForNonSuccess(System.Threading.Tasks.Task) offset: 0x26
-System.Runtime.CompilerServices.TaskAwaiter Void HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) offset: 0x28
-System.Runtime.CompilerServices.TaskAwaiter Void ValidateEnd(System.Threading.Tasks.Task) offset: 0x8
-System.Threading.Tasks.ValueTask`1 TResult get_Result() offset: 0x1B
-System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1+ConfiguredValueTaskAwaiter TResult GetResult() offset: 0x0
-System.Net.Http.HttpConnectionPool+<CreateHttp11ConnectionAsync>d__86 Void MoveNext() offset: 0x8F
-System.Runtime.ExceptionServices.ExceptionDispatchInfo Void Throw() offset: 0x11
-System.Runtime.CompilerServices.TaskAwaiter Void ThrowForNonSuccess(System.Threading.Tasks.Task) offset: 0x26
-System.Runtime.CompilerServices.TaskAwaiter Void HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) offset: 0x28
-System.Runtime.CompilerServices.TaskAwaiter Void ValidateEnd(System.Threading.Tasks.Task) offset: 0x8
-System.Threading.Tasks.ValueTask`1 TResult get_Result() offset: 0x1B
-System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1+ConfiguredValueTaskAwaiter TResult GetResult() offset: 0x0
-System.Net.Http.HttpConnectionPool+<GetHttpConnectionAsync>d__67 Void MoveNext() offset: 0x13E
-System.Runtime.ExceptionServices.ExceptionDispatchInfo Void Throw() offset: 0x11
-System.Runtime.CompilerServices.TaskAwaiter Void ThrowForNonSuccess(System.Threading.Tasks.Task) offset: 0x26
-System.Runtime.CompilerServices.TaskAwaiter Void HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) offset: 0x28
-System.Runtime.CompilerServices.TaskAwaiter Void ValidateEnd(System.Threading.Tasks.Task) offset: 0x8
-System.Threading.Tasks.ValueTask`1 TResult get_Result() offset: 0x1B
-System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1+ConfiguredValueTaskAwaiter TResult GetResult() offset: 0x0
-System.Net.Http.HttpConnectionPool+<SendWithRetryAsync>d__72 Void MoveNext() offset: 0x91
-System.Runtime.ExceptionServices.ExceptionDispatchInfo Void Throw() offset: 0x11
-System.Runtime.CompilerServices.TaskAwaiter Void ThrowForNonSuccess(System.Threading.Tasks.Task) offset: 0x26
-System.Runtime.CompilerServices.TaskAwaiter Void HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) offset: 0x28
-System.Threading.Tasks.ValueTask`1 TResult get_Result() offset: 0x1B
-System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1+ConfiguredValueTaskAwaiter TResult GetResult() offset: 0x0
-System.Net.Http.RedirectHandler+<SendAsync>d__4 Void MoveNext() offset: 0x94
-System.Runtime.ExceptionServices.ExceptionDispatchInfo Void Throw() offset: 0x11
-System.Runtime.CompilerServices.TaskAwaiter Void ThrowForNonSuccess(System.Threading.Tasks.Task) offset: 0x26
-System.Runtime.CompilerServices.TaskAwaiter Void HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) offset: 0x28
-System.Threading.Tasks.ValueTask`1 TResult get_Result() offset: 0x1B
-System.Runtime.CompilerServices.ValueTaskAwaiter`1 TResult GetResult() offset: 0x0
-System.Net.Http.HttpMessageHandlerStage System.Net.Http.HttpResponseMessage Send(System.Net.Http.HttpRequestMessage, System.Threading.CancellationToken) offset: 0x12
-System.Net.Http.SocketsHttpHandler System.Net.Http.HttpResponseMessage Send(System.Net.Http.HttpRequestMessage, System.Threading.CancellationToken) offset: 0x84
-System.Net.Http.HttpClientHandler System.Net.Http.HttpResponseMessage Send(System.Net.Http.HttpRequestMessage, System.Threading.CancellationToken) offset: 0xF
-System.Net.Http.HttpMessageInvoker System.Net.Http.HttpResponseMessage Send(System.Net.Http.HttpRequestMessage, System.Threading.CancellationToken) offset: 0x6B
-System.Net.Http.HttpClient+<SendAsyncCore>d__85 Void MoveNext() offset: 0x14B
-System.Runtime.ExceptionServices.ExceptionDispatchInfo Void Throw() offset: 0x11
-System.Runtime.CompilerServices.TaskAwaiter Void ThrowForNonSuccess(System.Threading.Tasks.Task) offset: 0x26
-System.Runtime.CompilerServices.TaskAwaiter Void HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) offset: 0x28
-System.Threading.Tasks.ValueTask`1 TResult get_Result() offset: 0x1B
-System.Runtime.CompilerServices.ValueTaskAwaiter`1 TResult GetResult() offset: 0x0
-System.Net.Http.HttpClient System.Net.Http.HttpResponseMessage Send(System.Net.Http.HttpRequestMessage, System.Net.Http.HttpCompletionOption, System.Threading.CancellationToken) offset: 0x1B
-System.Net.HttpWebRequest+<SendRequest>d__196 Void MoveNext() offset: 0x1A8
-System.Runtime.ExceptionServices.ExceptionDispatchInfo Void Throw() offset: 0x11
-System.Runtime.CompilerServices.TaskAwaiter Void ThrowForNonSuccess(System.Threading.Tasks.Task) offset: 0x26
-System.Runtime.CompilerServices.TaskAwaiter Void HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) offset: 0x28
-System.Runtime.CompilerServices.TaskAwaiter`1 TResult GetResult() offset: 0x0
-System.Net.HttpWebRequest System.Net.WebResponse GetResponse() offset: 0x18
INNER: AuthenticationException - The remote certificate was rejected by the provided RemoteCertificateValidationCallback.
Source=System.Private.CoreLib
-System.Runtime.ExceptionServices.ExceptionDispatchInfo Void Throw() offset: 0x11
-System.Net.Security.SslStream Void SendAuthResetSignal(System.Net.Security.ProtocolToken, System.Runtime.ExceptionServices.ExceptionDispatchInfo) offset: 0x35
-System.Net.Security.SslStream+<ForceAuthenticationAsync>d__171`1 Void MoveNext() offset: 0x5A3
-System.Runtime.ExceptionServices.ExceptionDispatchInfo Void Throw() offset: 0x11
-System.Runtime.CompilerServices.TaskAwaiter Void ThrowForNonSuccess(System.Threading.Tasks.Task) offset: 0x26
-System.Runtime.CompilerServices.TaskAwaiter Void HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) offset: 0x28
-System.Runtime.CompilerServices.TaskAwaiter Void GetResult() offset: 0x0
-System.Net.Security.SslStream System.Threading.Tasks.Task ProcessAuthentication(Boolean, Boolean, System.Threading.CancellationToken) offset: 0x63
-System.Net.Security.SslStream Void AuthenticateAsClient(System.Net.Security.SslClientAuthenticationOptions) offset: 0x39
-System.Net.Http.ConnectHelper+<EstablishSslConnectionAsyncCore>d__4 Void MoveNext() offset: 0xD0
Source=System.Private.CoreLib
-System.Runtime.ExceptionServices.ExceptionDispatchInfo Void Throw() offset: 0x11
-System.Runtime.CompilerServices.TaskAwaiter Void ThrowForNonSuccess(System.Threading.Tasks.Task) offset: 0x27
-System.Runtime.CompilerServices.TaskAwaiter Void HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) offset: 0x28
-System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter TResult GetResult() offset: 0xB
-LINQPad.DataContextManager+d__31 Void MoveNext() offset: 0x58D
First Chance Data:
-System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() offset=0x11
please add support for LinqPad configured proxy
Hello,
Any plan to upgrade your driver with Microsoft.OData 8 ?
I understand we can use basic auth from the closed issue 20. Is it possible to use Bearer Tokens similar to Postman, where we can set the bearer token?
The issue (found in v1.0.3.7) is that when you run Fiddler to debug your OData 4 queries, the system web proxy is ignored. Even if you check the "Use LINQPad web proxy" checkbox in the advanced properties, it's still ignored. You need to manually fill the info about the proxy (for fiddler, it's usually http://localhost:8888).
This is related to LINQPad.Util.GetWebProxy() that seems to be ignoring WebRequest.GetSystemWebProxy() (It may be a good idea to ask @albahari about the LINQPad utility method).
There is a workaround, re-register the proxy in the SendingRequest2 event:
this.SendingRequest2 += (s, e) =>
{
((HttpWebRequestMessage)e.RequestMessage).HttpWebRequest.Proxy = WebRequest.GetSystemWebProxy();
};
It would be nice if the driver would do it for us in the CustomizedRequestMessage implementation.
Swap the TextBox for a PasswordBox?
The service I connect to requires certificate based auth. I'd love to see support for this auth scenario in this!
Thanks,
Rich
Unsupported or illegal Accept header value: text/plain != [**application/json;**odata.metadata=minimal,
An option to accept invalid certificates would be very useful for test environments.
Thinking about something like this:
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => { return true; };
MTLS authentication would be very useful to have, as many corporate back-ends use it.
At least for the localhost, but preferably as an option for all sites.
Many sites use self-signed or otherwise invalid certificates while testing. This already exists for older version, see this discussion.
Hello,
Great job,
But could you implement the custom headers feature like you did in the 1.3.0.8 ?
It's very usefull to authentify with a single token
Thanks
Any plans to support the newer OData libraries?
Hi,
The OData 4 driver doesn't seem to play well with lprun.exe. When querying an OData 4 source and using lprun.exe to run the script, there's always an error. I'm using LINQPad v5.10.00 with the driver v1.0.3.4.
I used the following simple script:
var x = this.MyEntities.ToArray();
and it produced the following error:
D:\apps\LINQPad5>lprun.exe "C:\Users\maboivin\Documents\LINQPad Queries\test.linq" NullReferenceException: Object reference not set to an instance of an object. at OData4.OData4DynamicDriver.<>c__DisplayClass19_0.<InitializeContext>b__1(Object s, SendingRequest2EventArgs e) at Microsoft.OData.Client.DataServiceContext.FireSendingRequest2(SendingRequest2EventArgs eventArgs) at Microsoft.OData.Client.ODataRequestMessageWrapper.FireSendingRequest2(Descriptor descriptor) at Microsoft.OData.Client.DataServiceRequest.CreateExecuteResult(Object source, DataServiceContext context, AsyncCallback callback, Object state, String method) at Microsoft.OData.Client.DataServiceRequest.Execute[TElement](DataServiceContext context, QueryComponents queryComponents) at Microsoft.OData.Client.DataServiceQuery`1.Execute() at Microsoft.OData.Client.DataServiceQuery`1.GetEnumerator() at System.Linq.Buffer`1..ctor(IEnumerable`1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) at UserQuery in C:\Users\maboivin\Documents\LINQPad Queries\test.linq:line 1 at LINQPad.ExecutionModel.ClrQueryRunner.Run() at LINQPad.ExecutionModel.Server.RunQuery(QueryRunner runner)
From LINQPad not able to authorize to OData. Using OData basic authorization.
LINQPad driver:
Name: OData 4
Version: 1.0.1.0
Author: Dimtrii Smirnov
OData endpoint: Microsoft.AspNet.OData v6.1.0(Latest at 23/11/2017)
LINQPad 5(Free Edition) v5.26.01
Custom AuthorizeAttribute is created:
public class ODataBasicAuthorizeAttribute : System.Web.Http.AuthorizeAttribute
{
public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext)
{
if (actionContext.Request.Headers.Authorization == null || actionContext.Request.Headers.Authorization.Scheme != "Basic")
{
}
...
}
From LINQPad I have connection to OData endpoint and I'm able to see the table names:
Credentials are entered and pressing OK button:
In OData endpoint custom class: ODataBasicAuthorizeAttribute
, method: OnAuthorization
,actionContext.Request.Headers.Authorization
should contain credentials that we entered from Login window(LINQPad) in screenshot.
In OData endpoint custom class: ODataBasicAuthorizeAttribute
, method: OnAuthorization
,actionContext.Request.Headers.Authorization
value is null
In UI code there is functionality to select the type of authorization(Basic), but this choice is not shown in Login window in LINQPad:
LINQPadOData4/UI/ConnectionDialog.xaml
Line 26 in d07ecbf
When I expand a newly added connection I get a Populating message that simply goes away after a few seconds. When I hover over the connection I get an error.
Error: EdmParseException - Encountered the following errors when parsing the EDMX document:
XmlError: For security reasons DTD is prohibited in this XML document. To enable DTD processing set the DtdProcessing property on XmlReaderSettings to Parse and pass the settings into XmlReader.Create method. : (0, 0)
Linqpad 5.10.00
driver version 1.0.3.7 (869742f)
Cannot compile typed context: { expected (line 12))
The above error shows when adding an OData v4 uri to LinqPad5
The actual Driver does not work with a proxy.
I made some fixes in the code that it worked for me. in the files CodeGenerationContext.cs and OData4DynamicDriver.cs.
I zipped my project as an attachment.
LINQPadOData4-1.0.0.0_forProxy.zip
I have two entities defined, Product and Supplier and a one-to-many relationship from Product to Supplier Unless I am misunderstanding the LinqPad UI, the driver never fetches the Supplier for a product. Is this supported?
Dynamic properties support has been added to the OData client 7.7.0, See this blog post for more details.
To support this new feature:
Microsoft.OData.Client
dependency needs to be updated to the latest version (7.9.0).ODataT4CodeGenerator
needs to be updated to the one in the OData connected service which will give access to set a new property called EmitContainerPropertyAttribute
to true
.On a side note, I was able to make it work by looking at the current code and removing the dependency on the FilesManager
from the new ODataT4CodeGenerator
from the OData connected service.
Do you think it's something that could be added for the next version of the driver?
Hello,
I use your odata v4 driver (1.0.3.8) every day.
And I keep linqpad 5 only because your driver is only available on that version
Thanks !
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.