我的应用程序需要食用几种我无法修改的肥皂服务(它们被导入到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自动生成远程服务的类时,App.Config文件已更新。这是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
web.config:
<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服务。
问题是我无法配置第二个服务。我尝试将自动生成的app.config设置手动添加到web.config文件中,但是我收到了此错误:
The element <customBinding> may only appear once in this section.
我应该如何配置多个肥皂服务?
只要给每个名称一个独特的名称,您就可以在绑定部分中拥有尽可能多的绑定。在端点上,您指定要使用的绑定的类型和名称。binding
属性是指绑定的类型,bindingConfiguration
是指您要使用的该类型的绑定的名称。