C# 未找到 WCF 绑定错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/1026071/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WCF binding not found error?
提问by George2
I am using VSTS 2008 + C# + .Net 3.0. I am using self-hosted WCF. When executing the following statement, there is the following binding not found error. I have posted my whole app.config file, any ideas what is wrong?
我使用的是 VSTS 2008 + C# + .Net 3.0。我正在使用自托管 WCF。执行以下语句时,出现如下绑定未找到错误。我已经发布了我的整个 app.config 文件,有什么想法有什么问题吗?
ServiceHost host = new ServiceHost(typeof(MyWCFService));
Error message,
错误信息,
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.
Full app.config,
完整的 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>
thanks in advance, George
提前致谢,乔治
采纳答案by blowdart
You've misunderstood how to configure bindings - your binding in the endpoint needs to be a known protocol;
您误解了如何配置绑定 - 您在端点中的绑定需要是已知协议;
 <endpoint address="" binding="wsHttpBinding" contract="IMyService"/>
Once you have that you can then specify the binding configuration you have defined within the settings for that protocol using the bindingConfiguration element thus
一旦你有了它,你就可以使用 bindingConfiguration 元素指定你在该协议的设置中定义的绑定配置
 <endpoint address="" binding="wsHttpBinding" 
  bindingConfiguration="MyBinding" contract="IMyService"/>

