+ Start a Discussion

HTTP POST Callout to .NET Web Service

Hello Everyone,


I have created a RESTFUL .NET Web Service using WCF. I want to integrate this web service within Salesforce.

My code for .NET and Salesforce is below. The problem i am facing right now is that whenever i populate the body and pass XML data my .NET web service returns bad request error. For testing my .NET Web service i had created a client in C# and also used tool called fiddler. It works fine for both of them.


My .NET Code,


Code for IService


[WebInvoke(UriTemplate = "getXML", Method = "POST", ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml)]
String getXML(XElement response);



Code for Service

public String getXML(XElement response)
return "Hello World";


My Salesforce APEX Code is,


 HttpRequest req = new HttpRequest();
req.setHeader('Content-Type', 'text/xml');

req.setCompressed(true); // otherwise we hit a limit of 32000
req.setHeader('Accept', 'text/xml;charset=utf-8');
String email='karnadesai@gmail.com';
string firstName='karna';
String requestString = '<list>'+


Http http = new Http();
HttpResponse res = http.send(req);



I get bad request error only when i set the body of request. I have to pass data using XML only to this web service. Thanks for your help

Best Answer chosen by Admin (Salesforce Developers) 

Problem Solved.

For some reason .NET does not expect compressed data and also there is no need setting content length explicitly.

Remove Following Lines

req.setCompressed(true); // otherwise we hit a limit of 32000