1

Windows azure リレーを介したクライアント/サーバー アプリケーションがあります。これは、サーバーとクライアントの両方にコンソール アプリケーションを使用するとうまく機能します。

Windows Phone をクライアントとして使用したいのですが、何らかの理由でサービスバスを呼び出すことができません。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 で機能させるには、他に何ができるか、または行う必要がありますか?

4

2 に答える 2

2

私はあなたがかなり近いと思います。私が収集したところによると、Web 参照を電話プロジェクトに追加することはできません。そのパスを介してそれは可能ですが、実行時に使用しないため、Relay を介してメタデータ エンドポイントを公開する努力をすることはお勧めしません。代わりに、コントラクトを Windows Phone プロジェクトで参照し、サービス側で BasicHttpBinding と BasicHttpRelatBinding エンドポイントのターゲット アドレスを使用して ChannelFactory を作成します。

電話で通常の BasicHttpBinding を使用できるように、リスナーで ACS をオフにするなど、他のすべてが正しく設定されています。

編集:

それはおそらく完全に明確ではなかったので、ここにサービスがあります:

[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;
    }
}

コントラクト IEcho は自明であり、示されていません。お気づきのことと思いますが、ServiceMetadataBehavior が "脇に" ぶら下がっていて、その URI にヒットした場合に WSDL を提供する localhost を介して公開されています。そのアドレスを 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;
    }
于 2012-05-12T18:57:14.123 に答える
0

WindowsPhoneはsbプロトコルをサポートしていません。したがって、NetTcpRelayBindingを使用することはできません。Windows Phoneでサービスバスを使用する場合は、BasicHttpRelayBindingまたはWebHttpRelayBindingの2つのオプションがあります。いずれの場合も、RelayClientAuthenticationTypeをNoneに設定して、デフォルトのACS認証を無効にする必要があります:http://msdn.microsoft.com/en-us/library/windowsazure/microsoft.servicebus.relayclientauthenticationtype.aspx。次に、Windows Phoneでは、組み込みのBasicHttpBindingを使用してSOAPサービスにアクセスし、HttpWebRequestを使用してRESTサービスにアクセスできます。

よろしくお願いします、

明徐。

于 2012-05-14T07:52:09.310 に答える