WCF绑定没有找到错误?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (18)

我正在使用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"/>

扫码关注云+社区