1

I have a client/server application through windows azure relaying. This works well using a console application for both server and client.

Now I want to use Windows Phone as a client, but for some reason, I cannot call the servicebus. I can't add a web reference and when targeting the url in a browser I get the following message:

<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>

I have entered the following code in the server 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);

And before opening the host, i'm setting the endpoints to discovery mode public.

What else can or do I need to do to make this work with windows phone?

2 Answers 2

2

I think you're fairly close. By what I gather you can't add the web reference to your phone project. While that's possible through that path, I wouldn't recommend to make the effort to expose the metadata endpoint through the Relay since you will not use it at runtime. Instead, reference the contract into your Windows Phone project and make a ChannelFactory with BasicHttpBinding and the target address for the BasicHttpRelatBinding endpoint on the service side.

You've got everything else set up right by what I can tell, including having ACS turned off on the listener so that you can use the regular BasicHttpBinding on the phone.

EDIT:

Since that probably wasn't completely clear, here's a service:

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

The contract IEcho is trivial and not shown. What you'll notice is that I have a ServiceMetadataBehavior hanging "off on the side" exposed through localhost that will give you WSDL if you hit that URI. You can use that address with the "Add Web Reference" client in Visual Studio to create the proxy on Windows Phone; that proxy will use BasicHttpBinding on the phone. I just did that and it works as expected in a trivial phone app (with the reference renamed to 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
  • 1
    Even tho i'm happy to see that i'm in the right direction, I can't seem to figure out how to call the webservice through basichttpbinding... By trying to use a normal call, I can't use the servicehost and channel, as the System.ServiceModel 4.0 version is not available in a windows phone project Commented May 15, 2012 at 8:51
0

Windows Phone doesn’t stand by the sb protocol. So we can’t use NetTcpRelayBinding. We have two options if we want to consume Service Bus in Windows Phone: Use BasicHttpRelayBinding or WebHttpRelayBinding. In either case, we need to disable the default ACS authentication by setting RelayClientAuthenticationType to None: http://msdn.microsoft.com/en-us/library/windowsazure/microsoft.servicebus.relayclientauthenticationtype.aspx. Then on Windows Phone, we can use the built-in BasicHttpBinding to access SOAP services, and use HttpWebRequest to access REST services.

Best Regards,

Ming Xu.

2
  • I have the relayclientauthentication set to none in the https binding above. The problem is that I have no idea how to call the service from the WindowsPhone solution Commented May 15, 2012 at 8:49
  • Actually, using Service Bus in Windows Phone is similar to using it in Silverlight. You can find a sample on code.msdn.microsoft.com/CSAzureServiceBusSLRest-41878c00. Commented May 16, 2012 at 10:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.