【问题标题】:How do I generate WCF proxy code separately for two services residing in one class?如何为一个类中的两个服务分别生成 WCF 代理代码?
【发布时间】:2016-07-13 07:48:47
【问题描述】:

基于this answer,我创建了以下实现两个 WCF 服务的类:

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

    #region IMyService2
    #endregion
}

它托管在 Windows 服务中。 App.config 看起来像:

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

为了从某些客户端应用程序中使用这些服务,我通过以下命令生成代理代码:

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

问题是生成的 WcfEntryPoint.cs 包含 IMyService1 和 IMyService2 的代理代码。

如何仅为IMyService1IMyService2 生成代理代码,但不能同时为两者生成代理代码?我已尝试启动

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

没有运气。

我知道我需要通过在两个不同的类中实现IMyService1IMyService2 来实现。但对于项目而言,两个服务必须由同一个类实现。

【问题讨论】:

    标签: c# .net wcf


    【解决方案1】:

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

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

    在服务上你可以:

    1. Hide service operations 不会被 MEX 端点暴露。
    2. 添加第二个Custom Mex endpoint,路径为“Mex2”。

    在这两个引用之间,您应该能够为服务创建两个自定义 mex 端点。每个端点为特定用例发布方法的子集。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-15
      • 1970-01-01
      • 1970-01-01
      • 2011-04-03
      • 2011-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多