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

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

问题描述

我有一个托管WCF服务的Windows Azure WorkerRole。此服务应由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 die URL
< a href =http:// +:9196 / GreenwayService / =nofollow noreferrer> http:// +:9196 / GreenwayService / nicht registrieren,weil der TCP-Port
9196

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

这意味着用英语:HTTP无法注册URL...,因为TCP PORT 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>

这是启动服务的代码片段:

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

我需要在这三个地方进行更改以便在云中托管服务? / p>

What do I need to change inside those three places in order to host the services inside the cloud?

推荐答案

首要的问题是你使用localhost作为绑定地址。这将永远不会在Windows Azure中工作。 Windows Azure中的所有流量都定向(从负载平衡器)到角色实例(VM)的物理内部IP地址(也称为DIP或直接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).

为了使事情在Windows Azure中工作,您必须绑定到角色实例的DIP(直接IP地址),并使用由输入端点提供的端口。我这样做(对于Worker角色和自己托管的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.

我很确定你的服务将正常工作一次您将它们绑定到您从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"];

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

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