Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 07-26-2011, 07:14 AM   #1 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 6
Smaher is on a distinguished road
Exclamation returning array of objects' problem,, SOAP,, Web service (urgent please)

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


Last edited by Smaher; 07-26-2011 at 07:19 AM.
Smaher is offline   Reply With Quote
Old 08-10-2011, 03:04 PM   #2 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 5
clarket2 is on a distinguished road
Default

I had similar problems and then started to use the ASIHttpRequest library which worked much better. ASIHTTPRequest Documentation - All-Seeing Interactive

If you getting a 500 error then its most likley something in the request that the server cant deal with. If you set up an inline proxy, something like tcpmon, webscarab or burp suite you will be able to intercept the SOAP message and it will make your problem easier to troubleshoot.

I was able to parse with the NSXMLParser class.
clarket2 is offline   Reply With Quote
Old 08-11-2011, 03:59 AM   #3 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

take a look to this tutorial: WebService [How-To]

However I advice you to not hardcode the soap message in the code....
__________________
dany_dev is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 385
18 members and 367 guests
Absentia, AyClass, bignoggins, Diligent, dre, givensur, hussain1982, jbro, jPuzzle, LunarMoon, momolgtm, Newbie123, Paul10, revg, skog, taylor202, tomtom100
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,643
Threads: 94,110
Posts: 402,858
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Diligent
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:46 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0