Java根据WSDL直接生成XML请求报文

夜魔009 2014-03-08 06:57:00
想实现类似SOAPUI那种功能,就是知道WSDL,直接生成XML格式的请求、响应报文。请问有什么工具包可以实现?我只需要直接得到报文的XML,给它设置参数,直接调用。
不将WSDL编译成Java类!是直接生成报文,然后用HttpClient发送调用即可!
请问应如何实现?请给出实例,谢谢!
...全文
15913 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
xgangp 2016-11-09
  • 打赏
  • 举报
回复
我也遇到同样的问题,能告诉下如何解决的吗?
you_lhf 2016-01-24
  • 打赏
  • 举报
回复
求解决方法,谢谢楼主:::
cugyg 2014-08-01
  • 打赏
  • 举报
回复
我也遇到了同样的问题,急求楼主详细解决方法,非常感谢!
cugyg 2014-08-01
  • 打赏
  • 举报
回复
<?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions targetNamespace="http://webservice" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://webservice" xmlns:intf="http://webservice" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <!--WSDL created by Apache Axis version: 1.4 Built on Apr 22, 2006 (06:55:48 PDT)--> <wsdl:types> <schema elementFormDefault="qualified" targetNamespace="http://webservice" xmlns="http://www.w3.org/2001/XMLSchema"> <element name="log"> <complexType> <sequence> <element name="user" type="impl:User"/> </sequence> </complexType> </element> <complexType name="User"> <sequence> <element name="age" type="xsd:int"/> <element name="name" nillable="true" type="xsd:string"/> <element name="password" nillable="true" type="xsd:string"/> </sequence> </complexType> <element name="logResponse"> <complexType> <sequence> <element name="logReturn" type="xsd:string"/> </sequence> </complexType> </element> </schema> </wsdl:types> <wsdl:message name="logRequest"> <wsdl:part element="impl:log" name="parameters"> </wsdl:part> </wsdl:message> <wsdl:message name="logResponse"> <wsdl:part element="impl:logResponse" name="parameters"> </wsdl:part> </wsdl:message> <wsdl:portType name="Login"> <wsdl:operation name="log"> <wsdl:input message="impl:logRequest" name="logRequest"> </wsdl:input> <wsdl:output message="impl:logResponse" name="logResponse"> </wsdl:output> </wsdl:operation> </wsdl:portType> <wsdl:binding name="LoginSoapBinding" type="impl:Login"> <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="log"> <wsdlsoap:operation soapAction=""/> <wsdl:input name="logRequest"> <wsdlsoap:body use="literal"/> </wsdl:input> <wsdl:output name="logResponse"> <wsdlsoap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="LoginService"> <wsdl:port binding="impl:LoginSoapBinding" name="Login"> <wsdlsoap:address location="http://localhost:8080/ws/services/Login"/> </wsdl:port> </wsdl:service> </wsdl:definitions> 这个是我的wsdl文件,如何解析成XML并用httpclient调用webservice服务,用stub可以调用,但现在想改成HTTPclient的调用方式,谢谢指导。
  • 打赏
  • 举报
回复
http://bbs.csdn.net/topics/390842146 我的问题 楼主求解
yongyizhihua346 2014-05-09
  • 打赏
  • 举报
回复
LZ怎么搞定的,能告诉下吗?我也需要这种方法,谢谢!!
夜魔009 2014-05-05
  • 打赏
  • 举报
回复
我自己搞定了,感谢各位的回复。不过没什么用,不好意思不能给分
夜魔009 2014-03-22
  • 打赏
  • 举报
回复
引用 6 楼 gaoshanvd321 的回复:
你做WebService的时候项目的wsdl地址打开就是xml内容。若果你的项目不是WebService,你可以用WSDL4J来解决
你好,请问WSDL4J如何根据WSDL文件,生成相应方法的请求报文模板,和响应报文模板?我用httpclient直接把模板填充数据后发送给webserver服务器,应该就可以调用Webservice吧
LeayAo 2014-03-19
  • 打赏
  • 举报
回复
具体的格式要参照wsdl手动创建报文,然后发送,手动解析收到内容
LeayAo 2014-03-19
  • 打赏
  • 举报
回复
 Document document = DocumentHelper.createDocument();  
        Element root = DocumentHelper.createElement("soap:Envelope");
        root.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
        root.addAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
        root.addAttribute("xmlns:soap", "http://schemas.xmlsoap.org/soap/envelope/");
        document.add(root);
        //生成root的一个接点  
        Element category = DocumentHelper.createElement("soap:Body"); 
        root.add(category);
        //生产category的一个接点  
        Element method = category.addElement("SendNotify","http://tempuri.org/");
         method.addElement("title").addText(title);
        method.addElement("content").addText(content);
        
        URL url = new URL("http://*.*.*.*/****");
        URLConnection connection = url.openConnection();
        HttpURLConnection httpConn = (HttpURLConnection)connection;
        byte[] b = document.asXML().getBytes();
        // Set the appropriate HTTP parameters.
        httpConn.setRequestProperty("Content-Length", String.valueOf(b.length));
        httpConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
        httpConn.setRequestProperty("SOAPAction", "http://tempuri.org/SendNotify");
        httpConn.setRequestMethod("POST");
        httpConn.setDoOutput(true);
        httpConn.setDoInput(true);
        OutputStream out = httpConn.getOutputStream();
        out.write(b);
        out.close();
        // Read the response and write it to standard out.
        InputStreamReader isr = new InputStreamReader(httpConn.getInputStream());
        BufferedReader in = new BufferedReader(isr);
        SAXReader reader = new SAXReader();
        Document resultDoc = reader.read(in);
        Element resultRoot = resultDoc.getRootElement();
        List rootList = resultRoot.selectNodes("/your xml node patht']"); 
        Element element = null;  
        String resu=null;
        // 循环此节点,并取出对应的文本信息  
        for (Object obj : rootList) {  
            element = (Element) obj;  
            resu = element.getTextTrim();  
        } 
        return "true".equals(resu);
夕阳下的高山 2014-03-19
  • 打赏
  • 举报
回复
你做WebService的时候项目的wsdl地址打开就是xml内容。若果你的项目不是WebService,你可以用WSDL4J来解决
夜魔009 2014-03-18
  • 打赏
  • 举报
回复
引用 2 楼 bigc2001 的回复:
自己封装http请求
请说的详细一些,谢谢。我就是要报文
wyx100 2014-03-11
  • 打赏
  • 举报
回复
引用 2 楼 bigc2001 的回复:
自己封装http请求
正解
夜魔009 2014-03-11
  • 打赏
  • 举报
回复
有什么人知道怎么解决吗?
suciver 2014-03-11
  • 打赏
  • 举报
回复
你做WebService的时候项目的wsdl地址打开就是xml内容。若果你的项目不是WebService,你可以用WSDL4J来解决
比特灵 2014-03-11
  • 打赏
  • 举报
回复
自己封装http请求

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧