none
WCF in WP7 "The client and service bindings may be mismatched." RRS feed

  • Question

  • I create and tested a WCF service locally and of course it works fine.  I published to a shared hosting site and browsed to the wsdl and appears to be fine.  But when I make a call in WP7 code to the service I get an error with a useless error message.  After enabling includeExceptionDetailInFaults and WCF tracing the error reads. “System.ServiceModel.ProtocolException: Content Type application/soap+xml; charset=utf-8 was sent to a service expecting text/xml; charset=utf-8.  The client and service bindings may be mismatched.”

    Here are parts of the web.config

        <bindings>

           <basicHttpBinding>

             <!—- there is not a binding for this service should there be? -->

             <!—- other services… -->

           </basicHttpBinding>

        </bindings>

     

        <behaviors>

       <serviceBehaviors>

        <behavior name="SL_SeeYaThere_WCF.Web.SeeYaThereWCFBehavior">

         <serviceMetadata httpGetEnabled="true" />

         <serviceDebug httpHelpPageEnabled ="true" includeExceptionDetailInFaults="true"  />

        </behavior>

        <!—- other services… -->

       </serviceBehaviors>

      </behaviors>

    <services>

       <service behaviorConfiguration="SL_SeeYaThere_WCF.Web.SeeYaThereWCFBehavior" name="SL_SeeYaThere_WCF.Web.SeeYaThereWCF">

        <endpoint address="" binding="basicHttpBinding" contract="SL_SeeYaThere_WCF.Web.ISeeYaThereWCF" />

        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

       </service>

       <!—- other services… -->

      </services>

     

    This is my first experience with WFC and it hasn’t been enjoyable.  What am I doing wrong?

    Sunday, December 12, 2010 3:49 PM

Answers

  • Ok found the problem.  In the WP7 app there  is a ServicesReferences.clientConfig file that has the client bindings.  There were two end points for the WCF service one for Localhost and one for the shared hosted address.  It must have happened when I 'configure service reference' from the local host to shared host site.

    I changed the local host adderss to shared hosted addresss and it works.

    • Marked as answer by Frank Cowan Tuesday, December 14, 2010 4:44 AM
    Tuesday, December 14, 2010 4:44 AM

All replies

  • Hello,

    how did you create WP7 client? Your service exposes BasicHttp endpoint which expects SOAP 1.1 (content type text/xml) but your client sends requests in SOAP 1.2 (content type application/soap+xml). I don't understand WP7 programming model but you had to do something wrong when creating the client because it uses different binding with different message version. In WCF SOAP 1.2 is usually used in WsHttpBinding or CustomBinding.

    Best regards,
    Ladislav

    Sunday, December 12, 2010 8:28 PM
  • Thanks for the reply Ladislav.  I use the silverlight service utility that shipped with vs phone tools located at C:\Program Files\Microsoft SDKs\Windows Phone\v7.0\Tools\SlSvcUtil.exe with parameters AddressOfWSDL and "/ct:System.Collections.Generic.List`1". It created a client class that I added to WP7 Silverlight solution.  The class includes the line ...

    // This code was auto-generated by SlSvcUtil, version 3.7.0.0

     

     

     

     

    All that worked fine when hosted locally.  It wasn't until I published the service to a shared host that the error appeared.

    Is it possible that the shared host does not have something installed that is needed?  and If so what would I ask them to look for?

    Then I configure the service reference in VS setting Collection type to System.Collections.Generic.List and Dictionary collection type to System.Collections.Generic.Dictionary.  I also unchecked Reuse types in referenced assemblies.
    Sunday, December 12, 2010 11:10 PM
  • Ok found the problem.  In the WP7 app there  is a ServicesReferences.clientConfig file that has the client bindings.  There were two end points for the WCF service one for Localhost and one for the shared hosted address.  It must have happened when I 'configure service reference' from the local host to shared host site.

    I changed the local host adderss to shared hosted addresss and it works.

    • Marked as answer by Frank Cowan Tuesday, December 14, 2010 4:44 AM
    Tuesday, December 14, 2010 4:44 AM