【发布时间】: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