1

我希望构建一个混合应用程序,在该应用程序中,我通过 Azure 网站公开托管在本地、防火墙后面的特定 WCF 服务。Azure 网站将简单地调用我的 WCF 服务来获取和放置数据。

我曾认为 Azure Connect to an Azure Service to specific WCF services on-premise 有一种方法,但现在我已经将它安装在我网络上的沙盒机器上,我不确定情况是否如此。如果我可以将 Azure 和我的网络之间的连接锁定到我指定的那些 WCF 服务,我会更喜欢,以获得额外的安全性。

让我的 WCF 服务暴露给我的 Azure 网站的选项有哪些?

4

2 回答 2

2

Azure 服务总线是你的朋友。您真正想要做的是启用服务总线中继,具体如下所述:

http://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-relay/

此外,您环境中的服务必须通过防火墙将自己暴露给服务总线。您可以在此处 (http://msdn.microsoft.com/en-us/library/windowsazure/ee706729.aspx) 找到一些方便的提示,尽管通常向服务总线注册的简单行为往往会为 NAT 和遍历您的基础设施。

服务总线支持多种中继绑定,如下所述:http: //msdn.microsoft.com/en-us/library/windowsazure/hh410102.aspx

我的博客上有一个关于 Service Bus 的演示文稿,示例代码有两个项目专门演示了中继。查看http://www.stratospher.es/blog/post/slides-and-code-from-dallas-july-10-2012-windows-azure-cloud-summit并在那里下载示例代码。您想要的两个项目是“RelayDemoServer”和“RelayDemoClient”。示例代码在代码中配置继电器,但如果这更符合您的风格,您也可以通过配置来执行此操作。

简而言之,您基本上必须在服务器端(在您的基础结构中)为您想要的服务创建 WCF 端点,然后在服务总线中创建等效的中继绑定。一旦发生这种情况,您最终将获得内部端点的服务总线托管版本。它看起来像这样:

// create the host itself...
System.ServiceModel.ServiceHost host =
    new ServiceHost(typeof(ProblemSolver));

// programmatically add the endpoints

// 1. the WCF endpoint "internally"
host.AddServiceEndpoint(
    typeof(IProblemSolver),
    new NetTcpBinding(),
    "net.tcp://localhost:9358/solver"
    );

// 2. the endpoint that is projected back through the service bus (note: NetTcpRelayBinding)
// This one will end up with a DNS name of "sb://[serviceNamespace].servicebus.windows.net/solver"
host.AddServiceEndpoint(
    typeof(IProblemSolver), 
    new NetTcpRelayBinding(),
    ServiceBusEnvironment.CreateServiceUri("sb", Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting("ServiceBusNamespace"), "solver"))
        .Behaviors.Add(new TransportClientEndpointBehavior
            {
                TokenProvider = TokenProvider.CreateSharedSecretTokenProvider("owner", Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting("ServiceBusSecret"))
            });

host.Open();

然后,在客户端,您只需通过服务总线使用服务。看起来像这样:

var cf = new ChannelFactory<RelayDemoServer.IProblemSolverChannel>(
    new NetTcpRelayBinding(),
    new EndpointAddress(
        ServiceBusEnvironment.CreateServiceUri(
            "sb", 
            Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting("ServiceBusNamespace"), 
            "solver"
            )
        )
    );

cf.Endpoint.Behaviors.Add(
    new TransportClientEndpointBehavior 
        { 
            TokenProvider = TokenProvider.CreateSharedSecretTokenProvider(
                "owner", 
                Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting("ServiceBusSecret")
                ) 
        }
    );

using (var ch = cf.CreateChannel())
{
    Console.WriteLine(ch.AddNumbers(4, 5));
}

秘诀是对 CreateServiceUri 的调用,它计算出 SB 托管的 URI。

希望这对您有所帮助,但如果您需要更多信息,请告诉我,

亚当霍夫曼

Windows Azure 博客 - http://stratospher.es

推特 - http://twitter.com/stratospher_es

于 2012-09-18T21:38:41.990 回答
0

在那个级别,Azure 网站只是一个调用现场 WCF 服务的客户端,需要打开防火墙以允许适当的调用进出。

查看 Azure 服务总线,但它是基于消息的。

于 2012-09-18T15:36:39.127 回答