2010-04-19 75 views
3

我有一个公开了soap和xml端点的WCF服务。当我使用svcutil在客户端生成代理代码时,生成的配置包含导致客户端失败的两个端点。如果我编辑web.config文件并删除第二个端点(使用自定义绑定),所有这些都按预期工作。有没有一种方法可以让svcutil生成一个可以正常工作的配置,以便我不需要每次都手动编辑文件?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> 
+0

你的服务配置文件是什么? – Franchesca 2011-07-18 09:18:30

回答

0

你需要指定端点配置名称。由于他们使用相同的合同,所以没有办法。这就是为什么System.ServiceModel.ClientBase具有该构造函数参数的原因。

var client = new TestClient("CustomBinding_ITestService");