我在一个 WCF 库中定义了多个服务合同,这些合同托管在 Windows 服务下。这些服务在 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/
这一切都很好。
但是我想知道是否有任何方法(除了您建议的包装解决方法)我只需要添加一个引用,并且我可以从这两个服务中调用方法。