WCF服务的Azure中的WorkerRole Silverlight应用程序 [英] WCF Service in Azure WorkerRole for Silverlight application

查看:169
本文介绍了WCF服务的Azure中的WorkerRole Silverlight应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows Azure的WorkerRole它承载WCF服务。该服务由Silverlight应用程序消耗。在当地,这工作正常,但是,当我尝试部署它,端点需要在角色配置进行配置(见下图)。

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).

当我删除端点WCFEndpoint,一切工作在当地罚款。然而,当它的存在,会出现以下异常:

When I delete that endpoint "WCFEndpoint", everything works fine locally. However, when it is there, the following exception occurs:

System.ServiceModel.AddressAlreadyInUseException:HTTP konnte死网址
  HTTP:// +:9196 / GreenwayService /nicht registrieren,韦尔DER TCP端口
  9196冯einer anderen Anwendung verwendet wird。

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

这意味着英语:HTTP不能注册网址......,是因为TCP端口9196是由另一个应用程序

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.

下面是我的app.config:

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>

这是code段启动服务:

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?

推荐答案

首先的问题是,您正在使用localhost作为绑定地址。这不会在Windows Azure中运行。在Windows Azure中的所有流量定向(由负载均衡器),以角色实例的物理内部IP地址(也称为DIP或直接IP地址)(VM)。

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).

为了让事情在Windows Azure的工作,你必须绑定到角色的实例的DIP(直接IP地址),并使用由输入端点porvided的端口。我那样做(对工作者角色和自我托管WCF):

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):

 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();
    }

和这部作品在100%的本地开发和现实生活的Azure的环境。这里要注意的一点是,我建立动态端点我脱离我的角色的输入端点的IPEndpoint实例。

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.

我是pretty确保您的服务将如预期,一旦你结合他们的实际IP地址和端口您从RoleEnvironment.CurrentRoleInstance.InstanceEndpoints [WCFEndpoint]取

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"];

这篇关于WCF服务的Azure中的WorkerRole Silverlight应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆