How do I pass arrays of values to SudzC-generated webservice classes?

人盡茶涼 提交于 2019-12-06 04:42:49

问题


I have a sudzc service class generated from a WSDL that accepts an ArrayOfInt and ArrayOfString objects as parameters. The service method signature is this:

- (SoapRequest*) Search: (id <SoapDelegate>) handler filters: (NSMutableArray*) displayedAttributes: (NSMutableArray*) displayedAttributes;

My question is, how do I pass values into the parameters that expect NSMutableArrays?

In the above method signature, the "displayedAttributes" parameter is expecting an ArrayOfInt object (which should be populated with several integers in an int tag, e.g., <int>1</int><int>2</int><int>3</int> etc).

However none of these things which I've tried have worked:

  • Directly passing an NSArray/NSMutableArray of (int) objects
  • Directly passing an NSArray/NSMutableArray of NSNumber objects
  • Passing an array of strings containing @"1", @"2", @"3" etc
  • Passing an array of strings that already contain @"<int>1</int>", @"<int>2</int>", etc
  • Constructing a CXMLDocument out of a string based on the integers

I'm sure this is somehow explained in the accompanying documentation in the download -- it's just not clear to me at the moment.


回答1:


@Jon Limjap: Lucky you are!!! it asks you for a type which you have dealt before, I have custom class type that SudzC generated for me (!)... It initializes only when passed CXMLNode, (which need CXMLDocument / CXMLElement).. I have no idea how to deal with such type...

an instance is: filter is a class, I have a class of the filter, but there is no way to initialize it, (except alloc-init and then setting its properties, but its properties are another such custom type.. !!!!)...If you know any "trick" to tell/configure sudzc to allow us to pass objects or fetch objects of cocoa type, do tell me....




回答2:


I had similar situation of passing array of objects to SOAP request. I managed to get it working by doing following changes.

SOAP array case in not added in

+(NSString *) serialize: (id) object()
{
//look if it is array not implemented
}

so I managed to change in the following method

+ (NSString*) serialize: (id) object withName: (NSString*) nodeName {
    if([object respondsToSelector:@selector(serialize:)]) {
        if([object isKindOfClass:[SoapArray class]]) 
            return [object serialize:object];
        return [object serialize: nodeName];
    }
    NSString *temp =[NSString stringWithFormat:@"<%@>%@</%@>", nodeName, [Soap serialize: object], nodeName];
    NSLog(@"serialise = %@", temp);
    return temp;
}

at the time SOAP request,

NSMutableArray arr = [[MYTable_STUB_ARR alloc] init]

MYTABLE_OBJ *obj = [[MYTABLE_OBJ alloc] init];

[arr addObject:obj];

[obj release];

Pass element arr object your SOAP Request ??




回答3:


This is a bit old, but I hope it will help someone. I implemented the serialize: method on SoapArray this way:

- (NSMutableString *)serialize:(NSString *)name
{
    NSMutableString *str = [NSMutableString string];
    //[str appendFormat:@"<%@>", name];
    for (id content in self)
    {
        //[str appendString:[Soap serialize:content]];
        [str appendString:[Soap serialize:content withName:name]];
    }
    //[str appendFormat:@"</%@>", name];
    return str;
}

As you can see, there are some commented lines. If you uncomment them and comment the currently used one inside the for, you will get a tag named name which will contain objects tagged with the content class name.



来源:https://stackoverflow.com/questions/4943346/how-do-i-pass-arrays-of-values-to-sudzc-generated-webservice-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!