从 EndpointAddress 创建 WCF 绑定的简单方法
是否有基于给定端点的地址创建最基本的 WCF 绑定的快捷方式?
端点:net.tcp://localhost:7879/Service.svc
而不是一大块 if 语句...
Binding binding = null;
if (endpoint.StartsWith("net.tcp"))
{
binding = new NetTcpBinding();
}
else if (endpoint.StartWith("http"))
{
binding = new WsHttpBinding();
}
.
.
.
框架库中是否有一个快捷方式可以为我执行此操作,但我找不到或者我可以找不到它,因为它不公开存在?
Is there a shortcut for creating the most basic WCF Binding based on the address of a given Endpoint?
Endpoint: net.tcp://localhost:7879/Service.svc
Instead of a big block of if statements...
Binding binding = null;
if (endpoint.StartsWith("net.tcp"))
{
binding = new NetTcpBinding();
}
else if (endpoint.StartWith("http"))
{
binding = new WsHttpBinding();
}
.
.
.
Is there a shortcut in the Framework library that will do this for me that I just can't find or can I not find it because it doesn't publicly exist?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
.NET 4 中的 WCF 自动为您执行此操作 - 该功能称为“默认端点”。
请在此处了解 WCF 4 的所有新功能:WCF 4 开发人员简介
默认端点大约是文章的第二段左右。
WCF in .NET 4 does that automatically for you - the feature is called default endpoints.
Read about all of WCF 4's new features here: A Developer's Introduction to WCF 4
Default endpoints is about the second or so paragraph into the article.
虽然 WCF 4 支持默认服务端点,但它不支持默认客户端端点。不幸的是,框架用于创建默认绑定的方法是内部的,但其背后的逻辑很简单,因此我重新实现了它以在客户端使用(跳过原始缓存和跟踪逻辑):
没有任何配置,此代码相当于问题中的代码,但您可以在
system.serviceModel/protocolMapping
部分中选择和配置绑定。While WCF 4 supports default service endpoints, it does not support default client endpoints. Unfortunately the methods used by the framework to create default bindings are internal, but the logic behind it is simple, so I have reimplemented it to use on the client side (skipping original caching and tracing logic):
Without any configuration this code is equivalent to the code in the question, but you can select and configure your bindings inside the
system.serviceModel/protocolMapping
section.更深入地研究问题后,我真的不需要手动读取配置。相反,我需要发送绑定信息以及地址和合同。
http://www.codeproject.com/KB/WCF/WCFDiscovery.aspx ?display=PrintAll
我构建了一个简单的组件来序列化绑定信息。
http://nardax.codeplex.com/
After looking at the issue deeper I don't really need to read the configuration in manually. Instead I need to send the binding information along with the address and contract.
http://www.codeproject.com/KB/WCF/WCFDiscovery.aspx?display=PrintAll
I have built a simple component that serializes the binding information.
http://nardax.codeplex.com/