0
votes

I have a problem with connecting WCF Service and Windows Phone. I have a service with no source code (only publish on web) and I need to use it in Windows Phone 7 App.

I add a service reference in project, VS generated me file ServiceReferences.ClientConfig:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="HttpBinding_IWcfMobilServices">
          <security mode="None" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://www.www.com/WcfMobilServices.svc"
          binding="basicHttpBinding" bindingConfiguration="HttpBinding_IWcfMobilServices"
          contract="MobileService.IWcfMobilServices" name="HttpBinding_IWcfMobilServices"></endpoint>
    </client>
  </system.serviceModel>
</configuration>

When i call a service method:

public static void Login()
{
    var proxy = new MobileService.WcfMobilServicesClient();
    proxy.LoginAsync("loginName", "paswword");
    proxy.LoginCompleted += (s, a) =>
        {
                //some code
        };
}

application in LoginCompleted throw me exception on a.Result :

System.ServiceModel.ProtocolException: Content Type text/xml; charset=utf-8 was not supported by service http://www.www.com/WcfMobilServices.svc. The client and service bindings may be mismatched. ---> System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound. at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) at System.Net.Browser.ClientHttpWebRequest.<>c_DisplayClasse.b_d(Object sendState) at System.Net.Browser.AsyncHelper.<>c_DisplayClass1.b_0(Object sendState) --- End of inner exception stack trace --- at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state) at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result) --- End of inner exception stack trace --- at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary() at W7App.MobileService.LoginCompletedEventArgs.get_Result()} System.ServiceModel.CommunicationException {System.ServiceModel.ProtocolException}

Any idea what's wrong?

I tried to change the Binding in config file to wsHttpBinding, but VS shows me a warning:

The element 'bindings' has invalid child element 'wsHttpBinding'. List of Possible elements expected: 'basicHttpBinding, CustomBinding'.

Thanks

1
If you proceed ahead with the warning what happens ? and this might be a possible duplicate : stackoverflow.com/questions/8250251/…cvraman
If i ignore warning in config, app throw me an error during creating instance of wcf class : Unrecognized element 'wsHttpBinding' in service reference configuration. Note that only a subset of the Windows Communication Foundation configuration functionality is available in Silverlight.Davecz
Silverlight / WP7 only support Basic HTTP unfortunately. Do you know if the end-point you are trying to connect to supports Basic HTTP Binding? It may be that it doesn't?Belogix
Really don't know. I have only describe of service methods and web addressDavecz
@Ex_animo - Try creating a simple console application and connecting to the end-point. That will allow wsHttpBinding etc. Does that work? If so looks like the end-point doesn't support basicHttpBinding and means you might have a lot more work to do!Belogix

1 Answers

2
votes

Following on from our conversation. Silverlight / Windows Phone 7 ONLY supports basicHttpBinding and CustomBinding. By creating a console application you were able to connect using wsHttpBinding. So, your options are:

  1. Ask for basicHttpBinding to be added to the end-point.
  2. Create another WCF service that sits between the Windows Phone and other WCF service. That way you can connect with basicHttpBinding and then the intermediate WCF can use wsHttpBinding to connect to the other service.

Obviously, option 2 will be slower and add complication and hassle on any updates but unless option 1 is possible I don't think you have many other choices.