用J2ME来拜访WebService 续二

对于WebService服务端我们选择CXF来实现.

首先创建一个接口,

package com.joey.cxf;

import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;

/**
 *
 * @author joey
 */
@WebService
public interface Login{
    public @WebResult(name="returnText")String login(@WebParam(name="username") String name,@WebParam(name="password") String password);
}

 

然后来实现它...

 

package com.joey.cxf.impl;

import com.joey.cxf.Login;

/**
 *
 * @author joey
 */
public class LoginBean implements Login{

    public String login(String username,String password) {
        if("joey".equals(username) && "123456".equals(password)){
            return "登陆成功!";
        }
             return "登陆失败!";
        
    }

}

  好了, 这样一个WEBSERVICE就完成啦,  有了annotation我们几乎不用写xml. 最后我们来发布它吧

为了简单起见, 服务器用jetty. CXF自带那个.

package com.joey.test;

import com.joey.cxf.impl.LoginBean;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;

/**
 *
 * @author joey
 */
public class MyServer {
        public static void main(String[] args){
        JaxWsServerFactoryBean factory =  new JaxWsServerFactoryBean();
		factory.setServiceClass(LoginBean.class);
		factory.setAddress("http://localhost:8080/UserManager");
		Server server = factory.create();
		server.start();
        }
}

 

 

现在用前面那个J2ME APPLICATION 连接试试看!

你可能感兴趣的:(apache,xml,webservice)