0

自己署名SSLを使用してWCFサービスをセットアップしようとしています。

HTTPSを参照すると、メタデータが表示され、サービス参照を作成できます。

https://wserver:442/service1.svc ただし、例外がスローされます。そのメッセージを受け入れることができるエンドポイントをリッスンしていませんでした。

wserverは私のサーバーの名前ですが、どこにも使用していないので、どこから取得しているのかわかりませんか?

私のサーバーWebhost.config(おそらく問題があると思います)は次のとおりです。

<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="Binding1">
          <security mode="TransportWithMessageCredential">
            <message clientCredentialType="UserName"/>
          </security>
        </binding>
      </wsHttpBinding>

    </bindings>
    <services>
      <service behaviorConfiguration="ServiceBehavior" name="AutoSenderWCFService.AutoSenderService">
        <endpoint binding="wsHttpBinding" bindingConfiguration="Binding1"
          contract="AutoSenderWCFService.IService1" />
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceCredentials>

            <userNameAuthentication userNamePasswordValidationMode="Custom"
              customUserNamePasswordValidatorType="AutoSenderWCFService.MyValidator, AutoSenderWCFService"/>

          </serviceCredentials>

          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

それとも、自己署名SSLを間違えたのでしょうか。

私のクライアントサイドは次のとおりです。

    private void button1_Click(object sender, EventArgs e)
    {

        ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
        client.ClientCredentials.UserName.UserName = "test";
        client.ClientCredentials.UserName.Password = "testPassword";            
        ServiceReference1.Contact[] test = client.GetDrivers();

    }
}
4

2 に答える 2

0

これが発生する理由はいくつかあります。443で実行されるデフォルトのhttpsがあるため、サービスのhttpsにポート442を使用しています。

ポート442でのhttpsリスニングに関するマッピングを実行しましたか?以下に示すように、netshコマンドを使用してこれを行うことができます。

C:\> netsh http add sslcert ipport=0.0.0.0:442 certhash=6797aea29440de9389bc636e15a35b741d8c22a3 appid={2e80948d-9ae6-42c9-ad33-294929333965}

証明書ハッシュは拇印IDである必要があり、appidはassembly.csファイルに含まれるWCFプロジェクトdllのハッシュIDです。それ以外の場合は、プロジェクトをビルドする前に作成して含めます。

次に、mexエンドポイントを定義します。これを削除して、serviceMetaData要素を次のように変更できますhttpsGetEnabled ="true"httpGetEnabled="false"

次に、サービスページを参照して、問題がないかどうかを確認してください。

次に、クライアントコードで、WCFサービスの呼び出しを呼び出す前に、次の手順を実行して、証明書の検証チェックをバイパスする必要があります。

    System.Net.ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, error) =>
                                                                             {
                                                                                 return true;
                                                                             };

上記のコードを使用する理由は、自己署名証明書を使用しているためです。信頼できる機関によって発行された証明書がある場合は、クライアントアプリに上記のコードを含める必要はありません。

于 2012-05-18T14:47:56.530 に答える
0

上記のように、サーバー側のWeb.ConfigファイルのWCFサービスでHTTPSEnabledプロパティとHTTPEnabledプロパティを変更しました。「...でリッスンしているエンドポイントがありませんでした」という問題を発行しなくても正常に動作します。WebサイトはSSLを厳密に要求するため、HTTPEnabledプロパティをfalseに設定する必要があります。上記のソリューションを投稿していただきありがとうございます。

于 2015-06-10T16:09:52.523 に答える