WCF Service in Azure WorkerRole for Silverlight

I have a Windows Azure desktop where the WCF service is located. This service must be used by the Silverlight application. Locally, this works fine, however, when I try to deploy it, the endpoint must be configured in the role configuration (see the figure below).

enter image description here

When I delete this โ€œWCFEndpointโ€ endpoint, everything works fine locally. However, when it exists, the following exception occurs:

System.ServiceModel.AddressAlreadyInUseException: HTTP konnte die URL " http: // +: 9196 / GreenwayService / " nicht registrieren, weil der TCP-Port 9196 von einer anderen Anwendung verwendet wird.

which means in English: HTTP could not register the URL "..." because TCP PORT 9196 is being used by another application.

As far as I understand, the endpoint must be defined as in the picture in order to be accessible inside the cloud.

Here is my app.config:

<?xml version="1.0"?> <configuration> <system.diagnostics> <trace> <listeners> <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics"> <filter type=""/> </add> </listeners> </trace> </system.diagnostics> <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup><system.serviceModel> <services> <service name="Greenway.AzureWorkerRole.ServiceHosting.CrossDomainService"> <endpoint address="" behaviorConfiguration="HttpEnableBehavior" binding="webHttpBinding" contract="Greenway.AzureWorkerRole.ServiceHosting.ICrossDomainService" /> <host> <baseAddresses> <add baseAddress="http://localhost:9196/" /> </baseAddresses> </host> </service> <service behaviorConfiguration="GreenwayServiceBehavior" name="Greenway.AzureWorkerRole.ServiceHosting.GreenwayService"> <endpoint address="" binding="basicHttpBinding" contract="Greenway.AzureWorkerRole.ServiceHosting.IGreenwayService" /> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> <host> <baseAddresses> <add baseAddress="http://localhost:9196/GreenwayService/" /> </baseAddresses> </host> </service> </services> <behaviors> <endpointBehaviors> <behavior name="HttpEnableBehavior"> <webHttp/> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="GreenwayServiceBehavior"> <serviceMetadata httpGetEnabled="True"/> <serviceDebug includeExceptionDetailInFaults="False" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration> 

And this is a piece of code starting the services:

 ServiceHost greenwayServiceHost = new ServiceHost(typeof(GreenwayService)); ServiceHost crossDomainServiceHost = new ServiceHost(typeof(CrossDomainService)); greenwayServiceHost.Open(); crossDomainServiceHost.Open(); 

What do I need to change inside these three places to host services inside the cloud?

+1
source share
1 answer

First of all, the problem is that you are using "localhost" as the binding address. This will never work on Windows Azure. All traffic in Windows Azure is directed (from the load balancer) to the physical internal IP address (also called DIP or direct IP address) of the role instance (VM).

To make everything work in azure windows, you must bind to the DIP (Direct IP Address) of the Role instance and use the port located through the input endpoint. I do it like this (for the role of working and stand-alone WCF):

  private void CreateServiceHost() { this._serviceHost = new UnityServiceHost(typeof(MyService)); var binding = new NetTcpBinding(SecurityMode.None); RoleInstanceEndpoint externalEndPoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["ServiceEndpoint"]; string endpoint = String.Format( "net.tcp://{0}/MyService", externalEndPoint.IPEndpoint); this._serviceHost.AddServiceEndpoint(typeof(IMyService), binding, endpoint); this._serviceHost.Open(); } 

And it works 100% in the local environment and the real Azure environment. It should be noted here that I am dynamically creating my endpoint from an IPEndpoint instance of my role input endpoint.

I am sure that your services will work as expected after binding them to the actual IP address and port , which you take from RoleEnvironment.CurrentRoleInstance.InstanceEndpoints ["WCFEndpoint"];

+2
source

Source: https://habr.com/ru/post/1385056/


All Articles