找不到WCF绑定错误?

时间:2009-06-22 08:26:12

标签: c# visual-studio-2008 wcf binding

我使用的是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>
提前谢谢, 乔治

1 个答案:

答案 0 :(得分:23)

您误解了如何配置绑定 - 您在端点中的绑定需要是已知协议;

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

完成后,您可以使用bindingConfiguration元素指定您在该协议的设置中定义的绑定配置

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