0

I've tried to connect to a SOAP API from a iOS application in objective c, xcode. First, i used a wsdl2objc to produce endpoint stubs for the access, but i got response status code 500 like this:

{ URL: http://api.tradera.com/v3/PublicService.asmx } { status code: 500, headers { "Cache-Control" = private; "Content-Length" = 509; "Content-Type" = "application/soap+xml; charset=utf-8"; Date = "Thu, 24 Mar 2016 17:36:24 GMT"; Server = "Microsoft-IIS/7.5"; "X-AspNet-Version" = "4.0.30319"; "X-Powered-By" = "ASP.NET"; } }

Now i have written my own SOAP request and that gives the same response. Is it the server's or my fault?

THIS is how i do it:

NSURL* url = [NSURL URLWithString:@"http://api.tradera.com/v3/PublicService.asmx"];
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url];
NSString* messageLength = [NSString stringWithFormat:@"%d",soapMessage.length];

[request addValue:@"api.tradera.com" forHTTPHeaderField:@"Host"];
[request addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request addValue:messageLength forHTTPHeaderField:@"Content-Length"];
[request addValue:@"http://api.tradera.com/GetSearchResultAdvanced" forHTTPHeaderField:@"SOAPAction"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

NSURLResponse* response;
NSError* error;
NSData* data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

if ([((NSHTTPURLResponse*)response) statusCode] != 200) {
    [ErrorService alertResponseFault:((NSHTTPURLResponse*)response)];
}
user2908112
  • 457
  • 6
  • 18
  • Can you provide anymore context? Generally, `500` means internal server error which means it's the server's fault. But it could be possible that the server doesn't handle malformed requests properly and instead of sending a `400 bad request`, it freaks out with a `500`, which would mean your request is wrong – Chris Mar 24 '16 at 17:45
  • I'm not sure what else is relevant. I use the exact sample request given as example on their website, but no luck. They have a separate SOAP 1.2 version which i also have tried. It's just depressing when simple things don't work, especially if i may not causing it. – user2908112 Mar 25 '16 at 08:43
  • Have you tried testing it in a client like SOAPUI? – Chris Mar 25 '16 at 14:38
  • Just tested with SOAPUI and it worked fine with that. Tried to copy the exact same request to my project, but failed with same response. – user2908112 Mar 27 '16 at 12:47
  • Now it works! Don't know what was wrong. Probably error in request body, which I somehow dragged with me in all my tests, very stupid. Thank you for SOAPUI Chris, that helped me finally get on right track. – user2908112 Mar 27 '16 at 15:27
  • Glad you got it working! No problem, tools like soapui are super useful for debugging networking problems that Xcode doesn't give as much detail about – Chris Mar 27 '16 at 15:29
  • hi @user2908112, I am getting the same error in my project. Can you please help me? – Anand Kr. Avasthi Apr 09 '19 at 09:23

0 Answers0