mytest911
2012-09-08 17:06
浏览 809
已采纳

web service服务端接收到数据,做了处理,客户端接收不到返回值

大侠们指点下小弟啊

客户端通过
UserService us = new UserService();
IUserService is = us.getUserSoapPort();
User user = is.login("九霄", "123");
System.out.println(user.getNickname());获取不到返回值,但是服务器端能够接收到数据

但是客户端通过下面的方式获取到的soap信息很正常 ,附源码
//1、创建服务(Service)
String ns = "http://www.jiuxiao.com/user/";
URL url = new URL("http://localhost:9997/10_in_tomcat/ns?wsdl");
QName sname = new QName(ns,"userService");
Service service = Service.create(url,sname);
//2、创建Dispatch
Dispatch dispatch = service.createDispatch(new QName(ns,"userSoapPort"),SOAPMessage.class, Service.Mode.MESSAGE);

//3、创建SOAPMessage
SOAPMessage msg = MessageFactory.newInstance().createMessage();
SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
SOAPBody body = envelope.getBody();

//4、创建QName来指定消息中传递数据
QName ename = new QName(ns,"login");
SOAPBodyElement ele = body.addBodyElement(ename);
ele.addChildElement("username").setValue("九霄");
ele.addChildElement("password").setValue("123");
msg.writeTo(System.out);
System.out.println("\n invoking.....");
//5、通过Dispatch传递消息,会返回响应消息
SOAPMessage response = dispatch.invoke(msg);
response.writeTo(System.out);

//将响应的消息转换为dom对象
Document doc = response.getSOAPPart().getEnvelope().getBody().extractContentAsDocument();
String str =doc.getElementsByTagName("user").item(0).getTextContent();
System.out.println(str);

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • jinnianshilongnian 2012-09-08 18:50
    已采纳
    @XmlElement(required = true, namespace="")
    protected int id;
    @XmlElement(required = true, namespace="")
    protected String username;
    @XmlElement(required = true, namespace="")
    protected String nickname;
    @XmlElement(required = true, namespace="")
    protected String password;
    
    点赞 评论

相关推荐 更多相似问题