0

Getting error while sending SOAP request to a .net web service, am I missing something here?

 NSString *str1 = [NSString stringWithFormat:@"<UserId>%@</UserId><Password>%@</Password><Referal>%@</Referal>",u,p,r];

NSString *soapMessage = [NSString stringWithFormat: @"<?xml version=\"1.0\" \encoding=\"utf-8\"?>" "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org /soap/envelope/\">""<soap:Body>""<getData xmlns=\"http://tempuri.org/\">\n"" <reqXML>%@</reqXML>""</getData>\n""</soap:Body>""</soap:Envelope>", str1];

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];

[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

[theRequest setHTTPMethod:@"POST"];

NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

[theRequest addValue: @"application/soap+xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];

[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];

I am using

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:theRequest];

The error I am getting is:

Error Domain=com.alamofire.networking.error Code=-1011 "Expected status code in (200-299), got 400" UserInfo=0x7536290 {NSErrorFailingURLKey=http://213.171.205.156/webservice_booking_affiliate_live/bookingengine.asmx, NSLocalizedDescription=Expected status code in (200-299), got 400}

I understand that 400 is for bad request, is there something that I need to add?

For .net service do we need to send anything else like for Android they have soapobject.dotnet=true

halfer
  • 19,824
  • 17
  • 99
  • 186
grk
  • 5
  • 8

2 Answers2

0

The most common reason for a 400 Bad Request error is because the URL was typed wrong or the link that was clicked on points to a URL with some kind of mistake in it.

May be your url contains a white space at the starting

manujmv
  • 6,450
  • 1
  • 22
  • 35
0

Friends Found the answer:::

Sometimes problems do occur while transmitting XML within the soap:body. The quick and dirty solution to fix it was to wrap the xml (only the parameters that you want to pass, like temperature or currency codes etc...) in a CDATA section, in this way:::

<![CDATA[%@]]>. This would mean that the XML parser will not parse that section. 

According to most blogs, that alone should work but if it doesn't work for you,

replace the < and > with "&lt;" and "&gt;". 

If it still doesn't work, change them back in your web service if you have access to it.

query = [query stringByReplacingOccurrencesOfString:@"<" withString:@"&lt;"];
query = [query stringByReplacingOccurrencesOfString:@">" withString:@"&gt;"];

Cheers friends, thanks for trying... ATB

grk
  • 5
  • 8