How do I generate WCF proxy code separately for two services residing in one class?

时间:2016-07-11 20:29:28

标签: c# .net wcf

Based on this answer I created following class that implements two WCF services:

public class WcfEntryPoint : IMyService1, IMyService2
{
    #region IMyService1
    #endregion

    #region IMyService2
    #endregion
}

It's hosted in Windows Service. App.config looks like:

<system.serviceModel>
<services>
  <service name="TestWcfProject.WcfEntryPoint" behaviorConfiguration="WcfEntryPointBehavior">
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8000/TestWcfProject/service"/>
      </baseAddresses>
    </host>
    <!-- this endpoint is exposed at the base address provided by host: http://localhost:8000/TestWcfProject/service  -->
    <endpoint address="Service1" binding="wsHttpBinding" contract="TestWcfProject.IMyService1" />
    <endpoint address="Service2" binding="wsHttpBinding" contract="TestWcfProject.IMyService2" />
    <!-- the mex endpoint is exposed at http://localhost:8000/TestWcfProject/service/mex -->
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="WcfEntryPointBehavior">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="False"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
</system.serviceModel>

In order to use these services from some client application I generate proxy code by the command:

SvcUtil.exe http://localhost:8000/TestWcfProject/service?wsdl

The problem is that generated WcfEntryPoint.cs contains proxy code for both IMyService1 and IMyService2.

How can I generate proxy code only for IMyService1 or IMyService2 but not for both together? I've tried to launch

SvcUtil.exe /excludeType:TestWcfProject.IMyService2 http://localhost:8000/TestWcfProject/service?wsdl

with no luck.

I know that what I need could be achieved by implementing IMyService1 and IMyService2 in two different classes. But for the project it's essential that both services are implemented by the same class.

1 个答案:

答案 0 :(得分:1)

  

如何仅为IMyService1或IMyService2生成代理代码,但是   不是两个人在一起?

它不是svcutil支持的东西。但是,您可以更改服务发布元数据的方式。

在服务上你可以:

  1. Hide service operations未被MEX端点公开。
  2. 添加第二个Custom Mex endpoint,路径为“Mex2”。
  3. 在这两个引用之间,您应该能够为该服务创建两个自定义mex端点。每个端点都为特定用例发布方法的子集。