How to send a array as a parameter to a web service using SOAP and objective C.

Posted by Alejandra Meraz on Stack Overflow See other posts from Stack Overflow or by Alejandra Meraz
Published on 2010-04-08T22:29:18Z Indexed on 2010/04/08 22:33 UTC
Read the original article Hit count: 295

I'm working in a iPhone app that needs to send a array as a parameter using SOAP. this is the current request and connection:

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"
     "<function xmlns=\"http://tempuri.org/\" />\n"
     "</soap:Body>\n"
     "</soap:Envelope>\n"];

        NSURL *url = [NSURL URLWithString:@"http://myHost.com/myWebService/service.asmx"]; //the url to the WSDL

        NsMutableURLRequest theRequest = [[NSMutableURLRequest alloc] initWithURL:url];
     NSString *msgLength = [NSString stringWithFormat:@"%d",[soapMessage length]];

     [theRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
     [theRequest addValue:msgLength forHTTPHeaderField:@"Content-Lenght"];
     [theRequest setHTTPMethod:@"POST"];
     [theRequest addValue:@"myhost.com" forHTTPHeaderField:@"Host"];
     [theRequest addValue:@"http://tempuri.org/function" forHTTPHeaderField:@"SOAPAction"];
     [theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
     theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

Now, to send parameters I looked at the WSDL of the function description for the input is like this:

    <s:complexType name="ArrayOfDictionaryEntry">
            <s:sequence>
              <s:element minOccurs="0" maxOccurs="unbounded" name="DictionaryEntry" type="tns:DictionaryEntry" />
            </s:sequence>
          </s:complexType>
          <s:complexType name="DictionaryEntry">
            <s:sequence>
              <s:element minOccurs="0" maxOccurs="1" name="Key" />
              <s:element minOccurs="0" maxOccurs="1" name="Value" />
            </s:sequence>
</s:complexType>

<s:element name="functionInput">
        <s:complexType />
      </s:element>

I guess then that I need to make a array of dictionary entries. what I would like to send is something like this

[ location => USA, 
  module => DEVELOPMENT]

But I'm kind of confused.

  • the array is created outside the SOAP, like an NSArray or inside the SoapMessage?
  • if so... How is it done?
  • and the DictionaryEntry, should I make a class?

thanks for your time n.n

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c