0
votes

I have a Azure Project with 2 Web Roles (An Azure Web Site Project and an Azure WCF Service Role). The WCF service is consumed by the Azure Web Site Project and is referred using the "Add Service Reference" option. The website uses URL defined in the in the web.config to connect to the WCF service which works fine in the local dev/Azure compute emulator. In my local dev machine, when I run the solution, the service & website are loaded and executed in the IIS Express with URL "http://127.0.0.1:8080/v1.svc" and the "http://127.0.0.1:81/" respectively.

However when I published the application on Azure Cloud Services, it created a seperate machine/VM/Instance for the website and the service respectively (since they are considered as two different role's).

Now my question is, since Azure assigns the IP for the instances at runtime, how should I dynamically change the URL in the (in Website's web.config) and update the WCF service to enable the website consume the WCF service seamlessly?

Appreciate your time.

Thanks, Karthik.

2

2 Answers

0
votes

Thanks for your response. I tried the solution but was getting a 404 error. In my case the webrole name is "TimeSheetUI" and when i tried to access the the service using "timesheetui.cloudapp.net:8080" it throws 404 error. However if i try accessing it using http://e214d16594be4e31abfbf0488b5d612b.cloudapp.net:8080/timesheetservices.svc it works. I hope I dont need to add any CNAME entries with DNS etc., to make it to work.

However I tried the programmatic option to build the URL at runtime with the service endpoint's Type option set to "Internal".

var endpoints = RoleEnvironment.Roles["TimeSheetService"].Instances.Select(i => i.InstanceEndpoints["TimeSheetService.EndPoint"]).ToArray();
var r = new Random();
EndpointAddress endPointAddress = new EndpointAddress(String.Format("http://{0}/TimeSheetService.svc", endpoints[r.Next(endpoints.Count() - 1)].IPEndpoint));
var factory = new ChannelFactory<TimeSheetProxy.ITimeSheet>("BasicHttpBinding_ITimeSheet");var client = factory.CreateChannel(endPointAddress);TimeSheetUI.TimeSheetProxy.TimeSheet[] ts = client.DisplayTimeSheets();

The above code works fine without issues. But not sure if this is an elegant way of getting it done!

Found the above solution @ http://lab.studiopesec.com/azure-applications-101-part-ii/

-1
votes

Specify the endpoint/port for your service in the ServiceConfig file:

<ServiceDefinition name="MyService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
   <WebRole name="WCFServiceRole">
      …
      <Endpoints>
         <InputEndpoint name="HttpIn" protocol="http" port="8080" localPort="8080" />
      </Endpoints>
   </WebRole>
   <WebRole name="MyWebRole">
      …
      <Endpoints>
         <InputEndpoint name="HttpIn" protocol="http" port="80" localPort="80" />
      </Endpoints>
   </WebRole>
   …
</ServiceDefinition>

Then in your web.config, specify the WCF endpoint using the Azure DNS and port (i.e. mywebrole.cloudapp.net:8080

For more info, reference - Guidance for Using WCF in Windows Azure