gpt4 book ai didi

xml - Svcutil 生成具有多个端点的错误配置

转载 作者:数据小太阳 更新时间:2023-10-29 02:46:46 26 4
gpt4 key购买 nike

我有一个公开了 soap 和 xml 端点的 WCF 服务。当我使用 svcutil 在客户端生成代理代码时,生成的配置包含两个导致客户端失败的端点。如果我编辑 web.config 文件并删除第二个端点(使用自定义绑定(bind)),一切都会按预期进行。有没有办法让 svcutil 生成一个可以正常工作的配置,这样我就不需要每次都手动编辑文件了?

客户端错误:

An endpoint configuration section for contract 'MyNamespace.ITestService' could not be loaded because more than one endpoint configuration for that contract was found. Please indicate the preferred endpoint configuration section by name.

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>

最佳答案

您需要指定端点配置名称。没有办法解决它,因为他们使用相同的契约(Contract)。这就是 System.ServiceModel.ClientBase 具有该构造函数参数的原因。

var client = new TestClient("CustomBinding_ITestService");

关于xml - Svcutil 生成具有多个端点的错误配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2670006/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com