I need to pass this array to SOAP API as a parameter. The back-end implementer is new to building APIs (C#/.NET) and I have never implemented this kind of API before. There are 4-5 Stack Overflow question related to this, but none of them were the solution as per my query.
NSArray *arr = [NSArray arrayWithObjects:@"1",@"2", nil];
NSString *soapURL = @"http://tempuri.org/IService1/addRecord";
NSString *soapBody = [NSString stringWithFormat:@"<addRecord xmlns=\"http://tempuri.org/\">"
"<id>%@</id>"
"<title>%@</title>"
"<record>%@</record>"
"</addRecord> \n” ,@“1”,@“abc", arr ];
NSLog(@"%@",soapBody);
Error:
value in string The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'addRecord'. End element 'record' from namespace 'http://tempuri.org/' expected. Found text '( 1, 2 )'.
One thing I came to know that I cannot pass array directly in to soapBody
. What what is the alternative?
The API is working fine at the back-end.
Finally I resolved this issue with this code:
NSString *soapBody = [NSString stringWithFormat:@"< addRecord xmlns=\"http://tempuri.org/\" xmlns:arr=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\" > \n"
"<ID>1</ID>\n"
"<title>ABC</title>\n"
"<record>\n"];
for (int i=0; i<arrRecord.count; i++) {
soapBody = [NSString stringWithFormat:@"%@ <arr:int>%@</arr:int>\n",soapBody,arrRecord[i]];
}
soapBody = [NSString stringWithFormat:@"%@ </record></addRecord> \n",soapBody];
I needed to define "arr" in the parent node and type of element(int) in the record array.