zoukankan      html  css  js  c++  java
  • ASIHTTPRequest访问。NET的WebService  基于soap协议

    1.通过浏览器浏览WebService,会大概提供如下的信息:
    ASIHTTPRequest访问。NET的WebService <wbr> <wbr>基于soap协议


    2.构建soap消息体:
       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/">" 
                                 "<soap:Body>\n" 
                                 "<ExecuteDataset xmlns="http://tempuri.org/">" 
                                 "<sql>%@</sql>"
                                 "</ExecuteDataset>"
                                 "</soap:Body>\n" 
                                 "</soap:Envelope>",sql];//就是把上述中的那段xml填进来
       NSString * wsURL = @"http://192.168.9.12:8082/ZTService.asmx";//ZTService.asmx就相当与.NET那边一个文件

        //请求发送到的路径
        NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",wsURL]];
        ASIHTTPRequest * theRequest = [ASIHTTPRequest requestWithURL:url];
        NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
         
        //以下对请求信息添加属性前四句是必有的,第五句是soap信息。 对应1中的那些信息
        [theRequest addRequestHeader:@"Content-Type" value:@"text/xml; charset=utf-8"];
        [theRequest addRequestHeader:@"SOAPAction" value:@“http://tempuri.org/ExecuteDataset”];
         
        [theRequest addRequestHeader:@"Content-Length" value:msgLength];
        [theRequest setRequestMethod:@"POST"];
        [theRequest appendPostData:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
         
        [theRequest setDefaultResponseEncoding:NSUTF8StringEncoding];
    //显示网络请求信息在status bar上
        [ASIHTTPRequest setShouldUpdateNetworkActivityIndicator:YES];
         
        //同步调用
        [theRequest startSynchronous];

    3.采用kissXML开源库解析返回回来的xml字符串
    NSLog(@"返回的soap信息是:%@",returnSoapXML); 
        //开始解析xml 
      
        DDXMLDocument *doc = [[DDXMLDocument alloc] initWithXMLString:returnSoapXML options:0 error:nil];
       
        /////解析
      
        NSArray *items = [doc nodesForXPath:@"//Table" error:nil];
        //NSLog(@"%@",items);
       
       
        for (DDXMLElement *obj in items) {//循环查询的每条记录
            //NSLog(@"%@",obj.children);
            for(DDXMLNode *node in obj.children){//取得每个字段的值
             NSLog(@"%@",node.stringValue);
            }
         
        }

  • 相关阅读:
    阿里云观察——阿里云总裁王坚专访
    追寻凌云梦——对话阿里云总裁王坚
    四维的王坚和三维的阿里互联网汽车
    [2011移动者开发大会]王坚:互联网最革命的事是所有事情从离线到在线
    2013年8月,阿里云飞天5K集群成功上线,所有的服务对应的都是同一个系统内核、同一套分布式文件系统
    [搜索引擎大会]谷歌CEO Eric Schmit第一次高调用云和云计算的概念来描述谷歌所提供的互联网服务
    热门搜索引擎的TOP-K算法的python实现(回溯算法遍历trie树)
    海量日志数据提取出访问次数最多的那个IP python实现 总结
    Web数据挖掘 第十二章 Web使用挖掘的读书笔记
    Web数据挖掘 第十一章 观点挖掘和情感分析的读书笔记
  • 原文地址:https://www.cnblogs.com/cnsec/p/11515879.html
Copyright © 2011-2022 走看看