我在我的网站服务器上上传了一个 Web 服务www.example.com/webservice/SampleService.asmx
,我想连接到它的方法是GetAllUserInfo
,我使用下面的代码来使用这个 Web 服务但发生运行时错误,谁能帮我使用这个 Web 服务
- 我测试了这个 Web 服务并在 Visual Studio 上正常工作
NSString *soapMsg =[NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>" "<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/\">" "<soap:Body>" "<GetAllUserInfo xmlns=\"http://www.example.com/\">" "</GetAllUserInfo>" "</soap:Body>" "</soap:Envelope>"]; NSURL *url = [NSURL URLWithString:@"http://www.example.com/SampleService.asmx"]; NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url]; NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMsg length]]; [req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; [req addValue:@"http://www.example.com/GetAllUserInfo" forHTTPHeaderField:@"SOAPAction"]; [req addValue:msgLength forHTTPHeaderField:@"Content-Length"]; [req setHTTPMethod:@"POST"]; [req setHTTPBody:[soapMsg dataUsingEncoding:NSUTF8StringEncoding]];