0

我正在尝试使用 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 方法中的肥皂动作标题项。但是,我看到它已经被设置了。但我仍然收到相同的故障信息。检查下面的屏幕剪辑。肥皂动作不正确吗?它应该是不同的东西吗?

在此处输入图像描述

4

2 回答 2

0

您是否使用SoapUI测试过该服务?只是为了确保服务正常工作。

就个人而言,我更喜欢从Wsdl2Code生成的代码,尽管没有可用的生成器带我一路走到那里,Wsdl2Code 是最容易理解的,不那么繁琐,而且我认为唯一一个不跳过 base64 文件的生成器。所以有了这个,连同XMLDictionary,我只需要- (id)initWithDictionary:(NSDictionary *)dictionary;在适当的地方添加一些,然后 BAM!你在那儿。

于 2014-04-15T15:28:56.590 回答
0

SOAPAction 标头包含在 SOAP 1.1 中 - 因此看起来您尝试使用的 Web 服务使用此标头并期望此标头。有关此标头的更多信息,请访问 http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383528

将 HTTP 标头添加到 NSURLRequest 非常简单。你使用 -(void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field那是在 NSURLMutableRequest 上定义的。

具体来说,如果您使用的是我在文章中提到的 wsdl2objc 工具,您可以- (void)sendHTTPCallUsingBody:(NSString *)outputBody soapAction:(NSString *)soapAction forOperation:(BarracudaCloudAPIBindingOperation *)operation在 BarracudaCloudAPISvc.m 文件的方法中包含此标头。

于 2014-04-14T17:39:20.407 回答