6

I am calling a web service as below:

-(void)verifyEmailAndPasswordWebservices
{    
 NSString  *MD5Password = [ self MD5];
 NSLog(@"text field password %@",txt_Password.text);
 NSLog(@"converted password %@",MD5Password);    

NSString *soapMsg =[NSString stringWithFormat:
                    @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                    "<SOAP-ENV:Envelope SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:tns=\"http://php:8393/includes/webservice\">"
                    "<SOAP-ENV:Body>"
                    "<ns1:LoginUserRequest xmlns:ns1=\"http://schemas.xmlsoap.org/soap/envelope/\">"                        
                    "<email xsi:type=\"xsd:string\">%@</email>"
                    "<pass xsi:type=\"xsd:string\">%@</pass>"                   
                    "</ns1:LoginUserRequest>"
                    "</SOAP-ENV:Body>"
                    "</SOAP-ENV:Envelope>",txt_EmailOrMobile.text,MD5Password];



//---print it to the Debugger Console for verification---
NSLog(@"soapMsg..........%@",soapMsg);

NSURL *url = [NSURL URLWithString:@"http://10.0.0.115:8393/includes/webservice/login1.php"];
req = [NSMutableURLRequest requestWithURL:url];

//---set the headers---

NSString *msgLength = [NSString stringWithFormat:@"%d",[soapMsg length]];
[req addValue:@"application/soap+xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req addValue:@"http://10.0.0.115/includes/webservice/login1.php/LoginUser" forHTTPHeaderField:@"SoapAction"];
[req addValue:msgLength forHTTPHeaderField:@"Content-Length"];

//---set the HTTP method and body---

[req setHTTPMethod:@"POST"];
[req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];

// [activityIndicator startAnimating];

conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
if (conn)
{
    webData = [[NSMutableData data] retain];
}   
}

When i get the response it give me following error:

DONE. Received Bytes: 422 shows the XML (null) Parser error Error Domain=NSXMLParserErrorDomain Code=4 "The operation couldn’t be completed. (NSXMLParserErrorDomain error 4.)"

I've searched quite a bit on the internet. But not able to find anything. Any help on this please.

James Webster
  • 31,873
  • 11
  • 70
  • 114
Rushi
  • 4,553
  • 4
  • 33
  • 46

3 Answers3

8

NSXMLParserErrorDomain error 4 means that the XML parser was given an empty document. That suggests to me that the input was either null, or you've managed to change it before it's given to the parser.

I had a better look at your code. The problem isn't that you aren't getting a response. It's just that you're not waiting for it. The request you sent is asynchronous, but you're trying to fill your webData variable straight away (i.e. synchronously).

James Webster
  • 31,873
  • 11
  • 70
  • 114
  • Does this mean i have to speak to web service guy to check the response he is sending? Also the same web service is working in Android application. – Rushi Sep 05 '11 at 07:33
  • I've added to my answer, please let me know if that was indeed the problem. – James Webster Sep 05 '11 at 07:42
  • I've removed following lines from my code: if (conn) { webData = [[NSMutableData data] retain]; } Now im filling weData variable in following function: -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data it's no more giving NSXMLParserErrorDomain error 4. But it's giving following error now. Parser error Error Domain=NSXMLParserErrorDomain Code=5 "The operation couldn’t be completed. (NSXMLParserErrorDomain error 5.)" Im using PHP web service – Rushi Sep 05 '11 at 07:48
  • 1
    Error code 5 is: `NSXMLParserPrematureDocumentEndError = 5`. I'm not sure what this means in terms of your code, but I expect you don't have the entire repsonse. e.g. `entry 1 – James Webster Sep 05 '11 at 08:01
  • 3
    Note that if you ever see errors like this, you can hit Cmd+Shift+o in Xcode, type "NSXMLParserErrorDomain" and jump straight to the type definition along with (hopefully) all the error code definitions. – Mike Weller May 31 '12 at 13:19
1

Another possible reson might be that there is no root tag. example:A xml data like this--->


2011-12-22

<days_remaining>
            0
</days_remaining>
devashis
  • 11
  • 1
0

Try this code on your encoding method

NSString *theXML = [[NSString alloc] initWithBytes: [_responseData mutableBytes] length:[_responseData length] encoding:NSUTF8StringEncoding];
Hector
  • 3,909
  • 2
  • 30
  • 46
Gaurav Govilkar
  • 154
  • 1
  • 1
  • 10