Windows Phone 上的 Azure Servicebus 中继

标签 azure windows-phone-7.1 servicebus

我有一个通过 Windows Azure 中继的客户端/服务器应用程序。 这对于服务器和客户端都使用控制台应用程序来说效果很好。

现在我想使用Windows Phone作为客户端,但由于某种原因,我无法调用servicebus。 我无法添加 Web 引用,当在浏览器中定位 URL 时,我收到以下消息:

<s:Fault xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><faultcode xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">a:ActionNotSupported</faultcode><faultstring xml:lang="nl-NL">The message with Action 'GET' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver.  Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).</faultstring></s:Fault>

我已在服务器 app.config 中输入以下代码:

// sb:// binding
            Uri sbUri = ServiceBusEnvironment.CreateServiceUri("sb", serviceNamespace, "blabla");
            var sbBinding = new NetTcpRelayBinding(EndToEndSecurityMode.Transport, RelayClientAuthenticationType.None);
            serviceHost.AddServiceEndpoint(typeof(IMyContract), sbBinding, sbUri);

            // https:// binding (for Windows Phone etc.)
            Uri httpsUri = ServiceBusEnvironment.CreateServiceUri("https", serviceNamespace, "https/" + "blabla");
            var httpsBinding = new BasicHttpRelayBinding(EndToEndBasicHttpSecurityMode.Transport, RelayClientAuthenticationType.None);
            serviceHost.AddServiceEndpoint(typeof(IMyContract), httpsBinding, httpsUri);

在打开主机之前,我将端点设置为公共(public)发现模式。

我还可以或需要做什么才能在 Windows Phone 上使用此功能?

最佳答案

我认为你已经相当接近了。据我所知,您无法将网络引用添加到您的手机项目中。虽然可以通过该路径实现这一点,但我不建议努力通过中继公开元数据端点,因为您不会在运行时使用它。相反,将契约(Contract)引用到您的 Windows Phone 项目中,并使用 BasicHttpBinding 和服务端 BasicHttpRelatBinding 端点的目标地址创建一个 ChannelFactory。

据我所知,您已经正确设置了其他所有内容,包括在监听器上关闭 ACS,以便您可以在手机上使用常规的 BasicHttpBinding。

编辑:

由于这可能不完全清楚,这里有一项服务:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
class Program : IEcho
{
    static void Main(string[] args)
    {
        var sh = new ServiceHost(new Program(), 
                    new Uri("http://clemensv.servicebus.windows.net/echo"));
        sh.Description.Behaviors.Add(
             new ServiceMetadataBehavior { 
                   HttpGetEnabled = true, 
                   HttpGetUrl = new Uri("http://localhost:8088/echowsdl")});
        var se = sh.AddServiceEndpoint(typeof(IEcho), 
             new BasicHttpRelayBinding(EndToEndBasicHttpSecurityMode.None, 
                                       RelayClientAuthenticationType.None), String.Empty);
        var endpointBehavior = new TransportClientEndpointBehavior(
               TokenProvider.CreateSharedSecretTokenProvider("owner", "...key ..."));
        se.Behaviors.Add(endpointBehavior);
        sh.Open();
        Console.WriteLine("Service is up");
        Console.ReadLine();
        sh.Close();
    }

    public string Echo(string msg)
    {
        return msg;
    }
}

契约(Contract) IEcho 很简单,没有显示。您会注意到,我有一个通过 localhost 暴露在“侧面”的 ServiceMetadataBehavior,如果您点击该 URI,它将为您提供 WSDL。您可以将该地址与 Visual Studio 中的“添加 Web 引用”客户端一起使用,以在 Windows Phone 上创建代理;该代理将在手机上使用 BasicHttpBinding。我刚刚这样做了,它在一个简单的手机应用程序中按预期工作(引用重命名为 MySvc)

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        var client = new MySvc.EchoClient();
        client.EchoCompleted += OnClientOnEchoCompleted;
        client.EchoAsync("foo");
    }

    void OnClientOnEchoCompleted(object sender, EchoCompletedEventArgs c)
    {
        this.textBox1.Text = c.Result;
    }

关于Windows Phone 上的 Azure Servicebus 中继,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10564405/

相关文章:

c# - 多个 Task<T> 或 IProgress<T> 用于部分完成?

c# - 到达 ScrollViewer 的底部 - 最大 VerticalOffset 值低于 ScrollableHeight

c# - 向服务总线 1.0 队列发送消息时发生套接字错误

azure - Azure 客户端 .OnMessage 是否为空队列生成计费请求?

powershell - 使用 powershell 获取返回对象中的第一个值

c# - 为什么我的WP7 App在屏幕右侧有一列乱七八糟的数字?

azure - Apache Spark 的 .Net UDF 必须可从 Azure Databricks Notebook 调用

c# - Azure ServiceBus SubscriptionClient.EndReceive() 返回 null

如果应用服务使用身份验证,Azure 通知中心设备注册失败

asp.net-mvc - 如何将 MVC3 Web 应用程序部署到 Azure