Java Webservice客户端:使用纯文本xml而不是对象层次结构
我正在用java编写一个简单的代理:Java Webservice客户端:使用纯文本xml而不是对象层次结构,java,xml,web-services,jax-ws,Java,Xml,Web Services,Jax Ws,我正在用java编写一个简单的代理: 读取XML文件 向Web服务发送请求 读取Web服务响应 向文件写入响应 我的第一次尝试是使用JAXB读取xml文件并生成Java对象。 然后我用JAX-WS(IBMWebSphere)发送对象。 我以“ResponseObject”的形式接收响应,然后将其生成xml代码。我将XML代码写入一个文件 这个设置很好。但是 当将java对象发送到Web服务时,会生成xml,并且再次响应会创建java对象。我真的不需要那些请求和响应对象。 有没有办法用明文xml直
如果您处理的是纯文本,则不需要JAXB或JAX-WS。只需使用HTTP连接即可发送和接收字符串。谢谢Sfussenger。但是我需要一些帮助来构建SOAP消息。是否有一个可以处理soap内容的库?
<SOAP-ENV:Envelope
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Header/><SOAP-ENV:Body>
<ans1:readLS xmlns:ans1="http://phonedirlux.homeip.net/types">
<String_1 xsi:type="xsd:string">your message or e-mail</String_1>
</ans1:readLS>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import java.io.FileInputStream;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamResult;
public class Client {
public static void main(String[] args) {
try {
// Create the connection
SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
SOAPConnection conn = scf.createConnection();
// Create message
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage msg = mf.createMessage();
// Object for message parts
SOAPPart sp = msg.getSOAPPart();
StreamSource prepMsg = new StreamSource(
new FileInputStream("path/prepared.msg"));
sp.setContent(prepMsg);
// Save message
msg.saveChanges();
// View input
System.out.println("\n Soap request:\n");
msg.writeTo(System.out);
System.out.println();
// Send
String urlval = "http://www.pascalbotte.be/rcx-ws/rcx";
SOAPMessage rp = conn.call(msg, urlval);
// View the output
System.out.println("\nXML response\n");
// Create transformer
TransformerFactory tff = TransformerFactory.newInstance();
Transformer tf = tff.newTransformer();
// Get reply content
Source sc = rp.getSOAPPart().getContent();
// Set output transformation
StreamResult result = new StreamResult(System.out);
tf.transform(sc, result);
System.out.println();
// Close connection
conn.close();
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
}