svcutil仅为多个服务合同之一生成客户端代码

时间:2011-07-13 12:59:30

标签: wcf svcutil.exe

我有一个服务有多个服务合同,当我运行svcutil.exe时,它只生成一个合约或另一个合同的客户端代码(它似乎每次运行时都会切换)。更多信息: 服务:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Single)]
public class BackendService : IBackendService, IFitContract
{
     //implementation
}

我的web.config看起来像:

<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<bindings>
  <wsDualHttpBinding/>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<protocolMapping>
  <add scheme="http" binding="wsDualHttpBinding"/>
</protocolMapping>
</system.serviceModel>
<system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

svcutil call:

svcutil.exe /config:App.config /out:BackendService.cs /n:*,BackendServer /r:bin/Debug/CSCommon.dll http://localhost:56725/BackendService.svc?wsdl

为什么会发生这种情况?

1 个答案:

答案 0 :(得分:2)

由于您没有在web.config上为服务声明任何端点,因此WCF将向其添加一个默认端点。由于此端点有两个选项,WCF将只选择1(我不知道它选择它做什么)。因此,在这种情况下,您需要明确声明端点,如下所示。

<system.serviceModel>
  <services>
    <service name="BackendServiceNamespace.BackendService">
      <endpoint address="ibs"
                contract="BackendServiceNamespace.IBackendService"
                binding="wsDualHttpBinding" />
      <endpoint address="ifc"
                contract="BackendServiceNamespace.IFitContract"
                binding="wsDualHttpBinding" />
    </service>
  </services>
</system.serviceModel>