综合资料网logo
首页 >> 类别 >> iphone >> 正文

iPhone如何调用java的webService代码

字体:大 字体:中 字体:小 iphone的资料库 更新于:2011-11-28 阅读次数:172  
相关标签:
  • java(24)
  • iPhone(5)
  • iPhone如何调用java的webService代码

    Java代码

      package com.xiva.service;

      import org.apache.axis2.context.MessageContext;

      import org.apache.axis2.context.ServiceContext;

      public class LoginService {

      public boolean login(String userName, String password) {

      MessageContext context = MessageContext.getCurrentMessageContext();

      ServiceContext ctx = context.getServiceContext();

      if ("admin".equals(userName) && "123456".equals(password)) {

      ctx.setProperty("userName", userName);

      ctx.setProperty("password", password);

      ctx.setProperty("msg", "登陆成功");

      return true;

      }

      ctx.setProperty("msg", "登陆失败");

      return false;

      }

      public String getLoginMessage() {

      MessageContext context = MessageContext.getCurrentMessageContext();

      ServiceContext ctx = context.getServiceContext();

      return ctx.getProperty("userName") + "#" + ctx.getProperty("msg");

      }

      }

      package com.xiva.service;

      import org.apache.axis2.context.MessageContext;

      import org.apache.axis2.context.ServiceContext;

      public class LoginService {

      public boolean login(String userName, String password) {

      MessageContext context = MessageContext.getCurrentMessageContext();

      ServiceContext ctx = context.getServiceContext();

      if ("admin".equals(userName) && "123456".equals(password)) {

      ctx.setProperty("userName", userName);

      ctx.setProperty("password", password);

      ctx.setProperty("msg", "登陆成功");
     return true;

      }

      ctx.setProperty("msg", "登陆失败");

      return false;

      }

      public String getLoginMessage() {

      MessageContext context = MessageContext.getCurrentMessageContext();

      ServiceContext ctx = context.getServiceContext();

      return ctx.getProperty("userName") + "#" + ctx.getProperty("msg");

      }

      }

      安装前面提到的博客文章,发布好这个Service.

      下面就是在iPhone上的调用了。

      先把代码给出,我们再一个一个分析。

      Soapdemoviewcontroller的头文件代码

      //

      // SOAPDemoViewController.h

      // SOAPDemo

      //

      // Created by xiang xiva on 11-4-4.

      // Copyright 2011 __MyCompanyName__. All rights reserved.

      //

      #import

      @interface SOAPDemoViewController : UIViewController {

      IBOutlet UITextField *nameInput;

      IBOutlet UILabel *greeting;

      NSMutableData *webData;

      NSMutableString *soapResults;

      NSXMLParser *xmlParser;

      BOOL recordResults;

      }

      @property(nonatomic, retain) IBOutlet UITextField *nameInput;

      @property(nonatomic, retain) IBOutlet UILabel *greeting;

      @property(nonatomic, retain) NSMutableData *webData;

      @property(nonatomic, retain) NSMutableString *soapResults;

      @property(nonatomic, retain) NSXMLParser *xmlParser;

      -(IBAction)buttonClick: (id) sender;

      - (void)loginSOAP;

      @end

      //

      // SOAPDemoViewController.h

      // SOAPDemo

      //

      // Created by xiang xiva on 11-4-4.

      // Copyright 2011 __MyCompanyName__. All rights reserved.

      //

      #import

      @interface SOAPDemoViewController : UIViewController {

      IBOutlet UITextField *nameInput;

      IBOutlet UILabel *greeting;
     NSMutableData *webData;

      NSMutableString *soapResults;

      NSXMLParser *xmlParser;

      BOOL recordResults;

      }

      @property(nonatomic, retain) IBOutlet UITextField *nameInput;

      @property(nonatomic, retain) IBOutlet UILabel *greeting;

      @property(nonatomic, retain) NSMutableData *webData;

      @property(nonatomic, retain) NSMutableString *soapResults;

      @property(nonatomic, retain) NSXMLParser *xmlParser;

      -(IBAction)buttonClick: (id) sender;

      - (void)loginSOAP;

      @end

      Soapdemoviewcontroller的实现代码代码

      //

      // SOAPDemoViewController.m

      // SOAPDemo

      //

      // Created by xiang xiva on 11-4-4.

      // Copyright 2011 __MyCompanyName__. All rights reserved.

      //

      #import "SOAPDemoViewController.h"

      @implementation SOAPDemoViewController

      @synthesize greeting, nameInput, webData, soapResults, xmlParser;

      /*

      // The designated initializer. Override to perform setup that is required before the view is loaded.

      - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {

      self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

      if (self) {

      // Custom initialization

      }

      return self;

      }

      */

      /*

      // Implement loadView to create a view hierarchy programmatically, without using a nib.

      - (void)loadView {

      }

      */

      /*

      - (void)viewDidLoad {

      [super viewDidLoad];

      }

      */

      /*

      // Override to allow orientations other than the default portrait orientation.

      - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

      // Return YES for supported orientations

    上一页12 3 ...6下一页

    相关标签:
  • java(24)
  • iPhone(5)
  • 评论(0)

    我来说两句
    用户名: 密码: 匿名发表
    验证码: