/*
//Mark: 生成SOAP1.1版本的ASIHttp请求
参数 webURL: 远程WebService的地址,不含*.asmx
参数 webServiceFile: 远程WebService的访问文件名,如service.asmx
参数 xmlNS: 远程WebService的命名空间
参数 webServiceName: 远程WebService的名称
参数 wsParameters: 调用参数数组,形式为[参数1名称,参数1值,参数2名称,参数2值⋯⋯],如果没有调用参数,此参数为nil
*/
+ (ASIHTTPRequest *)getASISOAP11Request:(NSString*) WebURL
webServiceFile:(NSString*) wsFile
xmlNameSpace:(NSString*) xmlNS
webServiceName:(NSString*) wsName
wsParameters:(NSMutableArray*) wsParas
{
//1、初始化SOAP消息体
NSString* soapMsgBody1 = [[NSStringalloc] initWithFormat:
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n"
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \n"
"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
"<soap:Body>\n"
"<%@ xmlns=\"%@\">\n", wsName, xmlNS];
NSString* soapMsgBody2 = [[NSStringalloc] initWithFormat:
@"</%@>\n"
"</soap:Body>\n"
"</soap:Envelope>", wsName];
//2、生成SOAP调用参数
NSString* soapParas = [[NSStringalloc] init];
soapParas = @"";
if(![wsParas isEqual:nil]) {
inti = 0;
for(i = 0; i < [wsParas count]; i = i + 2) {
soapParas = [soapParas stringByAppendingFormat:@"<%@>%@</%@>\n",
[wsParas objectAtIndex:i],
[wsParas objectAtIndex:i+1],
[wsParas objectAtIndex:i]];
}
}
//3、生成SOAP消息
NSString* soapMsg = [soapMsgBody1 stringByAppendingFormat:@"%@%@", soapParas, soapMsgBody2];
//请求发送到的路径
NSURL* url = [NSURLURLWithString:[NSStringstringWithFormat:@"%@%@", WebURL, wsFile]];
//NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
ASIHTTPRequest * theRequest = [ASIHTTPRequest requestWithURL:url];
NSString*msgLength = [NSStringstringWithFormat:@"%d", [soapMsg length]];
//以下对请求信息添加属性前四句是必有的,第五句是soap信息。
[theRequest addRequestHeader:@"Content-Type"value:@"text/xml; charset=utf-8"];
[theRequest addRequestHeader:@"SOAPAction"value:[NSStringstringWithFormat:@"%@%@", xmlNS, wsName]];
[theRequest addRequestHeader:@"Content-Length"value:msgLength];
[theRequest setRequestMethod:@"POST"];
[theRequest appendPostData:[soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
[theRequest setDefaultResponseEncoding:NSUTF8StringEncoding];
returntheRequest;
}