不将WSDL编译成Java类!是直接生成报文,然后用HttpClient发送调用即可!
请问应如何实现?请给出实例,谢谢!
16 个解决方案
#1
有什么人知道怎么解决吗?
#2
自己封装http请求
#3
你做WebService的时候项目的wsdl地址打开就是xml内容。若果你的项目不是WebService,你可以用WSDL4J来解决
#4
正解
#5
请说的详细一些,谢谢。我就是要报文
#6
你做WebService的时候项目的wsdl地址打开就是xml内容。若果你的项目不是WebService,你可以用WSDL4J来解决
#7
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);
#8
具体的格式要参照wsdl手动创建报文,然后发送,手动解析收到内容
#9
你好,请问WSDL4J如何根据WSDL文件,生成相应方法的请求报文模板,和响应报文模板?我用httpclient直接把模板填充数据后发送给webserver服务器,应该就可以调用Webservice吧
#10
我自己搞定了,感谢各位的回复。不过没什么用,不好意思不能给分
#11
LZ怎么搞定的,能告诉下吗?我也需要这种方法,谢谢!!
#12
http://bbs.csdn.net/topics/390842146
我的问题 楼主求解
我的问题 楼主求解
#13
我也遇到了同样的问题,急求楼主详细解决方法,非常感谢!
#14
<?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的调用方式,谢谢指导。
<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的调用方式,谢谢指导。
#15
求解决方法,谢谢楼主:::
#16
我也遇到同样的问题,能告诉下如何解决的吗?
#1
有什么人知道怎么解决吗?
#2
自己封装http请求
#3
你做WebService的时候项目的wsdl地址打开就是xml内容。若果你的项目不是WebService,你可以用WSDL4J来解决
#4
正解
#5
请说的详细一些,谢谢。我就是要报文
#6
你做WebService的时候项目的wsdl地址打开就是xml内容。若果你的项目不是WebService,你可以用WSDL4J来解决
#7
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);
#8
具体的格式要参照wsdl手动创建报文,然后发送,手动解析收到内容
#9
你好,请问WSDL4J如何根据WSDL文件,生成相应方法的请求报文模板,和响应报文模板?我用httpclient直接把模板填充数据后发送给webserver服务器,应该就可以调用Webservice吧
#10
我自己搞定了,感谢各位的回复。不过没什么用,不好意思不能给分
#11
LZ怎么搞定的,能告诉下吗?我也需要这种方法,谢谢!!
#12
http://bbs.csdn.net/topics/390842146
我的问题 楼主求解
我的问题 楼主求解
#13
我也遇到了同样的问题,急求楼主详细解决方法,非常感谢!
#14
<?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的调用方式,谢谢指导。
<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的调用方式,谢谢指导。
#15
求解决方法,谢谢楼主:::
#16
我也遇到同样的问题,能告诉下如何解决的吗?