【问题标题】:Communicate with multiple web service dynamically与多个 Web 服务动态通信
【发布时间】:2016-07-26 09:15:29
【问题描述】:
我正在寻找一些关于如何完成我的工作的建议。基本上我有多个采用相同方法和参数的网络服务。总是必须获取代理类并在接受新提供程序时更改代码是一件痛苦的事情,我正在寻找能够在我的配置中添加 web 服务 URL 并在运行时能够编译生成代理的方法类并与远程机器动态通信。
作为示例:我必须将数据发送到一个名为 UpdateCustomers 的方法(int id、字符串名称、字符串姓氏、DateTime DateofBirth)到提供者,如果我们决定使用提供者 A 能够在配置中更改 web 服务 url指向A,或者当我们决定改为B等时......
网络服务是 .asmx 或 .svc
我正在寻找提示和建议。
问候
【问题讨论】:
标签:
c#
web-services
wcf
asmx
svc
【解决方案1】:
听起来像是WCF Routing 的工作。
根据您希望如何路由呼叫,您可以定义message filters,您可以使用它来评估传入呼叫是否满足一组标准,例如,soap 有效负载中的某个值设置为特定的价值:
<filters>
<filter name="myXPathFilter1"
filterType="XPath"
filterData="//valueIWantToFilterOn = somevalue"/>
</filters>
然后您可以注册过滤器以映射到特定端点:
<filterTables>
<table name="myRoutingTable">
<filters>
<add filterName="myXPathFilter1" endpointName="UpdateCustomers1" />
<add filterName="myXPathFilter2" endpointName="UpdateCustomers2" />
...
</filters>
</table>
</filterTables>