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
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:
basicHttpBinding
to be added to the end-point. 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.