Over a million developers have joined DZone.

Single web service for multiple devices (IPhone, Windows Phone, Silverlight, Windows 8)

Online version is at : http://www.alphablog.org/2012/01/20/single-web-service-for-multiple-devices-iphone-windows-phone-silverlight-windows-8/
At Devoteam Luxembourg, our goal was to develop a cross platform application.

We have developed a set of application based on a single "web services server".
  • An IPhone, IPad, Android version with Sencha Touch
  • A Windows Phone 7 native version
  • A Silverlight version
  • A Windows 8 based on winRT version
This article will only talk about consuming web services on this 4 versions.  We add some constraints like activating HTTPS for enhancing security, taking care of enhancing speed for mobile devices, etc ... What is the conclusion of the adventure ?! :)
Global architecture

Iphone, IPad and Android

we had set up JSON for the first time for IPhone and it was easy in IPhone side. But WCF was a bit more lazy ...

Here is a sample of service header :
[WebInvoke(Method = "POST", UriTemplate = "SendRequest", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public string SendRequest(Stream multipartData)

we had to parse the multipartData stream and transform the JSON string with the JavaScriptSerializer...

Windows Phone

WCF setup was more easy.
public string SendRequest(string login, string password, int requestType, string startDate, string endDate, int startAM, int stopAM)

but we had to develop an "automatic certificate installer" for windows phone, based on http://wp7certinstaller.codeplex.com. If the phone does not have the certificate, it will be redirected on a website. We can't use not trusted webservices without installing the certificate. Same as silverlight and windows 8 behavior, we do not have access to the ServicePointManager :
ServicePointManager.CertificatePolicy = delegate { return true; };


The silverlight consume the same web service than windows phone. Otherwise, it was mandatory to install the client certificate.

Windows 8

Due to close timeline, we have give up installing https for Windows 8. We use Http binding over the windows phone web service. It only use an other endpoint on the Windows Phone.


The sheet below describe what we can do and with predefined configurations :

For information here is the web.config :
<?xml version="1.0"?>
<binding name="IPhoneBinding">
<security mode="Transport">
<transport clientCredentialType="None" />

<binding name="WP7Binding">
<security mode="Transport"/>
<binding name="WP7BindingNoHttps">

<behavior name="WebBehavior">
<webHttp />

<behavior name="TimeOffServiceBehaviors">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />

<behavior name="TimeOffApp.TimeOffServiceWP7Behavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />

<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />

<service behaviorConfiguration="TimeOffServiceBehaviors" name="TimeOffApp.TimeOffService">
<endpoint address="" behaviorConfiguration="WebBehavior" binding="wsHttpBinding" bindingConfiguration="IPhoneBinding"
name="IPhoneEP" contract="TimeOffApp.TimeOffService" />
<service behaviorConfiguration="TimeOffApp.TimeOffServiceWP7Behavior" name="TimeOffApp.TimeOffServiceWP7">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="WP7Binding" contract="TimeOffApp.TimeOffServiceWP7" />
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="WP7BindingNoHttps" contract="TimeOffApp.TimeOffServiceWP7" />

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}