[] IOS SOAP-based third party open source project: wsdl2objc

wsdl2objc

Address: http://code.google.com/p/wsdl2objc/

 

Server, refer to: [Web Service] Apache Tuscany publish Web Service

 

Ready to work:

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

<Generate code

Run WSDLParser project

WSDL address bar, enter wsdl

Catalog Output Location bar code input and output

Click Parse WSDL button to generate the code:

 

<Added to the project

 

<Support 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

 

<Add framework

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

 

The sample code

#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

Solution:

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”

Reference: http://mmz06.blog.163.com/blog/static/121416962012913202818/

 

Build,Run

Request, the parameter is "Anthony"

Accordingly, says "Hello null"

wsdl2objc Bug!!!

Solution: modify the file IHelloWorldService.m, the class "IHelloWorldService_say" of "- (void) addElementsToNode: (xmlNodePtr) node" approach.

Set element namespace prefix is ​​"nil"

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

 

Build,Run

success! ! !

 

 

Reproduced in: https: //www.cnblogs.com/dyingbleed/archive/2013/01/18/2866210.html

Guess you like

Origin blog.csdn.net/weixin_33885676/article/details/93301844