我有一个暴露了soap和xml端点的WCF服务。当我使用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>
答案 0 :(得分:0)
您需要指定端点配置名称。没办法,因为他们使用相同的合同。这就是System.ServiceModel.ClientBase具有该构造函数参数的原因。
var client = new TestClient("CustomBinding_ITestService");