Hi,
I'm trying to get a soap response that returns an array of objects and each object has 10 strings from a web service after passing a string to the soap request.
The problem is that I'm getting this response:
The page cannot be displayed because an internal server error has occurred.
The web service has 4 methods. One of them returns a string with no problem but the other 3 that return arrays gave me that response.
the soap1.1 request and response looks like the following:
Code:
POST /theService/the.asmx HTTP/1.1
Host: theHost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://namespace/method"
<?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>
<method xmlns="http://namespace/">
<param>string</param>
</method>
</soap:Body>
</soap:Envelope>
Code:
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?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>
<methodResponse xmlns="http://namespace/">
<methodResult>
<_class>
<param1>string</param1>
<param2>string</param2>
<param3>string</param3>
<param4>string</param4>
<param5>string</param5>
<param6>string</param6>
<param7>string</param7>
<param8>string</param8>
<param9>string</param9>
<param10>string</param10>
</_class>
<_class>
<param1>string</param1>
<param2>string</param2>
<param3>string</param3>
<param4>string</param4>
<param5>string</param5>
<param6>string</param6>
<param7>string</param7>
<param8>string</param8>
<param9>string</param9>
<param10>string</param10>
</_class>
</methodResult>
</methodResponse>
</soap:Body>
</soap:Envelope>
------------------------------------
I establish the connection and print the response in NSSLog when passing values to WebServiceHelper class as follows:
Code:
#import "WebServiceHelper.h"
@implementation WebServiceHelper
@synthesize MethodName;
@synthesize MethodParameters;
@synthesize XMLNameSpace;
@synthesize XMLURLAddress;
@synthesize SOAPActionURL;
@synthesize MethodParametersAsString;
- (NSMutableData*)initiateConnection
{
NSString *lastChar;
NSString *slashUsed;
lastChar = [self.XMLNameSpace substringFromIndex:self.XMLNameSpace.length -1];
if([lastChar isEqualToString:@"/"]){
slashUsed = @"";
}
else
{
slashUsed = @"/";
}
NSMutableString *sRequest = [[NSMutableString alloc] init];
self.SOAPActionURL = [NSString stringWithFormat:@"%@%@%@",self.XMLNameSpace, slashUsed, self.MethodName];
//make soap request
[sRequest appendString:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"];
[sRequest appendString:@"<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/\">"];
[sRequest appendString:@"<soap:Body>"];
[sRequest appendString:[NSString stringWithFormat:@"<%@ xmlns=\"%@\">",MethodName, XMLNameSpace]];
if(MethodParametersAsString != nil) [sRequest appendString:MethodParametersAsString];
NSEnumerator *tableIterator = [MethodParameters keyEnumerator];
NSString *keyID;
while((keyID = [tableIterator nextObject]))
{
[sRequest appendString:[NSString stringWithFormat:@"<%@>%@</%@>", keyID, [MethodParameters objectForKey:keyID], keyID]];
NSLog(@"Method: %@ Parameter:%@ Value:%@",self.MethodName, keyID, [MethodParameters objectForKey:keyID]);
NSLog(@"<%@>%@</%@>", keyID, [MethodParameters objectForKey:keyID], keyID);
}
//close envelope
[sRequest appendString:[NSString stringWithFormat:@"</%@>", MethodName]];
[sRequest appendString:@"</soap:Body>"];
[sRequest appendString:@"</soap:Envelope>"];
//NSLog(sRequest);
//The URL of the Webserver
NSURL *myWebserverURL = [NSURL URLWithString:XMLURLAddress];
//SSL certificate set up
[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[myWebserverURL host]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myWebserverURL];
// Add the Required WCF Header Values. This is what the WCF service expects in the header.
[request addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request addValue:self.SOAPActionURL forHTTPHeaderField:@"SOAPAction"];
// Set the action to Post
[request setHTTPMethod:@"POST"];
// Set the body
[request setHTTPBody:[sRequest dataUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"\n \n this is sRequest: %@ \n \n", sRequest);
NSLog(@"\n \n this is request: %@ \n \n", [request valueForHTTPHeaderField:@"SOAPAction"]);
[sRequest release];
NSError *WSerror=nil;
NSURLResponse *WSresponse=nil;
// Call the xml service and return response into a MutableData object
NSMutableData *myMutableData = (NSMutableData *)[NSURLConnection sendSynchronousRequest:request returningResponse:&WSresponse error:&WSerror];
NSLog(@"\n \n this is WSresponse: %@ \n \n this is WSerror: %@ \n \n", WSresponse, WSerror);
if (WSerror) {
NSLog(@"Connection Error: %@", [WSerror description]);
}
NSString *theXml = [[NSString alloc] initWithBytes:[myMutableData mutableBytes] length:[myMutableData length] encoding:NSUTF8StringEncoding];
NSLog(@"response: %@", theXml);
[theXml release];
return myMutableData;
}
-(void)dealloc
{
[MethodName release];
[MethodParameters release];
[XMLNameSpace release];
[XMLURLAddress release];
[SOAPActionURL release];
[MethodParametersAsString release];
[super dealloc];
}
@end
-------------------------------
I just want to make sure that there is response so i can continue
so, why do i get that response and what is the solution for it?
and for XMLParser, how do u suggest me to do it?
thank you