适用于 Silverlight 应用程序的 Azure WorkerRole 中的 WCF 服务
我有一个托管 WCF 服务的 Windows Azure WorkerRole。该服务应由 Silverlight 应用程序使用。在本地,这工作正常,但是,当我尝试部署它时,需要在角色配置中配置端点(见下图)。
当我删除该端点“WCFEndpoint”时,本地一切正常。但是,当它存在时,会发生以下异常:
System.ServiceModel.AddressAlreadyInUseException:HTTP 相关 URL “http://+:9196/GreenwayService/" 不注册,不属于 TCP 端口 第 9196 章
这意味着:HTTP 无法注册 URL“...”,因为 TCP 端口 9196 已被另一个应用程序使用。
据我了解,端点需要如图所示进行定义,以便在云内部进行访问。
这是我的 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>
这是启动服务的代码片段:
ServiceHost greenwayServiceHost = new ServiceHost(typeof(GreenwayService));
ServiceHost crossDomainServiceHost = new ServiceHost(typeof(CrossDomainService));
greenwayServiceHost.Open();
crossDomainServiceHost.Open();
为了在云中托管服务,我需要在这三个地方进行哪些更改?
I have a Windows Azure WorkerRole which hosts a WCF Service. This service shall be consumed by a Silverlight application. Locally, this works fine, however, when I try to deploy it, the endpoint needs to be configured in the Role configuration (see image below).
When I delete that endpoint "WCFEndpoint", everything works fine locally. However, when it is there, 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 URL "...", because the TCP PORT 9196 is used by another application.
As far as I understand, the endpoint needs to be defined like 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 the code snippet 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 those three places in order to host the services inside the cloud?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一个也是最重要的问题是您使用“localhost”作为绑定地址。这在 Windows Azure 中永远行不通。 Windows Azure 中的所有流量都(从负载均衡器)定向到角色实例 (VM) 的物理内部 IP 地址(也称为 DIP 或直接 IP 地址)。
为了使 Windows azure 中的工作正常,您必须绑定到角色实例的 DIP(直接 IP 地址)并使用输入端点提供的端口。我这样做(对于辅助角色和自托管 WCF):
这在本地开发和真实的 Azure 环境中 100% 有效。这里需要注意的是,我从角色的输入端点的 IPEndpoint 实例动态构建端点。
我非常确定,一旦您将服务绑定到从 RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["WCFEndpoint"]; 获取的实际 IP 地址和端口,您的服务就会按预期工作。
First and foremost issue is that you are using "localhost" as binding address. This will never work in Windows Azure. All the traffic in Windows Azure is directed (from the Load Balancers) to the physical internal IP address (also called DIP or Direct IP Address) of the role instance (VM).
In order to make things working in windows azure you have to bind to the DIP (Direct IP Address) of the instance of the Role and to use the port porvided by the Input Endpoint. I do it like that (for Worker Role and self hosted WCF):
And this works in 100% in local dev and real live Azure environment. The thing to note here is that I building my endpoint dynamically out from the IPEndpoint instance of my Role's Input Endpoint.
I'm pretty sure your services will work as expected once you bind them to the actual IP Address and port which you take from the RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["WCFEndpoint"];