Tuesday, September 12, 2017

Ignore SSL Errors when generating OData Client

Leave a Comment

I am trying to generate client code for an OData v4 service using Visual Studio. My service is running on a server that doesn't have a DNS name, and is using a self-signed certificate for HTTPS. My service is not avaiable over HTTP.

When I run the OData Client Code Generator T4 template, I get the SSL Error at the bottom of this post. When I attempt to add the service via the 'Add Connected Service' context menu, I get an error saying it could not connect.

I believe VS is not connecting to my service because the SSL Certificate doesn't match the domain name of the URL, since the server is being accessed via IP Address instead of by domain name. If this were a client program, I could write my own certificate validation routine, overriding the existing policy. Since this code is running in Visual Studio, however, I do not have access to the runtime (I think).

Surely I am not the first person to come up against this. How do you generate an OData Client when your service is only available via IP Address?

Detailed error:

Severity    Code    Description Project File    Line    Suppression State Error       Running transformation: System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.    at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)    at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)    at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)    at System.Net.TlsStream.CallProcessAuthentication(Object state)    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)    at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)    at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)    at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size)    at System.Net.ConnectStream.WriteHeaders(Boolean async)    --- End of inner exception stack trace ---    at Microsoft.VisualStudio.TextTemplatingCB56359812AF85B717EE86D198C095A18F392F5ED334B1B5D270CD3394D2871D814F7AE052FF43EC12182D14B978B90A2434B91A696421B885CA34564683123A.GeneratedTextTransformation.CodeGenerationContext.GetEdmxStreamFromUri(Uri metadataUri) in :line 972    at Microsoft.VisualStudio.TextTemplatingCB56359812AF85B717EE86D198C095A18F392F5ED334B1B5D270CD3394D2871D814F7AE052FF43EC12182D14B978B90A2434B91A696421B885CA34564683123A.GeneratedTextTransformation.CodeGenerationContext.GetEdmxStringFromMetadataPath(Uri metadataUri) in :line 935    at Microsoft.VisualStudio.TextTemplatingCB56359812AF85B717EE86D198C095A18F392F5ED334B1B5D270CD3394D2871D814F7AE052FF43EC12182D14B978B90A2434B91A696421B885CA34564683123A.GeneratedTextTransformation.CodeGenerationContext..ctor(Uri metadataUri, String namespacePrefix) in :line 547    at Microsoft.VisualStudio.TextTemplatingCB56359812AF85B717EE86D198C095A18F392F5ED334B1B5D270CD3394D2871D814F7AE052FF43EC12182D14B978B90A2434B91A696421B885CA34564683123A.GeneratedTextTransformation.TransformText() in :line 67         972  

My OData Service URI (from the T4 template):

public const string MetadataDocumentUri = "https://10.144.128.44/mgmt/odata/$metadata";

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment