我正在尝试使用 wsdl2objc 工具从 Objective-c 使用 ASMX Web 服务。现在,我正在尝试使用温度转换网络服务。
使用该工具,生成了用于使用服务的客户端类(我已使用此链接作为编写代码的参考)。
但是,我不断收到此肥皂错误消息“无法处理没有有效操作参数的请求。请提供有效的肥皂操作”。
虽然此错误消息非常清楚地表明我需要在我的请求标头中添加一个“SOAPAction”标头,但在这种情况下,当使用此 wsdl2objc 工具生成用于使用 Web 服务的客户端类时,我不知道如何执行此操作。
我已经搜索了很长时间,但是在我提到的所有链接中,都没有提到在objective-c中发生这种情况。
请在下面检查我的代码:
- (IBAction)submitClicked:(id)sender {
TempConvertSoap *binding = [TempConvertSvc TempConvertSoap];
TempConvertSoapResponse* response;
TempConvertSvc_CelsiusToFahrenheit* request = [[TempConvertSvc_CelsiusToFahrenheit alloc] init];
request.Celsius = self.txtCelcius.text;
response = [binding CelsiusToFahrenheitUsingParameters:request];
dispatch_async(dispatch_get_main_queue(), ^{
[self processResponse:response];
});
}
-(void) processResponse: (TempConvertSoapResponse *) soapResponse
{
NSArray *responseBodyParts = soapResponse.bodyParts;
id bodyPart;
@try{
bodyPart = [responseBodyParts objectAtIndex:0];
}
@catch (NSException* exception)
{
UIAlertView* alert = [[UIAlertView alloc]initWithTitle:@"Server Error"message:@"Error while trying to process request" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
return;
}
if ([bodyPart isKindOfClass:[SOAPFault class]]) {
NSString* errorMesg = ((SOAPFault *)bodyPart).simpleFaultString;
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Server Error" message:errorMesg delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}
else if([bodyPart isKindOfClass:[TempConvertSvc_CelsiusToFahrenheitResponse class]]) {
TempConvertSvc_CelsiusToFahrenheitResponse* tempResponse = bodyPart;
UIAlertView* alert = [[UIAlertView alloc]initWithTitle:@"Success!" message:[NSString stringWithFormat:@"Result is %@", tempResponse.CelsiusToFahrenheitResult] delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}
}
通过参考这个链接,我还尝试通过手动创建soap消息并拨打电话来直接使用网络服务,但我得到了asmx网页的HTML作为响应!我就是不明白为什么我会得到这样的回应!!在运行本段开头提到的链接中给出的这个特定代码示例时,我甚至没有更改任何一行代码。
我对 iOS 编程完全陌生,可能会犯一些愚蠢的错误或遗漏一些非常微不足道的东西。有人可以帮忙吗?
如果需要更多信息,请告诉我。
谢谢你。
更新:
正如下面 Priya 所建议的,我检查了 setHttpCallUsingBody 方法中的肥皂动作标题项。但是,我看到它已经被设置了。但我仍然收到相同的故障信息。检查下面的屏幕剪辑。肥皂动作不正确吗?它应该是不同的东西吗?