我有一个 WCF 服务,它公开了一个肥皂和一个 xml 端点。当我使用 svcutil 在客户端生成代理代码时,生成的配置包含两个导致客户端失败的端点。如果我编辑 web.config 文件并删除第二个端点(使用自定义绑定),所有工作都按预期工作。有没有办法让 svcutil 生成一个可以正常工作的配置,这样我就不需要每次都手动编辑文件?
客户端错误:
无法加载合同“MyNamespace.ITestService”的端点配置部分,因为找到该合同的多个端点配置。请按名称指明首选端点配置部分。
svcutil 命令:
svcutil http://api.local/Test.svc
/reference:bin\MyNamespace.Interface.dll
/config:web.config
/mergeConfig
/out:"Service References\TestService.cs"
/n:*,MyNamespace
生成的客户端配置:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ITestService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
<customBinding>
<binding name="CustomBinding_ITestService">
<textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
messageVersion="Soap12" writeEncoding="utf-8">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</textMessageEncoding>
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://api2.local/Test.svc/soap" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ITestService" contract="MyNamespace.ITestService"
name="BasicHttpBinding_ITestService" />
<endpoint binding="customBinding" bindingConfiguration="CustomBinding_ITestService"
contract="MyNamespace.ITestService" name="CustomBinding_ITestService" />
</client>
</system.serviceModel>