c# – 在WCF中的mex绑定错误

我使用的是VSTS 2008 C#.NET 3.0.我正在使用自主托管的WCF服务.当执行以下语句时,会出现以下“绑定未找到”错误.我已经发布了我的整个app.config文件,任何想法有什么问题?

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

错误信息:

Could not find a base address that matches scheme http for the
endpoint with binding MetadataExchangeHttpBinding. Registered base
address schemes are [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://,您还需要使用mexHttpsBinding:

<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>

渣子

http://stackoverflow.com/questions/1026149/mex-binding-error-in-wcf

转载注明原文:c# – 在WCF中的mex绑定错误