3

I am trying to create two separate endpoints that are hosted in two separate Windows Services. http: //mydevice/thisresource

http: //mydevice/thatresource

My app.config file for the first service looks like the following:

<service behaviorConfiguration="WebHttpServiceBehavior" name="MyService1">
  <endpoint address="" behaviorConfiguration="WebEndpointBehavior"
      binding="webHttpBinding" bindingConfiguration="StreamingWebHttpBinding"
      name="WebEndpoint" contract=MyContract" />
  <host>
    <baseAddresses>
      <add baseAddress="http://localhost" />
    </baseAddresses>
  </host>
</service>

In the contract for the first service, my method attributes look like this:

[OperationContract]
[WebInvoke(Method = "PUT", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "/this")]
bool PutThisResource(int i);

My app.config file for the second service looks like the following:

<service behaviorConfiguration="WebHttpServiceBehavior" name="MyService2">
  <endpoint address="" behaviorConfiguration="WebEndpointBehavior"
      binding="webHttpBinding" bindingConfiguration="StreamingWebHttpBinding"
      name="WebEndpoint" contract=MyContract2" />
  <host>
    <baseAddresses>
      <add baseAddress="http://localhost" />
    </baseAddresses>
  </host>
</service>

In the contract for the second service, my method attributes look like this:

[OperationContract]
[WebInvoke(Method = "PUT", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "/that")]
bool PutThatResource(int i);

This code is going to run on a standalone Windows device which the outside world will hit. I don't really want to use a URI naming convention like http://localhost/myservice1 and http://localhost/myservice2 because, like I said, I want everything to seem seamless to the user. The code behind is broken out into separate Windows Services for different reasons other than this external interface. This all runs on Windows Embedded and the vision is that the device is more of an appliance and the client has no insight to even what OS is running internally.

When I try to run both services, I get a AddressAlreadyInUseException. I assume from this post from 2009

Can several WCF services share a common BaseAddress?

that I can't use the same root address. Is there an easy way to share the root amongst separate Windows Services (AppDomains)?

I had some success not using baseAddress in the xml config and creating a separate WCF service for each path, but that's a lot of work.

Community
  • 1
  • 1

0 Answers0