0

I'm trying to accomplish a SOAP request, which successfully returns the desired data in SoapUI, but fails to do so in Xcode using Objective-C for iOS.

// The SOAP message itself.
NSString *soapMessageString = [NSString stringWithFormat:@"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/"
                                                     "xmlns:ser=\"http://services.ws.fi.tav.aero\">"
                                                     "<soapenv:Header/>"
                                                     "<soapenv:Body>"
                                                     "<ser:getCurrentFlightList>"
                                                     "<code>IST</code>"
                                                     "<flightType>INT</flightType>"
                                                     "<flightLeg>DEP</flightLeg>"
                                                     "</ser:getCurrentFlightList>"
                                                     "</soapenv:Body>"
                                                     "</soapenv:Envelope>"];

// Calculate the SOAP message length
//  NSString *soapMessageLength = [NSString stringWithFormat:@"%lu", (unsigned long)[soapMessageString length]];

// The URL of the SOAP message.
NSURL *soapRequestURL = [NSURL URLWithString:@"<my-SOAP-url>"];
NSMutableURLRequest *soapRequest = [NSMutableURLRequest requestWithURL:soapRequestURL];

// HTTP Headers of the SOAP request
//  [soapRequest addValue:@"Wed, 12 Aug 2015 11:58:39 GMT" forHTTPHeaderField:@"Date"];
//  [soapRequest addValue:@"chunked" forHTTPHeaderField:@"Transfer-Encoding"];
//  [soapRequest addValue:@"HTTP/1.1 200 OK" forHTTPHeaderField:@"#status#"];
//  [soapRequest addValue:@"text/xml;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
//  [soapRequest addValue:@"keep-alive" forHTTPHeaderField:@"Connection"];
//  [soapRequest addValue:@"nginx/1.0.6" forHTTPHeaderField:@"Server"];
//  [soapRequest addValue:soapMessageLength forHTTPHeaderField:@"Content-Length"];

// Defining the connection method
[soapRequest setHTTPMethod:@"POST"];

// Combining the SOAP message(as NSData) into the request
[soapRequest setHTTPBody:[soapMessageString dataUsingEncoding:NSUTF8StringEncoding]];

// Making the connection
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:soapRequest delegate:self];

// Check the connection
if (connection) {
    _soapData = [NSMutableData data];
} else {
    NSLog(@"The connection is null!");
}

The piece of code above makes the request and then the delegate methods of NSURLConnectionDataDelegate retrieves and displays the data, in this case, the error message.

When the header information is commented out, the error I get is the following: Error reading XMLStreamReader.

And when it's not: 411 Length Required

Is there a difference in iOS in order for the SOAP request to be sent appropriately and retrieved successfully?

Can
  • 4,516
  • 6
  • 28
  • 50
  • Why you add HTTP response header values to request? – John Tracid Aug 12 '15 at 14:34
  • @JohnTracid I was checking the SoapUI app to see why it was performing and thought it might be the header values. Although the current one I'm coding version has the header values commented out. – Can Aug 12 '15 at 14:35
  • 1. You must provide `Content- Length`, `Content-Type` and maybe `SOAPAction` in header. 2. If you getting `Error reading XMLStreamReader` then something wrong with XML and you need to show it. – John Tracid Aug 12 '15 at 14:41
  • @JohnTracid I made an edit giving the contents of `soapMessageString`. Also enabled `Content-Type` and `Content-Length` headers. I checked the length value before and it was less then the one in SoapUI app but I doubt this is the reason. What should be the value of `SOAPAction`? – Can Aug 12 '15 at 14:52
  • @JohnTracid I added `SOAPAction` with the value of the URL. – Can Aug 12 '15 at 15:07
  • look at this question http://stackoverflow.com/questions/16445945/no-action-header-was-found-error-message-while-using-soap-webservice , some times we need to provide soap action in content type, also you can refer the connection request code from question link, one more thing for some old versions of soap formats, in soap request we need to convert < = < and > = > , it worked for us in past. – prasad Aug 12 '15 at 15:53
  • @CanSürmeli Hard to say what is still wrong. If you have access to server logs you could try to find more information. – John Tracid Aug 12 '15 at 17:03

0 Answers0