gpt4 book ai didi

iphone - 如何通过 SOAP 向 Web 服务发送参数?

转载 作者:行者123 更新时间:2023-12-03 21:23:40 24 4
gpt4 key购买 nike

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

我已经使用 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];

我基本上复制并修改了网络服务作为示例给出的肥皂请求。

我也实现了这些方法

  • 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 方法执行以及。但即使该方法一次也没有didReceiveData。
  • 我想知道,即使没有美国地点,仍会发送至至少有什么?
  • 有没有办法知道哪些是函数正在等待的参数为了?

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

最佳答案

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

关于iphone - 如何通过 SOAP 向 Web 服务发送参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2587951/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com