» Create/Consume REST WebService using WCF and Universal Apps
Create/Consume REST WebService using WCF and Universal Apps
|September 2, 2014
Posted by forumadmin
I want to create an IIS-hosted webservice which I will consume using a universal windows store aoo (windows phone/windows 8.1/windows RT).
As I understand universal applications do not support proxy class generation and SOAP calls using “Add service reference” so I need to create a RESTful webservice and manually consume it in the universal application.
I’ve tried dozens of tutorials and approaches throughout the net but I never managed to actually POST data to the webservice.
I need to send objects of a custom class which is defined in a shared library to the webservice. I understand that I will need to serialize the Object and include it in the POST request, however no matter what I try I end up with different issues – e.g HTTP 400 Bad Request: The incoming message has an unexpected message format ‘Raw’. The expected message formats for the operation are ‘Xml'; ‘Json’.
I’ve seen several approaches to manually set the content type header, however the methods I found are not available in a universal application.
Can someone provide information or an example which is fitting my scenario (POST-ing via universal app)?
update 1: For further clarification: I am aware how WCF works and I was already able to complete a basic GET request like described in this post. However I was unable to extend that to also work with POST requests.
Some code I’ve tried:
public async static void SendStartup(CustomClass customObject)
var httpClient = new HttpClient();
var serialized = JsonConvert.SerializeObject(customObject);
var response = await httpClient.PostAsync("http://localhost:49452/Metrics.svc/LogStartup", new StringContent(serialized));
string content = await response.Content.ReadAsStringAsync();
Web Service Interface:
[WebInvoke(UriTemplate = "LogStartup", Method="POST", BodyStyle=WebMessageBodyStyle.Wrapped)]
string LogStartup(CustomClass obj);
public void LogStartup(CustomClass obj)
This for example failes at runtime with the error mentioned above
More Related Questions
- Calling Rest WCF Service under RP in WP8 applications I'm trying to call a REST webservice who is under a Reverse Proxy.
I'm sure that login, domain and password are correct.
I use the HTTPClient portable lib.
private async void […]
- how to implement interoperable web service that returns generated bit map? I have only implemented WCF Web Services generated from WSDL with WSCF Blue. They are synchronized WSs that have simple type elements in messages to both ways.
Now I need to do something […]
- How to Deploy WCF Class Library Project on My Domain Name I've created a wcf class library project which connects to a sql server 2008 database and does some work and I want to publish this service, so that all our clients can have access to it, […]
- How to read and parse the json response from a WCF Restful service in an ASP.net web application? I have a restful wcf service URI like below
It's a GET method and return a list of products brands by passing product […]
- System.Runtime.Serialization.SerializationException on a string value I have a WCF REST service that is returning a business object that contains a string field called 'GeoDataKML'. This field is just a string value, but it has KML string inside it […]
- Calling methods on an old Web Service build in .Net 2.0 from a WCF Client This is an bit of an unknown for me but ill go ahead and ask anyway.
Our company has an old legacy webservice which is no longer maintained built on .NET 2. Adding a "Web Reference" to a […]
- Windows identity creation using WCF I have one WCF REST service which was exposed as the Windows Authenticated service in the server machine.
As the service is windows authenticated, iam able to form the WindowsIdentity of […]
- .NET Web-service – To SOAP or not to SOAP I have a XSD that I have generated classed from. After filling a class with data and serialize it, I want to send it to one or more specific clients.
My plan is to use SOAP, but the only […]
- WCF REST partial class/interface – endpoint not found issue The following code leads to "service endpoint not found" error. it uses partial class and partial interface. When i don't use partial class/interface, it works fine ...any […]
- Generic argument property causes error on WebService Service:
The error is with a type that has ChainedListNode<T>. Thing is, when I remove the DataMemberAttribute from Value, the service works.
public class […]