I created application of calling https soap service(with transport security), but i get status code of 400 with null
webdata
.My code is:
/
- (NSString* )serviceCall{
NSString *soapActionURL;
soapActionURL=[NSString stringWithFormat: @"http:/
NSString *soapMessage = [NSString stringWithFormat:
@"<s:Envelope xmlns:s=\"http:/
" <s:Body>\n"
"<GetData xmlns=\"http:/
"<value>10</value>\n"
"</GetData>\n"
"</s:Body>\n"
"</s:Envelope>\n"];
url = [NSURL URLWithString:@"https:/
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%lu", (unsigned long)[soapMessage length]];
NSData* bodyData = [soapMessage dataUsingEncoding:NSUTF8StringEncoding];
NSUInteger bodyDataLength = [bodyData length];
[theRequest setTimeoutInterval:10.0f];
[theRequest addValue: @"application/soap+xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: soapActionURL forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: [NSString stringWithFormat:@"%lu", (unsigned long)bodyDataLength] forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: bodyData];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
webData = [NSMutableData data] ;
}
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
/
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSLog(@"Status code %ld", (long)[httpResponse statusCode]);
[webData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
/
[webData appendData:data];
}
- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
NSMutableArray *list =[[NSMutableArray alloc]init];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:webData];
NSString *xmlData = [[NSString alloc]
initWithBytes:[webData mutableBytes]
length:[webData length]
encoding:NSUTF8StringEncoding];
NSLog(xmlData);
}
/
- (BOOL) connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
/
BOOL authResult;
authResult= [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
/
if(authResult)
{
NSLog(@"Auth is Ok");
}
return authResult;
}
- (void) connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
NSLog(@"___didReceiveAuthenticationChallenge");
if([challenge.protectionSpace.authenticationMethod isEqualToString: NSURLAuthenticationMethodServerTrust]) {
/
if ([challenge.protectionSpace.host isEqualToString: challenge.protectionSpace.host]) {
NSLog(@"trusting connection to host %@", challenge.protectionSpace.host);
NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
[challenge.sender useCredential:credential forAuthenticationChallenge:challenge];
}
}
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
-(void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"@%",error);
}
I get following Result:
WSServiceTest[2988:54075] Auth is Ok
WSServiceTest[2988:54075] ___didReceiveAuthenticationChallenge
WSServiceTest[2988:54075] trusting connection to host 192.168.0.10
WSServiceTest[2988:54075] Status code 400
WSServiceTest[2988:54075] (null)
Also on debug i get:
/
<NSHTTPURLResponse: 0x7fa80a78c8b0> { URL: https://192.168.0.10/Service/Service1.svc } { status code: 400, headers {
"Content-Length" = 0;
Date = "Thu, 18 Feb 2016 05:59:37 GMT";
Server = "Microsoft-IIS/7.5";
"X-Powered-By" = "ASP.NET";
} }
How can i get proper result? or what is wrong in my code?