IOS -- 基于WebService WSDL 的请求
2014-11-25 16:54
183 查看
公司的WebService真的把我搞惨了。还好ok了。
感谢 http://wuchaorang.2008.blog.163.com/blog/static/48891852201391695530894/ 对我的帮助。
先看清楚大前提
1. WebService 用的是soap 1.1
切入正题:
1.写出soap字符串进行请求,十分重要 我调用的是soap1.1。 soap1.2与soap1.1要写的soap体不一样。
详细区别可见 /article/4199746.html
2.Soap体搞定后 就可以请求了。请求后再用NSXMLParser或者GDataXMLNode来解析XML 详细IOS代码见下(只有请求代码)
最后你在NSURLConnectionDelegate 的方法里取值webData的值就ok了
希望能帮助到需要的人。
感谢 http://wuchaorang.2008.blog.163.com/blog/static/48891852201391695530894/ 对我的帮助。
先看清楚大前提
1. WebService 用的是soap 1.1
切入正题:
1.写出soap字符串进行请求,十分重要 我调用的是soap1.1。 soap1.2与soap1.1要写的soap体不一样。
详细区别可见 /article/4199746.html
<span style="white-space:pre"> </span>"<?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/\" " "xmlns:ns1=\"(此处为webservice的命名空间)">\"\n" "<soap:Body>" "<ns1:findProductDetail>" <span style="font-family: Arial, Helvetica, sans-serif;">(sn1:为上面的命名空间 此处填写的是你的方面名)</span> "<productId>20000</productId>" <span style="font-family: Arial, Helvetica, sans-serif;">(此处填写的是你的参数名以及参数值)</span> "</ns1:findProductDetail>" "</soap:Body>" "</soap:Envelope>"
2.Soap体搞定后 就可以请求了。请求后再用NSXMLParser或者GDataXMLNode来解析XML 详细IOS代码见下(只有请求代码)
NSString *number = @"20000"; 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/\" " "xmlns:ns1=\"http://你要用到的命名空间\">\"\n" "<soap:Body>" "<ns1:findProductDetail>" "<productId>%@</productId>" "</ns1:findProductDetail>" "</soap:Body>" "</soap:Envelope>", number]; NSLog(@"%@",soapMsg); NSURL *url = [NSURL URLWithString:@"你要请求的网址"]; NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url]; NSString *msgLength = [NSString stringWithFormat:@"%lu", (unsigned long)[soapMsg length]]; // 添加请求的详细信息,与请求报文前半部分的各字段对应
// soap1.1 addValue:@"text/xml soap1.2用addValue:@"application/soap+xml“
[req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; [req addValue:msgLength forHTTPHeaderField:@"Content-Length"]; // 设置请求行方法为POST,与请求报文第一行对应 [req setHTTPMethod:@"POST"]; // 将SOAP消息加到请求中 [req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]]; // 创建连接 conn = [[NSURLConnection alloc] initWithRequest:req delegate:self]; if (conn) { NSLog(@"NSURLConnection is ok \n"); webData = [NSMutableData data]; }
最后你在NSURLConnectionDelegate 的方法里取值webData的值就ok了
希望能帮助到需要的人。
相关文章推荐
- IOS:SOAP(Webservice)请求基于AFN2.6之后
- WebService之WSDL和SOAP实例(基于JAVA)
- iOS开发之iPhone通过get和post方式请求asp.net webservice
- Webservice_19_SOAP的基于契约优先WSDL的开发流程
- 基于SOAP协议并使用ASIHTTPRequest调用Webservice完成数据请求。
- iOS开发之iPhone通过get和post方式请求asp.net webservice
- .Net平台如何基于wsdl文件搭建虚拟WebService服务器进行跨平台服务调试?
- Android基于SOAP协议向WebService交互数据,修改请求超时时间
- IOS开发笔记 - 基于wsdl2objc调用webservice
- WebService之WSDL和SOAP实例(基于JAVA)
- ios调用webservice对wsdl二元次图解说明
- iOS开发之iPhone通过get和post方式请求asp.net webservice
- iOS请求webservice(转)
- Android基于SOAP协议向WebService交互数据,修改请求超时时间
- IOS开发笔记 - 基于wsdl2objc调用webservice
- 基于axis2的WebService获取客户端请求IP地址
- iOS开发之iPhone通过get和post方式请求asp.net webservice
- Android基于SOAP协议向WebService交互数据,修改请求超时时间
- IOS请求WebService/WCF服务的方法
- 基于JAX-WS用wsdl生成webservice服务端代码