Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- .NET Development
- :
- HTTP POST Callout to .NET Web Service
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
HTTP POST Callout to .NET Web Service
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
08-10-2012 08:01 AM
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
[OperationContract] [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.setEndpoint(url);
req.setHeader('Content-Type', 'text/xml');
req.setCompressed(true); // otherwise we hit a limit of 32000
req.setMethod('POST');
req.setHeader('Accept', 'text/xml;charset=utf-8');
String email='karnadesai@gmail.com';
string firstName='karna';
String requestString = '<list>'+
'<user>'+'<userId>0</userId>'+'<userName>othmanelm oulat</userName>'+
'<password>123qwe</password>'+'<mainRoleId>5</main RoleId>'+
'<contact>'+'<email>'+email+'</email>'+
'<firstName>'+firstName+'</firstName></contact>'+
'</user></list>';
req.setHeader('Content-Length',String.valueOf(requ estString.length()));
req.setBody(requestString);
Http http = new Http();
HttpResponse res = http.send(req);
System.debug(res.getBody());
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
Solved! Go to Solution.
Re: HTTP POST Callout to .NET Web Service
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
08-10-2012 10:39 AM
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
req.setHeader('Content-Length',String.valueOf(requ estString.length()));

