【发布时间】: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 的代理代码。
如何仅为IMyService1 或IMyService2 生成代理代码,但不能同时为两者生成代理代码?我已尝试启动
SvcUtil.exe /excludeType:TestWcfProject.IMyService2 http://localhost:8000/TestWcfProject/service?wsdl
没有运气。
我知道我需要通过在两个不同的类中实现IMyService1 和IMyService2 来实现。但对于项目而言,两个服务必须由同一个类实现。
【问题讨论】: