在Web.config中配置多个SOAP服务

时间:2018-02-20 23:47:23

标签: c# asp.net .net wcf soap

我的应用程序需要使用几个我无法修改的SOAP服务(它们被导入到Visual Studio中,并且这些类是自动生成的)。我已经在我自己的自定义类中包装了每个服务(以便我可以扩展功能),并且每个包装器都存在于自己的类库项目中。然后我的主应用程序实例化我的包装器以使用服务。像这样:

delete

当Visual Studio自动生成远程服务的类时,app.config文件已更新。这是MyProject.Service1 (class library) - instantiates and uses RemoteService1 - has app.config file MyProject.Service2 (class library) - instantiates and uses RemoteService2 - has app.config file MyProject (web application) - instantiates and uses MyProject.Service1 and MyProject.Service2 - has Web.config file 的一个:

MyProject.Service1

然后我手动将绑定和客户端信息粘贴到<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <bindings> <customBinding> <binding name="RemoteService1HttpBinding"> <textMessageEncoding messageVersion="Soap12" /> <httpTransport /> </binding> </customBinding> </bindings> <client> <endpoint address="http://path.com/to/RemoveService1" binding="customBinding" bindingConfiguration="RemoteService1HttpBinding" contract="RemoteService1Contract" name="RemoteService1Name" /> </client> </system.serviceModel> </configuration> Web.config中:

MyProject

这很好用。我能够实例化一个新的<system.serviceModel> <bindings> <customBinding> <binding name="RemoteService1HttpBinding"> <textMessageEncoding messageVersion="Soap12" /> <httpTransport /> </binding> </customBinding> </bindings> <client> <endpoint address="http://path.com/to/RemoveService1" binding="customBinding" bindingConfiguration="RemoteService1HttpBinding" contract="RemoteService1Contract" name="RemoteService1Name" /> </client> </system.serviceModel> 对象并调用MyService.Service1 SOAP服务。

问题是我还没能配置第二项服务。我尝试手动将自动生成的app.config设置添加到Web.config文件中,但是我收到此错误:

RemoteService1

我应该如何配置多个SOAP服务?

1 个答案:

答案 0 :(得分:1)

只要为每个绑定部分指定一个不同的名称,就可以在绑定部分中拥有任意数量的绑定。在端点上,指定要使用的绑定的类型和名称。 binding属性指的是绑定类型,bindingConfiguration指的是您要使用的该类型绑定的名称。

相关问题