1、报文头需要密码验证的

- (void)sendAsynWebServiceRequest:(NSString *)nameSpace method:(NSString *)method requestXmlString:(NSString *)requestXmlString

{

NSString *sRequestXmlString = [requestXmlString stringByReplacingOccurrencesOfString:@"<" withString:@"&lt;"];

sRequestXmlString = [sRequestXmlString stringByReplacingOccurrencesOfString:@">" withString:@"&gt;"];

NSString *soapMessage = [NSString stringWithFormat:

@"<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\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:encodingStyle=\"http://www.w3.org/2001/12/soap-encoding\">\n"

"<soap:Body>\n"

"<%@  xmlns=\"%@%@\">\n"

"<xml>%@\n%@</xml>\n"

"<verifyID>123456</verifyID>\n"

"</%@>\n"

"</soap:Body>\n"

"</soap:Envelope>",method,BASEURL,nameSpace,@"&lt;?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?&gt;",sRequestXmlString,method];

DMLog(@"发送的soap信息====%@",soapMessage);

tagName = method;

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BASEURL,nameSpace]];

NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];

[urlRequest setTimeoutInterval:120.0];

NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

[urlRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];

[urlRequest addValue: [NSString stringWithFormat:@"%@%@/%@",BASEURL,nameSpace,method] forHTTPHeaderField:@"soapAction"];//SOAPAction http://210.51.27.9:8080/dtlp/ws/service

[urlRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];

[urlRequest setHTTPMethod:@"POST"];

[urlRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

2、不需要密码验证的

NSString *sRequestXmlString = [requestXmlString stringByReplacingOccurrencesOfString:@"<" withString:@"&lt;"];

sRequestXmlString = [sRequestXmlString stringByReplacingOccurrencesOfString:@">" withString:@"&gt;"];

NSString *soapMessage = [NSString stringWithFormat:

@"<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\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:encodingStyle=\"http://www.w3.org/2001/12/soap-encoding\">\n"

"<soap:Body>\n"

"<%@  xmlns=\"%@%@\">\n"

"<xml>%@\n%@</xml>\n"

"</%@>\n"

"</soap:Body>\n"

"</soap:Envelope>",method,BASEURL,nameSpace,@"&lt;?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?&gt;",sRequestXmlString,method];

DMLog(@"发送的soap信息====%@",soapMessage);

tagName = [NSString stringWithFormat:@"%@Return",method];

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BASEURL,nameSpace]];

NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];

[urlRequest setTimeoutInterval:120.0];

NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

[urlRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];

[urlRequest addValue: [NSString stringWithFormat:@"%@%@/%@",BASEURL,nameSpace,method] forHTTPHeaderField:@"soapAction"];//SOAPAction http://210.51.27.9:8080/dtlp/ws/service

[urlRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];

[urlRequest setHTTPMethod:@"POST"];

[urlRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

3、解析返回的数据

-(NSString*)getBusinessXML:(NSString*)xmlStr xmltagName:(NSString*)xmltagName{

NSString *regEx = [[NSString alloc] initWithFormat:@"<%@ >[\\w\\W]*</%@>", xmltagName, xmltagName];

NSString *sxmlstr = [xmlStr stringByReplacingOccurrencesOfString:@"xsi:type=\"xsd:string\"" withString:@""];

NSRange range = [sxmlstr rangeOfString:regEx options:NSRegularExpressionSearch];

if(range.location != NSNotFound){

NSString *businessXML = [sxmlstr substringWithRange:range];

//替换特殊字符

businessXML = [businessXML stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];

businessXML = [businessXML stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];

businessXML = [businessXML stringByReplacingOccurrencesOfString:@"&amp;" withString:@"&"];

businessXML = [businessXML stringByReplacingOccurrencesOfString:@"&quot;" withString:@"'"];

businessXML = [businessXML stringByReplacingOccurrencesOfString:@"&apos;" withString:@"\""];

businessXML = [businessXML stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];

businessXML = [businessXML stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];

//去除tagname

// businessXML = [businessXML substringWithRange:NSMakeRange(tagName.length+2, businessXML.length-(tagName.length*2+5))];

NSRange range1 = [businessXML rangeOfString:@"<?" ];

NSRange range2 = [businessXML rangeOfString:@"?>"];

if (range1.location !=NSNotFound && range2.location != NSNotFound) {

NSRange ranng = NSMakeRange(range1.location, range2.location - range1.location + 2);

businessXML = [businessXML stringByReplacingCharactersInRange:ranng withString:@""];

}

return businessXML;

}

return DATAANALYZEFAIL;

}

最新文章

  1. VS2013全攻略
  2. java 删除所有HTML工具类
  3. 主机和虚拟机能相互ping通但是不能复制
  4. HDU 5007 Post Robot KMP (ICPC西安赛区网络预选赛 1001)
  5. CMD command
  6. SQL:with ties
  7. Java Random
  8. web前端页面性能
  9. 获取Avrix上Computer Vision and Pattern Recognition的论文,进一步进行统计分析。
  10. 柔弱的APP如何自我保护,浅谈APP防御手段,使用360加固助手加固/签名/多渠道打包/应用市场发布
  11. ORACLE窗口函数
  12. linux操作命令 开发人员需要掌握的一些命令
  13. Anaconda 虚拟环境的使用
  14. Docker详解
  15. python对数据类型的相关操作
  16. windows sever2003安装Wamp 2.5不成功——VC 11不支持Windows Server 2003和win XP?
  17. windows 用户变量和系统变量的差别
  18. xssProject在java web项目中应用
  19. JavaScript深拷贝—我遇到的应用场景
  20. UVALive - 6952 DP 分段/隔板

热门文章

  1. android获取com.android.internal.R
  2. js验证表单大全
  3. 第五节:AppDomain FirstChance异常通知
  4. IEnumerable 接口 实现foreach 遍历 实例
  5. Github上LeakCanary编译报错CreateProcess error=2的解决方法
  6. C高级 服务器内核分析和构建 (一)
  7. 多线程报表生成其中报表以pdf形式保存
  8. Python学习——struct模块的pack、unpack示例
  9. ultraedit高亮显示设置
  10. [原]Java修炼 之 基础篇(二)Java语言构成