我的应用程序需要使用几个我无法修改的SOAP服务(它们被导入到Visual Studio中,并且类是自动生成的)。我已经将每个服务包装在自己的自定义类中(以便扩展功能),并且每个包装器都位于自己的类库项目中。然后,我的主应用程序实例化包装器以使用服务。这样地:
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
当Visual Studio为远程服务自动生成类时,该应用程序。配置文件已更新。这是给你的
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>
然后手动将绑定和客户端信息复制粘贴到
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
对象并调用
RemoteService1
SOAP服务。
问题是我无法配置第二个服务。我试图手动添加自动生成的应用程序。将设置配置到Web。配置文件,但我遇到了以下错误:
The element <customBinding> may only appear once in this section.
我应该如何配置多个SOAP服务?