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);
            }
         
        }

  • 相关阅读:
    Python命令行下退格、删除、方向键乱码问题解决(亲测有效)
    提取MySQL binlog中指定表的操作记录
    windows下面安装Python和pip终极教程
    day1-作业2
    day1-作业
    centos6.5python2.6环境下安装ansible
    安装inotify-tools,用inotifywait命令监听文件或目录的访问信息(自动同步文件夹)
    GitHub开源MySQL Online DDL工具gh-ost参数解析
    GitHub开源MySQL Online DDL工具gh-ost安装文档
    mysql磁盘IO%util 居高不下之RAID卡 BBU Learn Cycle周期
  • 原文地址:https://www.cnblogs.com/cnsec/p/11515879.html
Copyright © 2011-2022 走看看