需要有关从wsdl2objc webservice生成的Objective-C代码的帮助

时间:2011-07-11 06:31:37

标签: iphone objective-c xcode web-services wsdl

我是iPhone开发的新手。我正在尝试使用wsdl2objc Web服务在客户端生成代理服务器。我经历了this tutorial并使用本教程做了一个示例应用程序。

实际上我有两个字符串s1和s2我需要连接两个字符串并使用按钮在文本字段上显示结果。我已经从wsdl2objc文件中生成了代码。生成的类的名称为SimpleService

由于我是iphone开发的新手,所生成的代码包含许多方法,我很困惑使用哪个类。我有一个编写正确编译但仍未执行的代码。我哪里错了?需要在以下代码中进行哪些更正?

@implementation WsdlViewController
@synthesize field;
-(IBAction)buttonpressed:(id)sender
{
    SimpleServiceSOAP *binding = [SimpleService SimpleServiceSOAP];
    binding.logXMLInOut = YES;
    SimpleService_concat *testParams = [[SimpleService_concat new]autorelease];
    testParams.s1 = field.text;   // parameters all become properties of this testParams object
    testParams.s2 = field.text;          
    SimpleServiceSOAPResponse * response = [binding   concatUsingParameters: testParams];  
                                   [response self];
    NSArray * responseBodyParts = response.bodyParts;
    NSError *responseError = response.error;
    for (id bodypart in responseBodyParts)
    {
        if ([bodypart  isKindOfClass:[SimpleService_concat class]])
        {
           SimpleService_concat * body = (SimpleService_concat *)bodypart; 
            field.text = body.s1;
            field.text = body.s2;
        }
    }    
}
你愿意我提供wsdl2objc生成的代码吗?

1 个答案:

答案 0 :(得分:0)

我根本不知道wsdl2objc。 但是,在阅读完代码之后,在我看来,内心基于这两条线:

field.text = body.s1;
field.text = body.s2;

由于您的解释是要连接两个字符串并在字段中显示结果,您应该尝试使用以下代码替换上面的两行:

field.text = [NSString stringWithFormat:@"%@%@", body.s1, body.s2];

这会连接两个字符串,并将结果分配给text的{​​{1}}属性。

希望这有帮助。