【问题标题】:how to send parameters to a web Services via SOAP?如何通过 SOAP 将参数发送到 Web 服务?
【发布时间】:2010-04-06 20:14:06
【问题描述】:

开始之前:我正在为 Iphone 编程,使用目标 C。

我已经使用 NSURLRequest 和 NSURLConnection 和 SOAP 实现了对 Web 服务函数的调用。然后该函数返回一个包含我需要的信息的 XML。

代码如下:

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

我基本上是复制和修改了 web 服务作为示例给出的soap请求。

我也实现了方法

  • didRecieveResponse
  • didRecieveAuthenticationChallenge
  • didRecievedData
  • didFailWithError
  • connectionDidFinishLoading。

而且效果很好。

现在我需要向函数发送 2 个参数:“位置”和“模块”。 我尝试像这样修改soapMessage:

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

但是不工作...有什么想法我应该如何修改它?

额外信息:

  • 它似乎在工作……有点。 但是网络服务什么也没返回。
  • 在连接过程中,方法 didReceiveResponse 执行一次并且 didFinishLoading 方法执行 也是。但甚至没有一次方法 接收数据。
  • 我想知道,即使没有 美国位置,它仍将发送至 至少有什么?
  • 有没有办法知道哪些是 函数正在等待的参数 为了?

我无权访问 Web 服务的源,但我可以访问 WSDL。

【问题讨论】:

    标签: iphone objective-c web-services parameters


    【解决方案1】:

    您可能正在向服务传递无效的消息。你应该看看 WSDL;其中应该列出一个或多个模式或模式文档。这些将告诉您如何构造 SOAP 消息的主体。

    【讨论】:

      【解决方案2】:

      在我开发与您给出的类似代码之前,我遇到了您的问题。再次检查您的 WSDL 文件,您需要在单个类中请求单个 SOAP 消息,否则您的问题的方法(在第一部分中给出)将发生冲突。

      请转到以下链接,希望对您有所帮助...

      1) kosmaczewski.net

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

      3)http://viium.com

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-11-03
        • 2017-03-11
        • 1970-01-01
        • 1970-01-01
        • 2011-02-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多