Skip to content

Instantly share code, notes, and snippets.

@bhameyie
Created May 28, 2013 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhameyie/5666780 to your computer and use it in GitHub Desktop.
Save bhameyie/5666780 to your computer and use it in GitHub Desktop.
Datactontract serializer with json
public class UploadServceClient
{
RestClient RestClient;
public UploadServceClient()
{
RestClient = new RestClient("http://localhost/MyService");
}
public MyResponseMessage CallMyEndpoint(MyRequestMessage myRequest)
{
string body = HackyBodyCreation(myRequest);
var restRequest = new RestRequest(Method.POST);
restRequest.RequestFormat = DataFormat.Xml;
restRequest.Resource = "Myoperation";
restRequest.AddParameter("application/xml", body, ParameterType.RequestBody);
var restResponse = RestClient.Execute<MyResponseMessage>(restRequest);
return restResponse.Data;
}
private string HackyBodyCreation(MyRequestMessage myRequest)
{
var builder = new StringBuilder();
var serializer = new DataContractSerializer(typeof(MyRequestMessage));
var xmlWriter = XmlWriter.Create(builder);
serializer.WriteObject(xmlWriter,myRequest);
xmlWriter.Close();
return builder.ToString().Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>","");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment