如何使用从WSDL2OBJC生成的代码

时间:2011-06-30 11:21:12

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

大家好,我是iphone开发的新手,并开始使用一些示例应用程序。

在示例应用程序中,我正在使用webservices ..我完成了本教程http://code.google.com/p/wsdl2objc/wiki/UsageInstructions并了解了wsdl2objc ..

但是这个教程太短了,所以任何人都可以提出类似教程或例子的建议,以便更清楚......

谢谢你

1 个答案:

答案 0 :(得分:1)

所有取决于您的Web服务类名称等,因为wsdl2objc基于此构成了很多NSObject和方法,但是, 建议您使用soap 1.2绑定并且您的Web服务称为“SimpleService”,以下将调用名为“MobileTestService”的Web方法并从生成的xml返回整数值。

-(NSString *)returnThatStringFromWebServiceResult {


SimpleServiceSoap12Binding * binding = [SimpleService SimpleServiceSoap12Binding];
binding.logXMLInOut = YES; // shows all in the console log.
SimpleService_concat * testParams = [[SimpleService_concat new]autorelease];
testParams.s1 = someTextField.text; // parameters all become properties of this testParams object
testParams.s2 = anotherTextField.text;
SimpleServiceSoap12BindingResponse * response= [binding SimpleService_concatUsingParameters:testParams];
[response self]; // removes compile error

NSArray * responseBodyParts = response.bodyParts;
NSError * responseError = response.error;

if (responseError!=NULL) {
    return @"";  // if error from ws use [responeError code]; for http err code


}

for (id bodyPart in responseBodyParts)
{
    if ([bodyPart isKindOfClass:[SimpleService_concat_Response class]]) 
    {
        SimpleService_concatResponse* body = (SimpleService_concatResponse*) bodyPart;
        return body.SimpleService_concatResult; // if you are returning a string from your WS then this value will be a string, 

    }

}
}