1

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

2 Answers 2

2

So, your xml needs to look like this :-

 <ArrayOfDictionaryEntry>
      <DictionaryEntry>
         <key>key1</key>
         <value>val1</value>
      </DictionaryEntry>
      <DictionaryEntry>
          <key>key2</key>
          <value>val2</value>
       </DictionaryEntry>
   <ArrayOfDictionaryEntry>

I would create a NSMutableDictionary object with all the key value pairs and then iterate through them and build the xml.

Sign up to request clarification or add additional context in comments.

Comments

0

Thank you... I finally connected with the web service sending the parameters... It looks like that the person responsible of configuring the web service didn't actually made the changes so i could send the parameters..

The WSDL now looks like this:

 <s:element name="GetMonitorList">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="location" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="moduleName" type="s:string" />
          </s:sequence>
        </s:complexType>

And my code looks like this:

@"<?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"
    "<location>USA</location>"
    "<moduleName>DEVELOPMENT</moduleName>"
    "</function>"
    "</soap:Body>\n"
    "</soap:Envelope>\n"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.