现在的位置: 主页 > 商讯 > 文章列表

webservice初级

作者:福建省医学会血液病学分会 来源:www.fjhematology.org 发布时间:2017-09-05 12:24:56
 

webservice初级

在学习webservice的时候,专题,经常将ns和url花了好久时间才理解过来,这里备份下!

首先定义接口:

@WebService
public interface IService
{
@WebResult(name = "login")
public User login(@WebParam(name = "username") String username,
@WebParam(name = "password") String password);
}


创建实现类:

@WebService(endpointInterface = "com.cml.soap.IService[这里是实现接口的全路径]", name = "myname")
public class ServiceImpl implements IService
{
@Override
@WebResult(name = "login")
public User login(@WebParam(name = "username") String username,
@WebParam(name = "password") String password)
{
System.out.println("进来登录");
return new User("恭喜你登录成功!", 1);
}
}

发布服务:

String address = "http://localhost:8888/cml";
Endpoint.publish(address, new ServiceImpl());

在浏览器上输入http://localhost:8888/cm?wsdl

创建soap消息:

public void sendSoap() throws Exception
{
String ns = "http://soap.cml.com/";
QName name = new QName(ns, "ServiceImplService");

String url = "http://localhost:8888/cml?wsdl";
// 使用的是url进行服务的创建
Service service = Service.create(new URL(url), name);


Dispatch dispatch = service.createDispatch(new QName(ns,
"mynamePort"), SOAPMessage.class, Service.Mode.MESSAGE);


SOAPMessage msg = MessageFactory.newInstance().createMessage();
SOAPEnvelope ele = msg.getSOAPPart().getEnvelope();
SOAPBody body = ele.getBody();


QName name2 = new QName(ns, "login", "tns");//

企业建站2800元起,携手武汉肥猫科技,做一个有见地的颜值派!更多优惠请戳:武汉网站开发 http://www.feimao666.com

  • 上一篇:Python是一门杰出的语言,值得你去学习
  • 下一篇:最后一页
  •