Question

I have a Windows Azure Cloud Service project containing multiple Web Roles to host some services. I want to use ServiceX in ServiceY (each running on diffrent roles) using an relative URL.

Thats the way I host ServiceX:

<service name="ServiceX">
    <endpoint address="" binding="basicHttpBinding" contract="ServiceX" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>

Now I want to use that service in ServiceY. With an absolute URL it works fine:

<system.serviceModel>
    <client>
      <endpoint name="ServiceXProxy"
          address="http://mycloudservice.cloudapp.net:8080/ServiceX.svc"
          binding="basicHttpBinding"
          contract="ServiceX"/>
...

But how can I use the ServiceX in ServiceY with a relative address? Isn't that possible since they running on the same cloud service?

Was it helpful?

Solution

You could use relative addresses programmatically, but you still need to know the base address (or just use localhost:8080 as the base) - it's not possible to use relative addresses via the web.config unless you build a custom configuration or leverage AppSettings.

// create bindings & endpoints
var baseAddress = System.ConfigurationManager.AppSettings["baseAddress"];
var binding = new System.ServiceModel.BasicHttpBinding();
var endpoint = new EndpointAddress(baseAddress + "/ServiceX.svc");

You could also load the client endpoint address from the web.config and override the base address using UriBuilder for similar means.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top