开发者

"The underlying connection was closed: An unexpected error occurred on a send." (VB .NET client to Java/Apache SSL-encrypted web service)

I am really hoping that someone here can help. Let me also preface my question by saying that I am not a .NET expert and have very little experience with web services and SSL/security issues.

I am trying to create a VB .NET console application to consume a Java-based web service hosted on an Apache server. Communication is taking place over SSL. A client certificate is required (provided by web service providers) and basic authentication (username/password) is also required to consume the service.

In installed the certificate (using certmgr.mgr) from a provided PFX file and h开发者_如何转开发ave the certificate stored in both my Personal store and Trusted Root store. I did not check off any checkboxes for strong encryption (used defaults for everything).

I created a proxy class for the service using a provided WSDL file. The WSDL that resides on their server is not correct and could not be used for early binding in .NET. I created the proxy class using "SVCUTIL *.wsdl /language:VB".

I am getting the following error when trying to call one of the exposed methods from the service:

An error occurred while making the HTTP request to "https://webservice-url?WSDL". This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server.

If I look at the InnerException from the Exception snapshot, I see the following:

The underlying connection was closed: An unexpected error occurred on a send.

Here is the code that I've used to initialize the client and connect to the web service:

'Override server certificate callback
    Dim oCertOverride As New CertificateOverride
    ServicePointManager.ServerCertificateValidationCallback = _
             AddressOf oCertOverride.RemoteCertificateValidationCallback

    'Set WS binding
    Dim binding As WSHttpBinding = New WSHttpBinding
    binding.Security.Mode = SecurityMode.Transport
    binding.Security.Transport.ClientCredentialType = _
            HttpClientCredentialType.Certificate

    'Set endpoint address
    Dim address As EndpointAddress = _
         New EndpointAddress("https://webservice-url?WSDL")

    'Create web service client
    Dim ws As wsclient = New wsclient(binding, address)

    'Set web service client certificate
    ws.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser, _
               StoreName.My, X509FindType.FindBySubjectName, "cert-subject-name")

    'Set username and password for server authentication
    ws.ClientCredentials.UserName.UserName = "username"
    ws.ClientCredentials.UserName.Password = "password"

    'Make test call to web service
    ws.HelloWord()

I should also mention that I can connect to the web service and view all exposed methods using Firefox and IE.

I've been scouring the Internet for help. Most of the quick fixes that have worked for people have not helped. I've played around with the binding settings but that has only resulted in various errors about being unable to connect to the web service using the "Anonymous" user account.

I'm really at a loss. Any tips or help would be greatly appreciated.

Thank you for your time.


Your binding seems over complicated (with the setting the certificate.)

Try, create this as a class:

Imports System.ServiceModel

Public Class MyBinding

Public Property _Binder As BasicHttpBinding

Public Sub New(ByVal BinderName As String)

    _Binder = New BasicHttpBinding()
    _Binder.Name = BinderName

    _Binder.CloseTimeout = TimeSpan.FromMinutes(10)
    _Binder.OpenTimeout = TimeSpan.FromMinutes(10)
    _Binder.ReceiveTimeout = TimeSpan.FromMinutes(10)
    _Binder.SendTimeout = TimeSpan.FromMinutes(10)
    _Binder.AllowCookies = False
    _Binder.BypassProxyOnLocal = False
    _Binder.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard
    _Binder.MaxBufferSize = 655360
    _Binder.MaxBufferPoolSize = 655360
    _Binder.MaxReceivedMessageSize = 655360
    _Binder.MessageEncoding = WSMessageEncoding.Text
    _Binder.TextEncoding = System.Text.Encoding.UTF8
    _Binder.TransferMode = TransferMode.Buffered
    _Binder.UseDefaultWebProxy = True

    _Binder.ReaderQuotas.MaxDepth = 32
    _Binder.ReaderQuotas.MaxStringContentLength = 8192
    _Binder.ReaderQuotas.MaxArrayLength = 655360
    _Binder.ReaderQuotas.MaxBytesPerRead = 4096
    _Binder.ReaderQuotas.MaxNameTableCharCount = 16384

    _Binder.Security.Transport.ClientCredentialType = HttpClientCredentialType.None
    _Binder.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None
    _Binder.Security.Transport.Realm = ""
    _Binder.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName
    _Binder.Security.Message.AlgorithmSuite = Security.SecurityAlgorithmSuite.Default
    _Binder.Security.Mode = BasicHttpSecurityMode.Transport

    System.Net.ServicePointManager.Expect100Continue = False

End Sub

End Class

Then, call the WS as follows:

Dim binding As New MyBinding("some_name")

'Set endpoint address
Dim address As EndpointAddress = _
     New EndpointAddress("https://webservice-url?WSDL")

'Create web service client
Dim ws As wsclient = New wsclient(binding._Binder, address)

I'm not on my PC with Visual Studio, so if there's a mistake in the code above, please let me know and I'll check.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜