【发布时间】:2010-12-12 06:55:56
【问题描述】:
我在一个托管在 Windows 服务下的 WCF 库中定义了多个服务合同。 这些服务在 Windows 服务配置文件中公开如下:
<services>
<service behaviorConfiguration="ReportingComponentLibrary.TemplateServiceBehavior"
name="ReportingComponentLibrary.TemplateService">
<endpoint address="" binding="wsHttpBinding" contract="ReportingComponentLibrary.ITemplateService" bindingConfiguration="wsHttp" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" ></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/ReportingComponentLibrary/TemplateService/" />
</baseAddresses>
</host>
</service>
<service behaviorConfiguration="ReportingComponentLibrary.TemplateServiceBehavior"
name="ReportingComponentLibrary.TemplateReportService">
<endpoint address="" binding="wsHttpBinding" contract="ReportingComponentLibrary.ITemplateReportService" bindingConfiguration="wsHttp" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" ></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/ReportingComponentLibrary/TemplateReportService/" />
</baseAddresses>
</host>
</service>
</services>
现在,当我在客户端应用程序中添加服务引用时,
是否可以为以上两项服务仅添加一项服务参考或
我需要为每个服务/服务合同单独引用。
更新:
这是我的申请详情:
我有三个不同的项目:
- WCF 服务库
- 用于在 WCF 服务之上托管的 Windows 服务
- 客户端 - 用于测试的控制台应用程序
现在,WCF 服务库中的 App.Config 如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="wsHttp" maxReceivedMessageSize="50000000" maxBufferPoolSize="50000000" messageEncoding="Mtom">
<readerQuotas maxDepth="500" maxStringContentLength="500000000" maxArrayLength="500000000"
maxBytesPerRead="500000000" maxNameTableCharCount="500000000" />
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="ReportingComponentLibrary.TemplateServiceBehavior"
name="ReportingComponentLibrary.TemplateService">
<endpoint address="" binding="wsHttpBinding" contract="ReportingComponentLibrary.ITemplateService" bindingConfiguration="wsHttp" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" ></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/ReportingComponentLibrary/TemplateService/" />
</baseAddresses>
</host>
</service>
<service behaviorConfiguration="ReportingComponentLibrary.TemplateServiceBehavior"
name="ReportingComponentLibrary.TemplateReportService">
<endpoint address="" binding="wsHttpBinding" contract="ReportingComponentLibrary.ITemplateReportService" bindingConfiguration="wsHttp" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/ReportingComponentLibrary/TemplateReportService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ReportingComponentLibrary.TemplateServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Windows Service中的App.Config同上。
现在在我的客户端应用程序中,我需要使用来自 TemplateService 和 TemplateReportService 的方法。
所以,我总是可以将两个不同的服务引用作为:
http://localhost:8080/ReportingComponentLibrary/TemplateService/ 和
http://localhost:8080/ReportingComponentLibrary/TemplateReportService/
一切正常。
但我想知道是否有任何方法(除了您建议的包装解决方法) 我只需要添加一个参考和 我可以从这两个服务中调用方法。
【问题讨论】:
标签: wcf wcf-client