2016-03-14 51 views
1

的SOAP Body如何在目標C動態創建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/>\">\n" 
             "<soap:Body>\n" 
             " <Ins_VIP xmlns=\"http://tempuri.org/>\">\n" 
             "<strVIPNo>%@</name>\n" 
             "</name>\n" 
             "</soap:Body>\n" 
             "</soap:Envelope>\n" , str]; 

這是你知道that.If我想用的功能通過海峽的值如何構建我是一個簡單的SOAP消息?

但是,我想通過這個對象的值傳遞它怎麼可能?

回答

1

你可以做這樣的事情,你需要做的修改,按您的要求:

//Add Request key and Values in below arrays 
NSArray* ReqKeyList; 

NSArray* ReqValueList; 


    NSString *HeaderPart; 
    NSString *BodyPart = @""; 
    NSString *FooterPart; 
    NSString *soapMessage; 

HeaderPart = [NSString stringWithFormat:@"<%@ xmlns=\"http://tempuri.org/\">\n",YourFunctionName]; 


FooterPart = [NSString stringWithFormat:@"</%@>\n", YourFunctionName]; 

for(int i=0;i<ReqKeyList.count;i++) 
{ 

    if (ReqValueList.count>i){ 

    BodyPart = [BodyPart stringByAppendingString:[NSString stringWithFormat:@"<%@>%@</%@>\n",ReqKeyList[i],ReqValueList[i],ReqKeyList[i]]]; 

    } 

} 


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/\">\n" 
        "<soap:Body>\n" 
        "%@" 
        "%@" 
        "%@" 
        "</soap:Body>\n" 
        "</soap:Envelope>\n",HeaderPart,BodyPart,FooterPart];