【iOS SOAP】基于第三方开源项目:wsdl2objc

wsdl2objc

地址:http://code.google.com/p/wsdl2objc/

准备工作:

svn checkout http://wsdl2objc.googlecode.com/svn/trunk/

<生成代码

运行WSDLParser项目

WSDL栏输入wsdl的地址

Output Location栏输入输出代码的目录

点击Parse WSDL按钮生成代码:

 

<添加到项目

 

<支持libxml2

TARGETS -> Build Settings -> Linking -> Other Linker Flags,设置“-lxml2”

TARGETS -> Building Settings -> Apple LLVM compiler 4.1 - Language -> Other C Flags,设置“-I/usr/include/libxml2”

 

<添加framework

TARGETS -> Build Phases -> Link Binary With Libraries,添加CFNetwork.framework

 

代码示例

复制代码
#import <UIKit/UIKit.h>
#import "IHelloWorldService.h"

@interface ViewController : UIViewController <IHelloWorldServiceBindingResponseDelegate> {
    
    UITextField *mNameTextField;
    UITextView *mMessageTextView;
    
}

@property (retain, nonatomic) IBOutlet UITextField *nameTextField;
@property (retain, nonatomic) IBOutlet UITextView *messageTextView;

- (IBAction)sendButtonPressed:(id)sender;

@end
复制代码

 

复制代码
#import "ViewController.h"

@interface ViewController ()
@end

@implementation ViewController

@synthesize nameTextField = mNameTextField, messageTextView = mMessageTextView;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (IBAction)sendButtonPressed:(id)sender {
    IHelloWorldServiceBinding *binding = [IHelloWorldService IHelloWorldServiceBinding];
    
    IHelloWorldService_say *say = [[IHelloWorldService_say new] autorelease];
    say.arg0 = [mNameTextField text];
    
    [binding sayAsyncUsingSay:say delegate:self];
}

- (void)operation:(IHelloWorldServiceBindingOperation *)operation completedWithResponse:(IHelloWorldServiceBindingResponse *)response {
    
    NSArray *responseHeaders = response.headers;
    NSArray *responseBodyParts = response.bodyParts;
    
    for(id header in responseHeaders) {
        // here do what you want with the headers, if there's anything of value in them
    }
    
    for(id bodyPart in responseBodyParts) {

        if ([bodyPart isKindOfClass:[SOAPFault class]]) {
            //
            continue;
        }
        
        if([bodyPart isKindOfClass:[IHelloWorldService_sayResponse class]]) {
            IHelloWorldService_sayResponse *body = (IHelloWorldService_sayResponse*)bodyPart;
            NSString *text = body.return_;
            mMessageTextView.text = [NSString stringWithFormat:@"%@\n%@", mMessageTextView.text, text];
            continue;
        }
    }
}

@end
复制代码

 

Build,报错:"libxml/tree.h" file not found

解决方法:

PROJECT -> Build Settings -> Search Paths -> Header Search Paths,设置“${SDK_DIR}/usr/include/libxml2”

TARGETS -> Build Settings -> Search Paths -> Header Search Paths,设置“${SDK_DIR}/usr/include/libxml2”

参考:http://mmz06.blog.163.com/blog/static/121416962012913202818/

 

Build,Run

请求,参数为“Anthony”

相应,内容为“Hello null”

wsdl2objc Bug!!!

解决方法:修改文件IHelloWorldService.m中,类“IHelloWorldService_say”的“- (void)addElementsToNode:(xmlNodePtr)node”方法。

设置元素命名空间前缀为“nil”

xmlAddChild(node, [self.arg0xmlNodeForDoc:node->docelementName:@"arg0"elementNSPrefix:nil]);

 

Build,Run

成功!!!

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值