views:

25

answers:

1

Hello,

I have an existing ASP.NET web application. This ASP.NET web application uses JQuery to provide a rich experience to the users. This user interface interacts with the server through some WCF services. A sample service looks like the following:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
[ServiceBehavior(IncludeExceptionDetailInFaults = false)]
public class myService : ImyService
{
  public bool SomeMethod(string parameter1, string parameter2)
  {
    try
    {
      return true;
    }
    catch (Exception ex)
    {
      return false;
    }
  }
}

I now want to expose this service to an iPhone and a Windows Phone 7 application. In an attempt to do this, I have configured the service like the following:

<system.serviceModel>      
  <behaviors>
    <endpointBehaviors>
      <behavior name="myServiceBehavior">
        <enableWebScript />
      </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
      <behavior name="">
        <serviceMetadata httpGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="false" />
      </behavior>
    </serviceBehaviors>
  </behaviors>

  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  <services>
    <service name="myService">
      <endpoint address="" behaviorConfiguration="myServiceBehavior"
        binding="webHttpBinding" contract="ImyService" />
    </service>
  </services>
</system.serviceModel>

The service works with the JQuery calls in my ASP.NET web application. I have not begun working on the iPhone client. But, when I try to expose this service to my WP7 client, I run into problems. As it stands now, when I launch my WP7 application, I receive an error that says:

KeyNotFoundException

If I change the binding in the config file to "basicHttpBinding", I cannot reference the service in Visual Studio. I receive an error that says:

The endpoint at 'http://machine:80/services/myService.svc' does not have a Binding with the None MessageVersion.  'System.ServiceModel.Description.WebScriptEnablingBehavior' is only intended for use with WebHttpBinding or similar bindings.

Ugh. How do I move forward? I thought WCF was designed to make this stuff easier. But I feel like I'm getting stuck doing something relatively basic.

Thank you for your help!

A: 

As far as I know (but I have no experience at all with iPhone or WinPhone development) you should be able to expose your WCF service using the regular webHttpBinding and no web script functionality, to get a normal REST style WCF service:

<system.serviceModel>      
   <services>
      <service name="myService">
         <endpoint 
             address="" 
             binding="webHttpBinding" 
             contract="ImyService" />
      </service>
   </services>
</system.serviceModel>

That alone should be sufficient - just browse to the virtual directory where your *.svc file is located and you should see your top-level resources in your browser.

The mobile devices typically don't support the SOAP-style bindings (like basicHttpBinding and so on) - so you need to use webHttpBinding instead (since that really only requires an HTTP client stack on the device - and every device these days definitely has this!)

marc_s