how to send parameters to a web Services via SOAP?

Posted by Alejandra Meraz on Stack Overflow See other posts from Stack Overflow or by Alejandra Meraz
Published on 2010-04-06T20:14:06Z Indexed on 2010/04/06 20:43 UTC
Read the original article Hit count: 248

Before I start: I'm programming for Iphone, using objective C.

I have already implemented a call to a web service function using NSURLRequest and NSURLConnection and SOAP. The function then returns a XML with the info I need.

The code is as follows:

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

I basically copy and modified the soap request the web service gave as an example.

i also implemented the methods

  • didRecieveResponse
  • didRecieveAuthenticationChallenge
  • didRecievedData
  • didFailWithError
  • connectionDidFinishLoading.

And it works perfectly.

Now I need to send 2 parameters to the function: "location" and "module". I tried modifying the soapMessage like this:

  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 xmlns=\"http://tempuri.org/\" />\n"
    "<m:GetMonitorList>\n"
    "<m:location>USA</m:location>\n"
    "<m:module>DEVELOPMENT</m:module>\n"
    "</m:GetMonitorList>\n"
 "</soap:Body>\n"
 "</soap:Envelope>\n"];

But is not working...any thoughts how should I modify it?

Extra info:

  • it seems to be working... kind of. But the webservice return nothing.
  • During the connection, the method didReceiveResponse execute once and the didFinishLoading method executes as well. But not even once the method didReceiveData.
  • I wonder if, even though there is no USA locations, it will still send at least something?
  • is there a way to know which are the parameters the function is waiting for?

I don't have access to the source of the webservice but i can access the WSDL.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c