WCF:奇怪的自动服务引用

WCF: strange automatic service reference

我使用 netHttp 绑定创建了一个简单的 WCF 服务,然后通过 "Add service reference|Discover" 自动将服务引用从它添加到另一个应用程序中。生成的绑定看起来很奇怪。

而不是原来的 NetHttpBinding 我得到了 CustomBinding.

它有效,但令人恼火的是我无法将 maxReceivedMessageSize 添加到自定义绑定。

问题:这样做有什么充分的理由吗?或者我可以安全地将自定义绑定替换为原始的 netHttpBinding 吗?

主持人的app.config:

  <endpoint address="images/netbh" binding="netHttpBinding" contract="WcfImageService.IImageService" bindingConfiguration="netHttp_bh" />

  <netHttpBinding>
    <binding name="netHttp_bh" messageEncoding="Binary">
      <webSocketSettings transportUsage="Never"/>
    </binding>
  </netHttpBinding>

客户端生成的app.config:

        <customBinding>
            <binding name="NetHttpBinding_IImageService1" >
                <binaryMessageEncoding />
                <httpTransport />
            </binding>
        </customBinding>

        <endpoint address="http://localhost:8080/images/netbh" binding="customBinding"
            bindingConfiguration="NetHttpBinding_IImageService1" contract="ImageServiceReference.IImageService"
            name="NetHttpBinding_IImageService1" />

我使用的是 Visual Studio 2015,以防万一。

我不知道你为什么在客户端得到一个customBinding(我认为Visual Studio在幕后使用的wsdl.exe工具有点混乱)但是你可以安全地替换自定义与原始 webHttpBinding 绑定。

作为替代方案,我认为您还可以在 元素上指定 maxReceivedMessageSize,如下所示:

<httpTransport maxReceivedMessageSize="2000000000" />