简体   繁体   中英

Objective-c : Unable to handle request without a valid action parameter. please supply a valid soap action

I'm trying to consume an ASMX web service from objective-c using the wsdl2objc tool. For now, I'm trying to consume the temperature conversion web service .

Using the tool, client classes got generated for consuming the service (I have used THIS link as reference to write the code).

However, I'm continuously getting this soap fault message "Unable to handle request without a valid action parameter. Please supply a valid soap action".

While this error message very clearly states that I need to add a "SOAPAction" header to my request headers, I don't know how to do that in this case when using this wsdl2objc tool to generate the client classes for consuming the web service.

I have searched for a long time but in all the links that I referred, there was no mention of this situation occurring in objective-c.

Please check my code below:

- (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];

    }
}

By referring to THIS link , I have also tried to directly consume the web service by manually creating the soap message and making a call but I'm getting the HTML of the asmx web page as a response!! I just can't understand why I would get such a response!! I have not changed even a single line of code while running this particular code example given in the link referred at the start of this paragraph.

I'm totally new to iOS programming and might be doing some silly mistake or missing something very trivial. Can someone kindly help?

Please do let me know if any more information is required.

Thank you.

Update:
As suggested by Priya below, I checked the soap action header item in the setHttpCallUsingBody method. However, I see that it is already being set. But still I'm getting the same fault message. Check the screen clip below. Is the soap action not correct? Should it be something different?

在此处输入图片说明

SOAPAction header was included in SOAP 1.1 - So looks like that the web services that you are trying to consume uses this and expects this header. More on this header at http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383528

Adding a HTTP header to a NSURLRequest is very easy. You use - (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field thats defined on NSURLMutableRequest.

Specifically, if you are using the wsdl2objc tool that I mentioned in my article, you can include this header in - (void)sendHTTPCallUsingBody:(NSString *)outputBody soapAction:(NSString *)soapAction forOperation:(BarracudaCloudAPIBindingOperation *)operation method in BarracudaCloudAPISvc.m file.

Have you test the service with SoapUI ? Just to be sure that the service is working.

Personally, I prefer the codes generated from Wsdl2Code though none of the available generators took me all the way there, Wsdl2Code are the easiest one to understand , less fiddly, and I think the only one that doesn't skip base64 file. So with this, along with XMLDictionary , I just need to add a few - (id)initWithDictionary:(NSDictionary *)dictionary; where appropriate, and BAM! You're there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM