在同一个svc文件中使用2个WCF接口

时间:2011-08-16 15:30:00

标签: wcf web-config svc

我们正在尝试与外部WCF服务进行通信。

WCF服务通过svc文件公开。看来有两个接口通过相同的svc文件公开。

我们如何在web.config文件中配置它?

1 个答案:

答案 0 :(得分:2)

如果我理解你的问题,你就有一个实现2个WCF服务合同的类。在web.config中,为每个服务合同配置端点,但在同一<service>节点下。我只在自托管WCF服务时完成此操作,而不是在IIS中,但我认为如果在端点配置中为address指定值,则会使其相对于.svc文件的位置:

<service name="YourServiceLibrary.YourServiceClass">
  <endpoint address="Service1"
    contract="YourServiceLibrary.IService1"
    ...
     />
  <endpoint address="Service2"
    contract="YourServiceLibrary.IService2"
    ...
     />
</service>

然后,您可以为每个服务合同设置客户端代理,以指向http://YourServer/YourServicePath/YourServiceClass.svc/Service1http://YourServer/YourServicePath/YourServiceClass.svc/Service2