【发布时间】:2018-07-31 10:51:13
【问题描述】:
我的应用程序需要使用几个我无法修改的 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 为远程服务自动生成类时,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.
我应该如何配置多个 SOAP 服务?
【问题讨论】:
-
啊,你是对的!那效果很好。与具有多个端点的
<client />相同。如果您将评论复制到答案中,我会接受。