xcode 如何使用objective-c为ipad发送/接收soap对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16433896/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to send/receive soap object with objective-c for ipad
提问by Arif YILMAZ
I have been trying to write a objective-c application for ipad to send/receive soap web service. I have written a code but it gives an error. the webservice is working online.
我一直在尝试为 ipad 编写一个objective-c 应用程序来发送/接收soap web 服务。我写了一个代码,但它给出了一个错误。网络服务正在联机工作。
here is my code,
这是我的代码,
-(IBAction)invokeService
{
[txt1 resignFirstResponder];
NSString *soapFormat = [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"
"<GetUserList xmlns=\"http://tempuri.org/\" />\n"
"</soap:Body>\n"
"</soap:Envelope>\n"];
NSLog(@"The request format is %@",soapFormat);
NSURL *locationOfWebService = [NSURL URLWithString:@"http://servicing2.rotanet.com/service1.asmx"];
NSLog(@"web url = %@",locationOfWebService);
NSMutableURLRequest *theRequest = [[NSMutableURLRequest alloc]initWithURL:locationOfWebService];
NSString *msgLength = [NSString stringWithFormat:@"%d",[soapFormat length]];
[theRequest addValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue:@"GetUserList" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
//the below encoding is used to send data over the net
[theRequest setHTTPBody:[soapFormat dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *connect = [[NSURLConnection alloc]initWithRequest:theRequest delegate:self];
if (connect) {
webData = [[NSMutableData alloc]init];
startActivityIndicator;
}
else {
NSLog(@"No Connection established");
}
}
I get this error message
我收到此错误消息
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault> <faultcode>soap:Client</faultcode><faultstring>System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: GetUserList.
at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response)
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing) </faultstring><detail /></soap:Fault></soap:Body></soap:Envelope>
what am I doing wrong?
我究竟做错了什么?
回答by Akash Kava
Disclaimer: I am author of WSClient++ and it is a commercial product.
免责声明:我是 WSClient++ 的作者,它是一个商业产品。
http://wsclient.neurospeech.com
http://wsclient.neurospeech.com
Creating simple SOAP requests are easy, however when you have complex graph of objects, dealing with Dictionaries and raw XML can be time consuming, WSClient++ generates Objective C source code for SOAP proxy with each complex type. You just make a single method call to retrieve results.
创建简单的 SOAP 请求很容易,但是当您有复杂的对象图时,处理字典和原始 XML 可能很耗时,WSClient++ 会为每个复杂类型的 SOAP 代理生成 Objective C 源代码。您只需调用一个方法即可检索结果。