Wcf svcutil仅为多个服务契约之一生成客户端代码

Wcf svcutil仅为多个服务契约之一生成客户端代码,wcf,svcutil.exe,Wcf,Svcutil.exe,我有一个具有多个服务契约的服务,当我运行svcuti.exe时,它只为一个契约或另一个契约生成客户端代码(每次运行它时,它似乎都会切换)。更多信息: 服务: 我的web.config看起来像: <system.web> <compilation debug="true" targetFramework="4.0" /> </system.web> <system.serviceModel> <behaviors> <servi

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

我的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>

想知道为什么会发生这种情况吗?

由于您没有在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>

有道理。我认为协议映射的目的是不需要手动添加端点(在4.0中)
svcutil.exe /config:App.config /out:BackendService.cs /n:*,BackendServer /r:bin/Debug/CSCommon.dll http://localhost:56725/BackendService.svc?wsdl
<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>