[英]WCF multiple services same contract in same Config
Im trying to host to different service implementations of the same contract: 我试图托管同一合同的不同服务实现:
The reason is that need a dummy implementation for out-of-the-house testing. 原因是需要用于外部测试的虚拟实现。
Im trying to host both in the same WindowsService: 我试图将两者都托管在同一个WindowsService中:
private ServiceHost _host;
private ServiceHost _dummy;
protected override void OnStart(string[] args)
{
_host = new ServiceHost(typeof(Service));
_host.Open();
//trying to avoid the app.config beeing used - because its already been hoste by _host
_dummy = new ServiceHost(typeof(TestDummyService));
_dummy.Description.Endpoints.Clear();
_dummy.AddServiceEndpoint(typeof(IService),
new WebHttpBinding(),
@"<link>/Dummy.svc/");
_dummy.ChannelDispatchers.Clear();
_dummy.Open();
}
This is the config file: 这是配置文件:
<system.serviceModel>
<services>
<service name="namespace.Service">
<host>
<baseAddresses>
<add baseAddress="<link>/Service.svc"/>
</baseAddresses>
</host>
<endpoint address=""
binding="webHttpBinding"
contract="namespace.IService"
behaviorConfiguration="web" />
<endpoint address="/mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors >
<behavior>
<serviceMetadata httpGetEnabled="true"
httpGetUrl="<link>/Service.svc/About" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name ="web">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
The ChannelDispatcher at /Service.svc/About with Contracts 'IHttpGetHelpPageAndMetadataContract' is unable to open. /Service.svc/About中带有合同'IHttpGetHelpPageAndMetadataContract'的ChannelDispatcher无法打开。
any help is appreciated. 任何帮助表示赞赏。
Update 1 My goal is to have 2 different implementations of the same contract ( IService
) hosted in one WindowsService. 更新1我的目标是在一个WindowsService中托管同一合同(
IService
)的2个不同实现。
I would also like to configure both of them in the config file. 我也想在配置文件中配置它们两个。
Well i would like to know what's the business scenario. 好吧,我想知道什么是业务场景。 All I guess is, the client should not know the implementation, its just the URL of the service would indicate (or route) to the implementation.
我只想知道,客户端不应该知道实现,它只是服务的URL会指示(或路由)实现。
Kindly clarify. 请澄清。
Refer to this existing post and let me know if it makes sense. 请参阅此现有帖子 ,让我知道是否有意义。
The above post is hinting the implementation, refer to this post for deployment details. 上面的帖子暗示了实现,有关部署的详细信息,请参考该帖子 。
so i found out, that even thow the testdummy service was added programatic, it still got the service metadatabehavior. 所以我发现,即使将testdummy服务添加为程序性的,它仍然具有服务元数据行为。
My solution was to not make the dehavior default - given it at name: 我的解决方案是不将行为作为默认值-为其指定名称:
app.config: 的app.config:
<service name="namespace.Service" behaviorConfiguration="someName">
//.. later: // ..稍后:
<behavior name="someName">
<serviceMetadata httpGetEnabled="true"
httpGetUrl="<link>/Service.svc/About" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
The rest of the code, statyed the same 其余代码,声明相同
Can't you add another endpoint and fill in the adress with a distinct name: 您不能添加另一个端点并用一个唯一的名称填写地址:
<endpoint address="/SecondService"
binding="webHttpBinding2"
contract="namespace.IService"
/>
Url becomes /Service.svc/SecondService 网址变成/Service.svc/SecondService
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.