WCF服务的2个不同的服务合同露出2端点 [英] WCF service exposing 2 endpoints on 2 different service contracts

查看:111
本文介绍了WCF服务的2个不同的服务合同露出2端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我想配置,从而可以显示2端点,指的是不同的功能,不同网址下的WCF服务。



我想有什么是的服务1 ,露出方法A,b,C,和客服2 ,露出方法D,E。
我希望能够浏览这两个本地主机/WebServiceName/Service1/Service.svc 本地主机/ WebServiceName /客服2 / Service.svc



其他应用程序引用<强>本地主机/ WebServiceName /服务1 / Service.svc 应该只能看到包含方法的接口,B和C.他们不应该看到关于客服2 接口什么。和客服2 亦同。



到目前为止,我已经在我的WCF服务定义了两个接口, I_Service1 和<强> I_Service2



我在web.config中添加的两个端点,像这样:

 <端点地址=HTTP://本地主机/ WebServiceName /服务1 /绑定=的wsHttpBinding合同=WebServiceName.I_Service1bindingConfiguration =Binding1/> 
<端点地址=HTTP://本地主机/ WebServiceName /客服2 /绑定=的wsHttpBinding合同=WebServiceName.I_Service2bindingConfiguration =Binding2/>

在enpoint使用完整的地址的建议来自这里:的



/stackoverflow.com/questions/1182725/multiple-endpoints-under-iis?rq=1\">Multiple端点

不过,我仍然能T浏览本地主机/ WebServiceName /服务1 / Service.svc 。我收到:

 说明:HTTP 404。您正在查找的资源(或者它的一个依赖)可能已被移除,更名或暂时不可用。请检查以下URL并确保其拼写正确。 



我能成功浏览的本地主机/ WebServiceName / Service.svc 的和WSDL包括方法A,b,C,D,E。但是这应该是错在我想要的行为。



有什么,我错过了什么?



更新:按照本文的 http://allen-conway-dotnet.blogspot.ro/2011/09/exposing-multiple-binding-types-for.html 我对这些端点创建了两个不同的合同服务。但目前我只seing 服务1 当我浏览了。 客服2 显然不存在(HTTP 404错误相关的问题出现)



配置如下:

 <服务和GT; 
<服务behaviorConfiguration =WebServiceName.ServiceBehavior1NAME =WebServiceName.Service1>
<端点地址=绑定=的wsHttpBindingbindingConfiguration =Binding1
合同=WebServiceName.I_Service1/>
<端点地址=MEX绑定=mexHttpBinding合同=IMetadataExchange接口/>
<主机>
< baseAddresses>
<添加baseAddress =HTTP://localhost/WebServiceName/Service1/Service.svc/>
< / baseAddresses>
< /主机>
< /服务>
<服务behaviorConfiguration =WebServiceName.ServiceBehavior2NAME =WebServiceName.Service2>
<端点地址=绑定=的wsHttpBindingbindingConfiguration =Binding1
合同=WebServiceName.I_Service2/>
<端点地址=MEX绑定=mexHttpBinding合同=IMetadataExchange接口/>
<主机>
< baseAddresses>
<添加baseAddress =HTTP://localhost/WebServiceName/Service2/Service.svc/>
< / baseAddresses>
< /主机>
< /服务>
< /服务>


解决方案

有关我解决这个问题包括两瞬间在我的web服务的.svc文件,这两个接口分开。
这样的,我的本地主机/ WebServiceName / Service1.svc 本地主机/ WebServiceName / Service2.svc



通过端点配置

 <服务和GT; 
<服务behaviorConfiguration =WebServiceName.ServiceBehavior1NAME =WebServiceName.Service1>
<端点地址=绑定=的wsHttpBindingbindingConfiguration =Binding1
合同=WebServiceName.I_Service1/>
<端点地址=MEX绑定=mexHttpBinding合同=IMetadataExchange接口/>
<主机>
< baseAddresses>
<添加baseAddress =HTTP://localhost/WebServiceName/Service1.svc/>
< / baseAddresses>
< /主机>
< /服务>
<服务behaviorConfiguration =WebServiceName.ServiceBehavior2NAME =WebServiceName.Service2>
<端点地址=绑定=的wsHttpBindingbindingConfiguration =Binding2
合同=WebServiceName.I_Service2/>
<端点地址=MEX绑定=mexHttpBinding合同=IMetadataExchange接口/>
<主机>
< baseAddresses>
<添加baseAddress =HTTP://localhost/WebServiceName/Service1.svc/>
< / baseAddresses>
< /主机>
< /服务>
< /服务>

这解决方案是没有必要的最好的一个(如果一个客户真正想要的,就可以发现,这个服务公开2个不同的接口,但我可以用不同的凭据/令牌保护它们)。但此刻,我会去用它。


I have an WCF service which I am trying to configure so that it exposes 2 endpoints, refering to different functionalities, under different URLs.

What I want to have is Service1, exposing methods A, B, C, and Service2, exposing methods D, E. I want to be able to browse both localhost/WebServiceName/Service1/Service.svc and localhost/WebServiceName/Service2/Service.svc.

Other applications referencing localhost/WebServiceName/Service1/Service.svc should see only the interface containing the methods A, B and C. They should not see anything regarding Service2 interface. And for Service2 likewise.

So far I have defined two interfaces in my WCF service, I_Service1 and I_Service2.

I have added two endpoints in my web.config like so:

<endpoint address="http://localhost/WebServiceName/Service1/" binding="wsHttpBinding" contract="WebServiceName.I_Service1" bindingConfiguration="Binding1" />
<endpoint address="http://localhost/WebServiceName/Service2/" binding="wsHttpBinding" contract="WebServiceName.I_Service2" bindingConfiguration="Binding2" />  

The suggestion of using full address in the enpoint comes from here: Multiple endpoints under IIS

But still, I can't browse localhost/WebServiceName/Service1/Service.svc. I receive:

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. 

I can successfully browse localhost/WebServiceName/Service.svc and the wsdl includes methods A, B, C, D, E. But this should be wrong in the behaviour I want.

Is there something that I have missed?

UPDATE: Following this article http://allen-conway-dotnet.blogspot.ro/2011/09/exposing-multiple-binding-types-for.html I created two different contract services for those endpoints. But currently I am seing only Service1 when I browse it. Service2 apparently does not exist (HTTP 404 error related issues appear).

The configuration looks like:

<services>
   <service behaviorConfiguration="WebServiceName.ServiceBehavior1" name="WebServiceName.Service1">
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding1"
     contract="WebServiceName.I_Service1" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
     <host>
       <baseAddresses>
         <add baseAddress="http://localhost/WebServiceName/Service1/Service.svc" />
       </baseAddresses>
     </host>
   </service>
   <service behaviorConfiguration="WebServiceName.ServiceBehavior2" name="WebServiceName.Service2">
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding1"
     contract="WebServiceName.I_Service2" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
     <host>
       <baseAddresses>
         <add baseAddress="http://localhost/WebServiceName/Service2/Service.svc" />
       </baseAddresses>
     </host>
   </service>
  </services>

解决方案

For the moment my solution to this problem was incorporating two .svc files in my webservice to separate the two interfaces. Such, I have localhost/WebServiceName/Service1.svc and localhost/WebServiceName/Service2.svc.

With the endpoint configuration

<services>
   <service behaviorConfiguration="WebServiceName.ServiceBehavior1" name="WebServiceName.Service1">
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding1"
     contract="WebServiceName.I_Service1" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
     <host>
       <baseAddresses>
         <add baseAddress="http://localhost/WebServiceName/Service1.svc" />
       </baseAddresses>
     </host>
   </service>
   <service behaviorConfiguration="WebServiceName.ServiceBehavior2" name="WebServiceName.Service2">
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding2"
     contract="WebServiceName.I_Service2" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
     <host>
       <baseAddresses>
         <add baseAddress="http://localhost/WebServiceName/Service1.svc" />
       </baseAddresses>
     </host>
   </service>
  </services>

This solution is not necessary the best one (if a client really wants, it can find that this service exposes 2 different interfaces, but I can secure them with different credentials/tokens). But at the moment I will go with it.

这篇关于WCF服务的2个不同的服务合同露出2端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆