C. Knight
C. Knight

Reputation: 749

Use same WCF service reference in multiple projects

I have multiple projects in my solution which consume the same WCF service. As such they each have a service reference to the WCF service. All's well so far.

When these services are combined into the solution they naturally get the service model from the app.config of the exe. This is where things get interesting. Even though both of the service references point to the same WCF service it looks like I need to expose two end points:

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="SecureHttpBindingEndpoint">
      <security mode="Transport" />
    </binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address=".../LocalAuthentication.svc" binding="basicHttpBinding" bindingConfiguration="SecureHttpBindingEndpoint" contract="Webservice1.ILocalAuthentication" name="SecureHttpBindingEndpoint" />
  <endpoint address=".../LocalAuthentication.svc" binding="basicHttpBinding" bindingConfiguration="SecureHttpBindingEndpoint" contract="WebService2.ILocalAuthentication" name="SecureHttpBindingEndpoint" />
</client>

The only difference between the endpoints is the contract - due to the fact that the service references were added with different names.

My question is Is it possible to only have one endpoint which both services use?

(Note that the projects are used independently in other solutions so it isn't really feasible to factor out a wrapper project just containing the service reference).

Upvotes: 1

Views: 1213

Answers (1)

C. Knight
C. Knight

Reputation: 749

The comments given, and in particular the clarification of @Tim explain why it is not possible for my two projects to both use the same endpoint. If any one else is having this issue and really needs to resolve it there seems to be two potential approaches:

  1. Create a Wrapper project actually containing the service reference and have both other projects use that.
  2. Rename the service references in the projects so that they have the same 'namespace'. When defining a service reference you can specify the 'namespace' which is used as the qualified name in the endpoint. If both projects have the same 'namespace' then they can use the same endpoint.

Note that I'm using the '', as the 'namespace' defined in this way is not the full namespace of the service reference, but rather is appended onto the namespace of the project that the service reference is added to. This means that there will not be any namespace conflicts if multiple projects have a service reference with the same 'namespace'.

In my case I was not able to take approach 1., but after some thought (and speaking to other code owners) I was able to take approach 2 by simply deleting and recreating one of the service references. Of course I could have just left it, having two endpoints for the same webservice in a config isn't the end of the world, but it just didn't seem neat.

Upvotes: 1

Related Questions