随笔 - 65  文章 - 0  评论 - 21  阅读 - 32万

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

wsdl2objc

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

 

服务器端,参考:【Web Service】Apache Tuscany发布Web Service

 

准备工作:

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

成功!!!

 

 

posted on   Anthony Li  阅读(4911)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
< 2013年1月 >
30 31 1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31 1 2
3 4 5 6 7 8 9

博客园博客已停止更新,博客地址:dyinigbleed.com

点击右上角即可分享
微信分享提示