【问题标题】:WCF picking basicHttpBinding & ignoring the defined customBindingsWCF 选择 basicHttpBinding 并忽略定义的 customBindings
【发布时间】:2015-10-07 09:33:48
【问题描述】:
 <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
    <bindings>
        <customBinding>
            <binding name="httpBinding">
                <binaryMessageEncoding />
                <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"/>
            </binding>
            <binding name="httpsBinding">
                <binaryMessageEncoding/>
                <httpsTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"/>
            </binding>
        </customBinding>
    </bindings>
    <services>
        <service name="MyNamespace.MyIService" behaviorConfiguration="MyNamespace.MyIService" >

            <endpoint address="http://wcf-client-url/virtualDirectory/MyService.svc"
                      binding="customBinding" contract="MyNamespace.MyIService"
                      name="httpBinding"/>
            <endpoint address="https://wcf-client-url/virtualDirectory/MyService.svc"
                      binding="customBinding" bindingConfiguration="httpsBinding"
                      contract="MyNamespace.MyIService" name="httpsBinding" />               
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="MyNamespace.MyIService" >
                <serviceMetadata httpsGetEnabled="true" httpGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="true"/>
                <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
            </behavior>
            <behavior name="">
                <serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <client>
        <endpoint address="http://wcf-client-url/virtualDirectory/MyService.svc"
                      binding="customBinding"
                      bindingConfiguration="httpBinding"
                      contract="MyNamespace.MyIService"
                      name="httpBinding" />

        <endpoint address="https://wcf-client-url/virtualDirectory/MyService.svc"
                  binding="customBinding"
                  bindingConfiguration="httpsBinding"
                  contract="MyNamespace.MyIService"
                  name="httpsBinding" />
    </client>
</system.serviceModel>

我在 IIS 中托管的 WCF 服务中有上述配置。我可以在浏览器中成功浏览到服务,因为您可以观察到我想使用 customBinding。

当我使用 Visual Studio 在我的客户端应用程序中使用 VS 内置添加服务引用对话框添加对此服务的引用时,下面是 Visual Studio 为我创建的客户端端点。

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_MyIService" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://wcf-client-url/virtualDirectory/MyService.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_MyIService"
        contract="ServiceReference1.MyIService" name="BasicHttpBinding_MyIService" />
    </client>
  </system.serviceModel>

我不明白为什么 VS 为我创建一个客户端 basicHttpBinding 但我已经在服务器上定义了一个 customBinding。

另外,当我在“WCF 测试客户端”中测试我的服务,然后双击 WCF 测试客户端中的配置文件时,我看到它确实在测试客户端中显示了以下配置。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_MyIService" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://myPCHostName/virtualDirectory/MyService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_MyIService"
                contract="MyIService" name="BasicHttpBinding_MyIService" />
        </client>
    </system.serviceModel>
</configuration>

我对这个 WCF 开发有点陌生,我不清楚我的 customBinding 是如何被忽略的。

根据我上面的配置,BasicHttpBinding 是在任何位置设置为默认绑定,还是我可以完全删除它,即使我似乎无法确定它在该配置中的设置位置。

【问题讨论】:

  • basicHttpBinding 是默认的,用于没有明确绑定配置的服务的开箱即用绑定。您可以按照 Mimas 下面的说明进行操作,也可以通过在配置中省略 name 属性来定义“默认”绑定配置。
  • 解决了吗?因为我有同样的问题。

标签: wcf wcf-binding wcf-endpoint


【解决方案1】:

尝试为服务端的两个端点指定 behaviorConfigurationbindingConfiguration。您只为 https 端点指定了 bindingConfiguration,而根本没有为行为这样做。

应该是这样的

<bindings>
    <customBinding>
        <binding name="httpBinding">
            <binaryMessageEncoding />
            <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"/>
        </binding>
        <binding name="httpsBinding">
            <binaryMessageEncoding/>
            <httpsTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"/>
        </binding>
    </customBinding>
</bindings>
<services>
    <service name="MyNamespace.MyIService" behaviorConfiguration="MyNamespace.MyIService" >
        <endpoint address="http://wcf-client-url/virtualDirectory/MyService.svc"
            binding="customBinding" 
            contract="MyNamespace.MyIService" 
            bindingConfiguration="httpBinding" 
            behaviorConfiguration="httpEndpoint" 
            name="httpBinding"/>
        <endpoint address="https://wcf-client-url/virtualDirectory/MyService.svc"
            binding="customBinding" 
            bindingConfiguration="httpsBinding" 
            behaviorConfiguration="httpEndpoint"
            contract="MyNamespace.MyIService" 
            name="httpsBinding" />               
    </service>
</services>
<behaviors>
    <serviceBehaviors>
        <behavior name="httpEndpoint" >
            <serviceMetadata httpsGetEnabled="true" httpGetEnabled="true"/>
            <serviceDebug includeExceptionDetailInFaults="true"/>
            <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
        </behavior>
    </serviceBehaviors>
</behaviors>

【讨论】:

    猜你喜欢
    • 2012-05-02
    • 1970-01-01
    • 1970-01-01
    • 2014-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-31
    • 2016-03-15
    相关资源
    最近更新 更多