i am developing iphone and android app that capable of accessing soap web service. in android i become much easier with ksoap2 third party library. but when i comes to iphone i dont have any library or inbuilt methods for that.
I surfed in web i got the link http://iphonedevsdk.com/forum/iphone-sdk-development/39819-how-to-call-wcf-service.html. i tried the same procedure but i got status code 400 (The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.).
the request format
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/IService1/Logindetails
</Action>
</s:Header>
<s:Body>
<Logindetails xmlns="http://tempuri.org/">
<value> {"SessionId":"dfg45fsg","IpAddress":"192.168.0.1","UserName":"tiru123","Password":"ku204","MacAddress":"192:158:012:45","IMEINo":"testno","Location":"Adyar"}</value>
</Logindetails>
</s:Body>
</s:Envelope>
response format
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<ActivityId CorrelationId="57d29115-decc-4d40-8716-2495ee9d9c20" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">a5d15743-7290-41fd-a7e6-47f8a1dc23d6</ActivityId>
</s:Header>
<s:Body>
<LogindetailsResponse xmlns="http://tempuri.org/">
<LogindetailsResult>{"CollectorId":0,"IMEINo":null,"IpAddress":null,"IsChangePassword":false,"IsRefund":false,"Location":null,"MacAddress":null,"MerchantGroup":"Direct","MerchantId":264,"Password":null,"Roles":null,"SessionId":null,"UserId":450,"UserName":"tirupoomi123","Usergroup":"Merchant"}
</LogindetailsResult>
</LogindetailsResponse>
</s:Body>
</s:Envelope>
my iphone code
NSString *soapMessage = @"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
"<s:Header>\n"
"<Action s:mustUnderstand=\"1\" xmlns=\"http://schemas.microsoft.com/ws/2005/05/addressing/none\">\n"
"http://tempuri.org/IService1/Logindetails\n"
" </Action>\n"
" </s:Header> \n"
"<s:Body>\n"
" <Logindetails xmlns=\"http://tempuri.org/\">\n"
" <value>\n"
"{\"SessionId\":\"dfg45fsg\",\"IpAddress\":\"192.168.0.1\",\"UserName\":\"tiru123\",\"Password\":\"ku204\",\"MacAddress\":\"192:158:012:45\",\"IMEINo\":\"testno\",\"Location\":\"Adyar\"}\n"
"</value>\n"
" </Logindetails> \n"
"</s:Body> \n"
"</s:Envelope>";
NSLog(soapMessage);
NSURL *url = [NSURL URLWithString:@"http://192.168.0.189/Service1.svc?wsdl"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://tempuri.org/IService1/Logindetails" forHTTPHeaderField:@"Soapaction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if(theConnection) {
webData = [[NSMutableData data] retain];
}
else {
NSLog(@"theConnection is NULL");
}
if anyone have any solution please help me
This above code works fine in normal wsdl web service. But not in wcf service.
I think that the problem with web service.
If any body have sample wcf sevice with iphone access please share with me