My application needs to consume several SOAP services that I have no ability to modify (they were imported into Visual Studio and the classes were automatically generated). I've wrapped each service in my own custom class (so that I can extend functionality), and each of those wrappers lives in its own Class Library project. My main application then instantiates my wrappers to use the services. Like this:
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
When Visual Studio auto-generated the classes for the remote services, the app.config file was updated. Here's the one for 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>
I then manually copy-pasted the binding and client information into the 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>
That works just fine. I'm able to instantiate a new MyService.Service1
object and make calls to the RemoteService1
SOAP service.
The problem is that I haven't been able to configure the second service. I tried to manually add the auto-generated app.config settings to the Web.config file, but I got this error:
The element <customBinding> may only appear once in this section.
How am I supposed to configure multiple SOAP services?
You can have as many bindings as you want within your binding section so long as you give each a distinct name. On your endpoint, you specify the type and name of the binding which you would like to use. The binding
property refers to the type of binding, and the bindingConfiguration
refers to the name of the binding of that type which you want to use.