2012-05-12 20 views
1

私はWindows Azure Relayを介してクライアント/サーバーアプリケーションを持っています。 これは、サーバーとクライアントの両方にコンソールアプリケーションを使用するとうまくいきます。Windows Phone上のAzure ServiceBusリレー

今は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); 

そして、ホストを開く前に、エンドポイントを公開モードに設定します。

Windows Phoneでこの作業を行うには、他に何が必要ですか?

答えて

2

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

あなたは電話で通常のBasicHttpBindingを使うことができるように、リスナーでACSをオフにすることを含め、私が知ることができるものだけをセットアップしました。

EDIT:

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

[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は些細と示されていない契約。あなたが気づくのは、localhostを通して公開されている "off側"にぶら下がっている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; 
    } 
+1

でも私は正しい方向に向いていることを嬉しく思っています。私はbasichttpbindingを通じてWebサービスを呼び出す方法を理解できないようです...通常の呼び出しを使用しようとすると、 Windows PhoneプロジェクトではSystem.ServiceModel 4.0バージョンが利用できないため、servicehostとチャネルを使用してください –

+0

これは魅力的なように機能しました!ありがとうすべては今働いています:) –

0

のWindows Phoneは、SBプロトコルによって立っていない些細な電話アプリに期待作品。 NetTcpRelayBindingを使用することはできません。 Windows Phoneでサービスバスを使用する場合は、2つの方法があります。BasicHttpRelayBindingまたはWebHttpRelayBindingを使用します。どちらの場合でも、RelayClientAuthenticationTypeをNone:http://msdn.microsoft.com/en-us/library/windowsazure/microsoft.servicebus.relayclientauthenticationtype.aspxに設定することで、デフォルトのACS認証を無効にする必要があります。 Windows Phoneでは、組み込みのBasicHttpBindingを使用してSOAPサービスにアクセスし、HttpWebRequestを使用してRESTサービスにアクセスできます。

よろしく、

明徐。

+0

上記のhttpsバインディングでrelayclientauthenticationをnoneに設定しました。問題は、Windows Phoneソリューションからサービスを呼び出す方法がわかりません。 –

+0

実際、Windows Phoneでサービスバスを使用することは、Silverlightで使用する方法と似ています。サンプルはhttp://code.msdn.microsoft.com/CSAzureServiceBusSLRest-41878c00で見つけることができます。 –

関連する問題