Alejandra Meraz
Alejandra Meraz

Reputation: 57

how to send parameters to a web Services via SOAP?

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

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:

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

Upvotes: 2

Views: 6296

Answers (2)

Tirth
Tirth

Reputation: 7789

I was experiencing your problem before when i develop the code as similar you given.Check your again WSDL file and you need to request a single SOAP message in the single class otherwise your methods(given in first part) of your question will be clash.

Please go to the following link, I hope, it will help you...

1) kosmaczewski.net

2) http://icodeblog.com/2008/11/03/iphone-programming-tutorial-intro-to-soap-web-services/

3) http://viium.com

Upvotes: 0

Paul Schifferer
Paul Schifferer

Reputation: 509

You are probably passing the service a message that is not valid. You should have a look at the WSDL; there should be one or more schemas or schema documents listed inside it. Those will tell you how you can construct the body of the SOAP message.

Upvotes: 1

Related Questions