How to create dynamic soap envelop in objective c

会有一股神秘感。 提交于 2019-12-08 08:04:13

问题


SOAP Body

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];

This is a simple soap message you know that.If i want to pass value of str using function that how i construct it?

But, i want to pass by value for this object how is it possible?


回答1:


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];


来源:https://stackoverflow.com/questions/35980742/how-to-create-dynamic-soap-envelop-in-objective-c

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