How to create dynamic soap envelop in objective c

夙愿已清 提交于 2019-12-07 01:31:20

You can do something like this, you have to do modifications as per your requirement:

//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];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!