Search code examples
authenticationsoapreturn-valuesudzc

My sudzc loginHandler returns only NSString. How to get the returned Innertoken?


When I use the LoginHandler generated from SUDZC on a Soap-service's wsdl, I'll see only the following output:

Login returned the value: OK

However when I enable service.logging I'll get the following output:

<soap:Body>
  <LoginResponse xmlns="http://tempuri.org/">
     <LoginResult>OK</LoginResult>
     <authToken>
        <InnerToken>21017998-02fd-4ac9-b132-98c0cb2fd1bf</InnerToken>
     </authToken>
  </LoginResponse>

I need to get the InnerToken-value and keep it for subsequent SOAP-calls (i.e. need to add it to the service.headers member). Anybody ideas on how to get the InnerToken from the above result?

I'm using the following LoginHandler code-fragment.

- (void) LoginHandler: (id) value {
  // Handle errors
  if([value isKindOfClass:[NSError class]]) {
    NSLog(@"%@", value);
    return;
  }
  // Handle faults
  if([value isKindOfClass:[SoapFault class]]) {
    NSLog(@"%@", value);
    return;
  }
  // Do something with the NSString* result
  NSString* result = (NSString*)value;
  NSLog(@"Login returned the value: %@", result);
}

Solution

  • In the (generated) SoapRequest.m file I changed the following:

    - (void)connectionDidFinishLoading:(NSURLConnection *)connection
    {
        ...
        if(self.handler != nil && [self.handler respondsToSelector: self.action]) {
            objc_msgSend(self.handler, self.action, output);
    }
    

    into:

    - (void)connectionDidFinishLoading:(NSURLConnection *)connection
    {
        ...
        if(self.handler != nil && [self.handler respondsToSelector: self.action]) {
            objc_msgSend(self.handler, self.action, element);
    }
    

    which solved my issue!