質問

VSTS 2008 + C# + .NET 3.0を使用しています。セルフホスト型 WCF サービスを使用しています。次のステートメントを実行すると、次の「バインディングが見つかりません」エラーが発生します。app.config ファイル全体を投稿しましたが、何が間違っているのか考えられますか?

ServiceHost host = new ServiceHost(typeof(MyWCFService));

エラーメッセージ:

バインディングメタデータチェンジHttpbnindを使用して、エンドポイントのスキームHTTPに一致するベースアドレスを見つけることができませんでした。登録されたベースアドレススキームは[https]です。

完全な app.config:

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="MyBinding"
            closeTimeout="00:00:10"
            openTimeout="00:00:20"
            receiveTimeout="00:00:30"
            sendTimeout="00:00:40"
            bypassProxyOnLocal="false"
            transactionFlow="false"
            hostNameComparisonMode="WeakWildcard"
            maxReceivedMessageSize="100000000"
            messageEncoding="Mtom"
            proxyAddress="http://foo/bar"
            textEncoding="utf-16"
            useDefaultWebProxy="false">
          <reliableSession ordered="false"
               inactivityTimeout="00:02:00"
               enabled="true" />
          <security mode="Transport">
            <transport clientCredentialType="Digest"
               proxyCredentialType="None"
               realm="someRealm" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <services>
      <service name="MyWCFService"
                behaviorConfiguration="mexServiceBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="https://localhost:9090/MyService"/>
          </baseAddresses>
        </host>
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="MyBinding" contract="IMyService"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="mexServiceBehavior">
          <serviceMetadata httpGetEnabled="True"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
役に立ちましたか?

解決

サービスのベース アドレスは「HTTPS://」を定義しますが、mex アドレスは「HTTP」です。

サービスで https:// を使用する場合は、 mexHttpsバインディング 同じように:

<services>
    <service name="MyWCFService" behaviorConfiguration="mexServiceBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="https://localhost:9090/MyService"/>
          </baseAddresses>
        </host>
        <endpoint address="" 
                binding="wsHttpBinding" 
                bindingConfiguration="MyBinding" 
                contract="IMyService" 
        />
        <endpoint address="mex" 
                binding="mexHttpsBinding" 
                contract="IMetadataExchange" 
        />
    </service>
</services>

マルク

他のヒント

ダブルスコアを取得できますか? :)

WS-Httpを使用している場合、HTTPSプロトコルにバインドするため、正しいMEXバインディングを使用する必要があります。

<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />

Marc_s 回答

  

httpとhttpsの両方でIMetadataExchangeを使用することは可能ですか?   別のエンドポイント?

&nbsp; marc_s&nbsp; answered&nbsp;

  

http://および   これをhttp mexエンドポイントに使用します。

そのための解決策は、同じアドレス==「mex」で複数のエンドポイントを宣言することです。および次のような異なるバインディング

<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />  
<endpoint contract="IMetadataExchange" binding="mexHttpsBinding" address="mex"/>

最近、テストでMEXを有効にし、ライブで無効にするために使用できる構成スイッチが1つある方が簡単であることがわかりました。

From&nbsp; http://msdn.microsoft.com/en-us /library/aa395224.aspx

  

&nbsp; ServiceHostFactory&nbsp;クラスを使用してカスタムを作成することができます   インターネットインフォメーションサービスのServiceHostから派生   (IIS&nbsp; ServiceMetadataBehaviorを追加するカスタムServiceHost、(   この動作が明示的でない場合でも、メタデータの公開を有効にします)   サービスの設定ファイルに追加されました。

     

&nbsp;メタデータの公開を1回可能にする命令型コードを記述し、   その後、そのコードを複数の異なるサービスで再利用します。これは   &nbsp; ServiceHost&nbsp;から派生する新しいクラスを作成することにより達成されます。   &nbsp; ApplyConfiguration()メソッドをオーバーライドして、   メタデータの公開動作。

カスタムサービスホストのMSDN記事

のコード例>
//Add a metadata endpoint at each base address
//using the "/mex" addressing convention
foreach (Uri baseAddress in this.BaseAddresses)
{
    if (baseAddress.Scheme == Uri.UriSchemeHttp)
    {
        mexBehavior.HttpGetEnabled = true;
        this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                MetadataExchangeBindings.CreateMexHttpBinding(),
                                "mex");
    }
    else if (baseAddress.Scheme == Uri.UriSchemeHttps)
    {
        mexBehavior.HttpsGetEnabled = true;
        this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                MetadataExchangeBindings.CreateMexHttpsBinding(),
                                "mex");
    }
    else if (baseAddress.Scheme == Uri.UriSchemeNetPipe)
    {
        this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                MetadataExchangeBindings.CreateMexNamedPipeBinding(),
                                "mex");
    }
    else if (baseAddress.Scheme == Uri.UriSchemeNetTcp)
    {
        this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                MetadataExchangeBindings.CreateMexTcpBinding(),
                                "mex");
    }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top