我想制作一个简单的iOS应用程序,该应用程序调用Web服务。
我引用了以下链接http://www.codeproject.com/Tips/622376/iOS-Soap-Webservice-Calling-and-Parsing-the-Respon
我试图运行从此链接获得的示例项目。但是我得到的响应像
“ soap:ClientServer无法识别HTTP标头SOAPAction的值:http : //tempuri.org/。”
我无法找出导致此错误的原因。而且我是Web服务的新手。有人可以帮助我解决此错误吗?有人请告诉我,调用Web服务的基本步骤是什么?来自iOS应用程序。调用Web服务是否有Xcode和iOS的特殊版本要求?请帮助我...谢谢您的帮助...
这是我用于发送请求的代码
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"
" <CelsiusToFahrenheit xmlns=\"http://tempuri.org/\">\n"
"<Celsius>%@</Celsius>\n"
"</CelsiusToFahrenheit>\n"
"</soap:Body>\n"
"</soap:Envelope>\n" ,textFieldCelcisus.text];
NSURL *url = [NSURL URLWithString:@"http://w3schools.com/webservices/tempconvert.asmx"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://tempuri.org/" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if( theConnection )
{
webData = [NSMutableData data] ;
NSLog(@"webdata is %@",webData);
NSLog(@"Problem");
}
else
{
NSLog(@"theConnection is NULL");
}
更改此行:
[theRequest addValue: @"http://tempuri.org/" forHTTPHeaderField:@"SOAPAction"];
进入:
[theRequest addValue: @"http://www.w3schools.com/webservices/CelsiusToFahrenheit" forHTTPHeaderField:@"SOAPAction"];
服务器抱怨SOAPAction的值。SOAPAction在WSDL中定义,并且每个操作都不同。
由于您提供了服务URL,并且该服务是公共的,因此我仅对其进行了检查。“ CelsiusToFahrenheit”的SOAPAction似乎是:http://www.w3schools.com/webservices/CelsiusToFahrenheit
请注意,每个操作都有其自己的SOAPAction,例如:
CelsiusToFahrenheit -> http://www.w3schools.com/webservices/CelsiusToFahrenheit
FahrenheitToCelsius -> http://www.w3schools.com/webservices/FahrenheitToCelsius
etc...
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句