如何在单一服务中公开多个合同 [英] how to expose mulitple Contracts in a Single Service

查看:102
本文介绍了如何在单一服务中公开多个合同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Friends

您能否指导我讲解如何在一项服务中公开多份合同.

我在服务层中有以下合同.
ISiteService
IOrderService
IProductService ...

我希望完成以下工作.

1)我如何使用TCPBinding托管服务,以公开客户端应用程序的所有服务协定.
2)如何在客户端调用服务合同.


我已经看过很多例子,但它们仅解释了一份服务合同.

Hi Friends

Could you please guide me through how I can expose the mulitple contracts in a single service.

I am having the follwoing Contract in my service Layer.
ISiteService
IOrderService
IProductService...

I want the follwoing things to be done.

1) how I host the Service using the TCPBinding exposing the all service contracts for the client application.
2) how I can invoke the service contract at client end.


I have gone through the many examples but they only explain the one service contract.

Thanks

推荐答案

您可以拥有一个带有多个svc文件的WCF应用程序.每个都将引用不同的服务.因此,一旦托管了它,您将拥有三个服务的三个端点.您的客户端可以使用URL添加服务引用,也可以创建服务代理来调用该方法.
You can have one WCF application with multiple svc files. Each would refer to a different service. So once you have hosted it, you would have three endpoints for the three services. Your client can either add a service reference using the URL or create a service proxy to call the method.


我没有任何链接或方便的代码.尽管我会说这与在一个Web应用程序中具有多个aspx页面是一样的.

有一个WCF应用程序项目.向其中添加n个服务.将其托管在IIS或任何您使用的系统中,我会工作.几乎与具有多个aspx页的任何ASP.Net应用程序相同.
I do not have any link or some code handy. Although I would say this a same as having multiple aspx pages in one web application.

Have a WCF application project. Add n number of services to it. Host it in IIS or whatever you use and I would work. Almost same as any ASP.Net application with multiple aspx pages.


您应该为要公开的每个WCF接口创建一个EndPoint.如果使用代码,则应该是这样的:
ServiceHost主机=新的ServiceHost(typeof(YourServiceClass));
host.AddEndPoint(typeof(Interface1),...);
host.AddEndPoint(typeof(Interface2),...);
host.AddEndPoint(typeof(Interface3),...);
host.Open();
如果使用的是配置文件,请在其中添加相应的部分.
如果使用这种方法,则YourServiceClass应该实现所有三个接口.
在客户端,您应该为每个接口使用代理.使用SvcUtil创建代理(也可以使用VS功能).
祝你好运
You should create an EndPoint for each WCF interface you want to expose.If you using the code, it should be something like this:
ServiceHost host=new ServiceHost(typeof(YourServiceClass));
host.AddEndPoint(typeof(Interface1),...);
host.AddEndPoint(typeof(Interface2),...);
host.AddEndPoint(typeof(Interface3),...);
host.Open();
If you are using the config file, add corresponding sections to it.
If you use this approach YourServiceClass should implement all three interfaces.
On the client side you should use a proxy for each interface. Use SvcUtil to create the proxies(you may use VS features as well).
good luck


这篇关于如何在单一服务中公开多个合同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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