SOAP requests with Cocoa

I'm just trying to send some xml data to a soap server. While I may not have found the 'correct' way of doing it, I did find some information on sending data within the Apple documentation.

NSData *XMLdata = [soapXML XMLDataWithOptions:NSXMLNodePrettyPrint];
NSURL *webserviceURL = [NSURL URLWithString:@"http://soap.example.com/soap.php"];
NSMutableURLRequest *URLrequest = [NSMutableURLRequest requestWithURL:webserviceURL];
[URLrequest setHTTPMethod:@"POST"];
[URLrequest setValue:@"text/xml" forHTTPHeaderField:@"Content-type"];
[URLrequest setValue:@"http://soap.example.com/soap.php/login" forHTTPHeaderField:@"Soapaction"];
[URLrequest setHTTPBody: XMLdata];

NSURLConnection *connectionResponse = [[NSURLConnection alloc] initWithRequest:URLrequest delegate:self];
if(!connectionResponse) {
NSLog(@"Failed to submit request");
} else {
NSLog(@"Request submitted");
receivedData = [[NSMutableData data] retain];
}

As you can see we are creating some POST data and sending an NSData object across. I'm building up the SOAP envelope by loading up the basic envelope structure from a file then adding the correct data using the NSXMLDocument classes.

NSXMLDocument *soapXML = [[NSXMLDocument alloc] initWithContentsOfURL:[NSURL fileURLWithPath:envelopePath] options:NSXMLDocumentTidyXML error:&error];

Then we add the extra nodes:

NSXMLElement *rootElement = [soapXML rootElement];
NSXMLElement *soapBody = [NSXMLElement elementWithName:@"SOAP-ENV:Body"];

// Now create the actual login block of the envelope
NSXMLElement *loginNode = [NSXMLElement elementWithName:@"m:login"];
NSDictionary *loginAttribs = [NSDictionary dictionaryWithObjectsAndKeys:serverURL, @"xmlns:m", nil];
[loginNode setAttributesAsDictionary:loginAttribs];

[soapBody addChild:loginNode];
[rootElement addChild:soapBody];

Now you can use the NSURLConnection correctly.

Because we are using a delegate of 'self' we'll need to implement the relevant methods to cope with the data as it comes in. For that, I'd say read this document and familiarise yourself with the callbacks: http://developer.apple.com/documentation/Cocoa/Conceptual/URLLoadingSyst...