2011-01-27 48 views
4

私は本当にここの誰かが助けることを望んでいます。 .NETの専門家ではなく、WebサービスやSSL /セキュリティの問題についてはほとんど経験がないと言って、私の質問に先立って説明します。"基底の接続が閉じられました:予期しないエラーが送信で発生しました。" (VB .NETクライアントからJava/Apache SSLで暗号化されたWebサービス)

私は、VB .NETコンソールアプリケーションを作成して、Apacheサーバー上でホストされているJavaベースのWebサービスを使用しようとしています。 SSL経由で通信が行われています。クライアント証明書が必要(Webサービスプロバイダによって提供される)で、基本認証(ユーザ名/パスワード)もサービスを使用するために必要です。

提供されたPFXファイルから(certmgr.mgrを使用して)証明書をインストールし、個人用ストアと信頼済み​​ルートストアの両方に証明書を格納します。私は強力な暗号化(すべてのデフォルトを使用)のチェックボックスをオフにしませんでした。

提供されたWSDLファイルを使用してサービスのプロキシクラスを作成しました。サーバーに存在するWSDLが正しくなく、.NETでの初期バインディングに使用できませんでした。私は "SVCUTIL * .wsdl/language:VB"を使ってプロキシクラスを作成しました。 「?:// Webサービス-URL WSDLのhttps」:

サービスから公開されているメソッドのいずれかを呼び出すしようとしたとき、私は次のエラーを取得していますへのHTTPリクエストをしながら

エラーが発生しました。これは、HTTPSの場合、サーバー証明書がHTTP.SYSで正しく構成されていないためです。これは、クライアントとサーバー間のセキュリティバインディングの不一致によっても発生する可能性があります。

私は例外のスナップショットからのInnerExceptionを見れば、私は以下を参照してください。

基になる接続が閉じられました:予期しないエラーが送信時に発生しました。ここで

は、私は、クライアントを初期化し、Webサービスに接続するために使用したコードは次のとおりです。

'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() 

私も、私は、Webサービスに接続し、すべての公開されたメソッドを表示することができことを言及する必要がありますFirefoxとIEを使用します。

私はインターネットで援助を求めています。人々のために働いたクイックフィックスのほとんどは助けられていません。私はバインディング設定で遊んだことがありますが、これは "匿名"ユーザーアカウントを使用してWebサービスに接続できないという様々なエラーが発生しただけです。

私は本当に迷っています。すべてのヒントや助けをいただければ幸いです。

ありがとうございます。

+0

サーバーのSSLログにアクセスできますか?サーバー側から確認してください。ローカルでSSLを使用してWebServerをインストールし、実サーバと同様の設定を行い、コードを使ってテストすることもできます。 –

答えて

0

あなたのバインディングは複雑すぎるようです(証明書を設定してください)。)

てみてください、クラスとしてこれを作成します。

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 

エンドクラス

を次に、以下のようにWSを呼び出す:

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) 

を私はビジュアルで私のPCにはありませんよスタジオですので、上記のコードに間違いがある場合はお知らせください。

関連する問題