问题
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