0

I developed an application that imports many .wsdl files in order to have access to call several methods on a web service. I used Visual Studio's Add Service Reference and followed the instructions to have access to the services. In the end, I was left with the following app.config file, and I was wondering if there was a way to refactor the application so that I don't have to repeat all these endpoints. Note that all the endpoints are the same except for the value of the contract attribute.

<client>
  <endpoint address="https://xxx.yyy.com:10803" behaviorConfiguration="clientEndpointCredential"
    binding="basicHttpBinding" bindingConfiguration="bsapi_binding"
    contract="CriteriaList.bsapi_port" name="bsapi_port" />
  <endpoint address="https://xxx.yyy.com:10803" behaviorConfiguration="clientEndpointCredential"
    binding="basicHttpBinding" bindingConfiguration="bsapi_binding"
    contract="ContainerList.bsapi_port" name="bsapi_port" />
  <endpoint address="https://xxx.yyy.com:10803" behaviorConfiguration="clientEndpointCredential"
    binding="basicHttpBinding" bindingConfiguration="bsapi_binding"
    contract="DisplayUnitList.bsapi_port" name="bsapi_port" />
  <endpoint address="https://xxx.yyy.com:10803" behaviorConfiguration="clientEndpointCredential"
    binding="basicHttpBinding" bindingConfiguration="bsapi_binding"
    contract="DomainList.bsapi_port" name="bsapi_port" />
  <endpoint address="https://xxx.yyy.com:10803" behaviorConfiguration="clientEndpointCredential"
    binding="basicHttpBinding" bindingConfiguration="bsapi_binding"
    contract="ResourceCriteriaAdd.bsapi_port" name="bsapi_port" />
  <endpoint address="https://xxx.yyy.com:10803" behaviorConfiguration="clientEndpointCredential"
    binding="basicHttpBinding" bindingConfiguration="bsapi_binding"
    contract="ResourceCriteriaUpdate.bsapi_port" name="bsapi_port" />
  <endpoint address="https://xxx.yyy.com:10803" behaviorConfiguration="clientEndpointCredential"
    binding="basicHttpBinding" bindingConfiguration="bsapi_binding"
    contract="ResourceCriteriaList.bsapi_port" name="bsapi_port" />
  <endpoint address="https://xxx.yyy.com:10803" behaviorConfiguration="clientEndpointCredential"
    binding="basicHttpBinding" bindingConfiguration="bsapi_binding"
    contract="ResourceCriteriaListByCriteriaId.bsapi_port" name="bsapi_port" />
</client>
Ray
  • 4,679
  • 10
  • 46
  • 92
  • http://stackoverflow.com/questions/5098672/create-wcf-endpoint-configurations-in-the-client-app-in-code – CodeCaster Oct 13 '15 at 13:39
  • @CodeCaster: That link explains how to replace the config entries and place them in code. I'm asking if there's a way to remove all that repetition that I currently have in the config file. But the goal is to still keep using the config file. – Ray Oct 13 '15 at 13:46
  • As you already found out, a configured endpoint is tied to an address/binding/contract combination, so no, you can't reuse the lines you show. Instead if you keep one behavior configuration, you can instantiate your clients in code using the address (for example from an `AppSettings` key), a behavior you read from the config and a `BasicHttpBinding` instantiated from code. – CodeCaster Oct 13 '15 at 13:48
  • @CodeCaster: I had to import eight .wsdl files which generated eight Reference.cs files, and also eight proxy classes. So depending on the service call, I instantiated the appropriate proxy class. Somehow, my head is telling me there's a way to centralize all these proxies. Is this what you are explaining in your last comment? If yes, can you direct me to some documentation that explains this? – Ray Oct 13 '15 at 13:57

0 Answers0