IOS如何向SOAP消息中插入数组

问题描述:

我有一个数组,其中包含一些内部的索引。当我登录它时它看起来是这样的:IOS如何向SOAP消息中插入数组

item pass: (
    80340025, 
    80319340, 
    80251277 
) 

我的数组被声明为NSAAray

然后我需要做一个SOAP调用插入此数组到SOAP消息中的各项指标。问题是如何?

这是我的肥皂信息。

NSString *soapMessage = [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/\">" 
          "<soap:Body>" 
          " <IncidentQuery xmlns=\"https://www.monitoredsecurity.com/\">" 
          "<IncidentNumber>%d</IncidentNumber>" 
          "<MaxSignatures></MaxSignatures>" 
          "</IncidentQuery>" 
          "</soap:Body>" 
          "</soap:Envelope>", item_pass]; 



    NSURL *url = [NSURL URLWithString:@"https://api.monitoredsecurity.com/SWS/incidents.asmx"]; 
    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url]; 
    NSString *msgLength = [NSString stringWithFormat:@"%lu", (unsigned long)[soapMessage length]]; 


    [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
    [theRequest addValue: @"https://www.monitoredsecurity.com/IncidentQuery" forHTTPHeaderField:@"SOAPAction"]; 
    [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"]; 
    [theRequest setHTTPMethod:@"POST"]; 
    [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; 







    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 
    [connection start]; 

    if(connection) 
    { 
     _webResponseData = [NSMutableData data] ; 


    } 
    else 
    { 
     NSLog(@"Connection is NULL"); 
    } 
+0

你想插入3个号码1块肥皂吗?或每个请求的每个号码?你的代码有什么问题? – anhtu

+0

我想插入3个数字给1个肥皂。代码插入一个数字没有问题。但我想传入3个数字到这个肥皂,但它失败,因为我不知道如何。 – zac

+0

我看到'soapMessage'只有一个放置数字的地方?你想要什么格式? – anhtu

做这样

-(void)SoapCallingMethod 
{ 
    for(int i=0;i<array.count;i++) 
    { 
    [self yourSoapMethod:[yourArray objectAtIndex:i]]; 
    } 
} 

-(void)yourSoapMethod:(NSInteger)indexNumber 
{ 
    yourSoapMessage = [NSString stringWithFormat:"%d",indexNumber]; 

    // Rest Steps 
} 
+0

IndexNumber需要是一个整数,因为我的soap请求参数只接受整数 – zac

+0

检查我更新的答案 –