开发者

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

  • 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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜