We have a web service up and running built in VS2010.
Several of the operational contracts looks like this:
[OperationContract]
ITicket Login(string userName, byte[] passwordHash, string softwareVersion);
I.e. they booth have complex arguments and complex return types, or even multiple returns.
We have recently started an outsourced iPhone project and are letting them use this service to communicate with our server. From what I have learnt from them I understood that this is not a good practice for communicating to the iPhone (lack of good ways to consume the WSDL for example). And therefore I have started to look at the possibility to expose the service as a REST service communicating with JSON.
I have added a new endpoint, using webHttpBinding, decorated the contracts like this:
[OperationContract]
[WebGet(UriTemplate = "/login?username={userName}&password={password}&softwareVersion={softwareVersion}", ResponseFormat=WebMessageFormat.Json)]
ITicket Login(string userName, string password, string softwareVersion);
This method now works as intended.
I then tried to decorate another method as this:
[OperationContract]
[WebGet(UriTemplate = "/GetMetaData?ticket={ticket}",RequestFormat=WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
IMetaData GetMetaData(ITicket ticket);
When I now try to access this I receive the following error:
Server Error in '/Jetas5MobileService' Application. Operation 'GetMetaData' in contract 'IJetas5MobileService2' has a query variable named 'ticket' of type 'Jetas.MobileService.DataContracts.ITicket', but type 'Jetas.MobileService.DataContracts.ITicket' is not convertible by 'QueryStringConverter'. Variables for UriTemplate query values must have types that can be converted by 'QueryStringConverter'.
I have manage to build a OperationContract that only takes a string as argument and then parses thin in the back end by using DataContractJsonSerializer
, but that feels more like a ugly hack.
Is there any way to solve this in a better manner? I am beginner when it comes to WCF and REST so do not be afraid to point me to any beginner tutorials that there might be out there. I have tried to search for them but the vast amount of sources makes it hard to find the good ones.