c# – WCF绑定找不到错误?

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

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

错误信息,

Configuration binding extension 'system.serviceModel/bindings/MyBinding' could not be found. Verify that this binding extension is properly registered in system.serviceModel/extensions/bindingExtensions and that it is spelled correctly.

完整的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="http://localhost:9090/MyService"/>
          </baseAddresses>
        </host>
        <endpoint address="" binding="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>

提前致谢,
乔治

最佳答案
你误解了如何配置绑定 – 你的端点绑定需要一个已知的协议;

 <endpoint address="" binding="wsHttpBinding" contract="IMyService"/>

一旦你拥有了,那么你可以使用bindingConfiguration元素指定在该协议的设置中定义的绑定配置

 <endpoint address="" binding="wsHttpBinding" 
  bindingConfiguration="MyBinding" contract="IMyService"/>

转载注明原文:c# – WCF绑定找不到错误? - 代码日志