开发者

Pass by reference in a soap call (Objective-C)

I'm attempting to make a SOAP call in objective-C to a web service that apparently requires a parameter to开发者_如何学C be passed by reference (I think). I don't have access to the web service itself, I'm only tasked to work with it. I've been given examples in C# to work with the problem, which are essentially:

var response = ServiceClient.Method(out parameter1, parameter2;

In C# theres conveniently that 'out' keyword but I haven't come across anything like that in ObjC. Currently I'm making soap calls like:

        NSMutableArray* _params = [NSMutableArray array];
        [_params addObject: [[[SoapParameter alloc] initWithValue: parameter1 forName: @"paramName"] autorelease]];
    NSString* _envelope = [Soap createEnvelope: @"Method" forNamespace: self.namespace withParameters: _params withHeaders: self.headers];

    SoapRequest* _request = [SoapRequest create: _target action: _action service: self soapAction: @"http://blahblahblah" postData: _envelope deserializeTo: [[responseType alloc] autorelease]];
    [_request send];
    return _request;

Any help is much appreciated


In C# theres conveniently that 'out' keyword but I haven't come across anything like that in ObjC.

The equivalent to out is to use a pointer to the variable. Define your method like this:

- (int) aMethodWithOutParameter:(NSString**)param {}

Then use it like this:

NSString *s;
int result = [self aMethodWithOutParameter:&s];
NSLog(@"result = %i, s = %@", result, s);

Note the extra * in the method declaration, and then & on the passed in variable when calling it.


You'll need to post code; there is no reason or need to use pass by reference from what you have posted so far, but there also isn't enough information to give a proper answer.

This doesn't make sense, either: [[responseType alloc] autorelease]] as the object is not being initialized.

Reading that code, the SoapRequest API seems odd, too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜