SVC webservice - objective-c

倖福魔咒の 提交于 2019-12-04 18:56:26

Hey guys found out the solution. The second line in the soap message corrected.

"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
                 "<soap:Body>\n"

Also in the url string .svc extension was missing. I corrected it with the statement. http://assetwebservice.sudesi.in/service.svc See well the s from service.svc is lower case whereas in soapaction parameter it is upper case.

Below is the entire soap message with http header parameters.

NSString *soapMessage = [NSString stringWithFormat:
                         @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
                          "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
                         "<soap:Body>\n"
                         "<BindCategory xmlns=\"http://tempuri.org/\">\n"
                         "</BindCategory>\n"
                         "</soap:Body>\n"
                         "</soap:Envelope>\n"
                         ];
NSLog(@"soapMessage: \n%@",soapMessage);

NSURL *url = [NSURL URLWithString:@"http://assetwebservice.sudesi.in/service.svc"];    
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/IService/BindCategory" forHTTPHeaderField:@"soapaction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

One thing still confuse me is that even if it is a GET request it throws me "ERROR in Connection" NSLog & succeeds when I change it to POST

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!