WCF服务中多端点的优点
我是 WCF 新手。请告诉我为 wcf web 服务创建多个端点有什么好处?
另外,您能否帮我举一个示例,说明如何在 IIS 中托管此类服务以及 wcf 客户端如何连接到所提供的确切端点。
谢谢。
I am new to WCF. Please tell me what is advantage of creating multiple endpoints to a wcf web service?
Also can you please help me with an example that how to host such service in IIS and how a wcf client will connect to exact endpoint provided.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
提供不同端点的优点是每个端点可以使用不同的绑定。这样他就可以根据客户端的能力选择合适的绑定。例如,您可以为 Java、PHP 等客户端公开一个可互操作端点,以及一个专有的二进制端点,该端点可能更快,但仅适用于 .NET 客户端。
每个端点都有地址、绑定和合约。因此客户端可以选择他想要使用的服务端点。
要在 IIS 中托管 WCF 服务,您有两种可能性:仅 HTTP 绑定可用的 ASP.NET 应用程序(basicHttpBinding、wsHttpBinding、webHttpBinding...)或在 WAS(仅限 IIS 7.0)中可以使用二进制绑定。从客户端的角度来看,您可以向客户端项目添加一个指向给定服务 URL 的服务引用并使用该服务。这是另一篇文章讨论了这个问题。
The advantage of providing different endpoints is that each endpoint could use different binding. This way based on the client capabilities he could choose the appropriate binding. For example you could expose an interoperable endpoint for Java, PHP, ... clients and a proprietary binary endpoint which could be faster but only for .NET clients.
Each endpoint has address, binding and contract. So the client could choose which service endpoint he wants to consume.
To host a WCF service in IIS you have 2 possibilities: either in an ASP.NET application where only HTTP bindings are available (basicHttpBinding, wsHttpBinding, webHttpBinding, ...) or in WAS (IIS 7.0 only) where you can use binary bindings. From a client perspective you add a Service Reference to the client project pointing to a given service url and consume the service. And here's another article you which discusses this.
根据经验:
使用不同的绑定,例如,对于 Java 客户端使用一个
BasicHttpBinding
,而对于 .NET 客户端使用WsHttpBinding
。还有一些为 HTTPS,另一些为 HTTP...划分和公开不同的合约/接口。例如,您有一个公开许多操作的接口,并且有一个执行基本操作的精简接口,然后将第二个接口发布到外部,以便内部客户端使用扩展接口的端点,但外部客户端使用另一个接口。
例如
,现在您有一个类实现两者:
现在您只向外部公开一个类,而实现位于同一个类中。
From experience:
Using different binding, for example one
BasicHttpBinding
for Java clients while usingWsHttpBinding
for .NET clients. Also HTTPS for some and HTTP for others...Dividing and exposing different contracts/interfaces. For example you have one interface that exposes many operations and you have a cut down interface which does basic things and you publish the second to outside so internal clients use the endpoint for extended interface but external clients use the other one.
For example
Now you have One class implementing both:
And now you expose only one to outside while implementation is in the same class.