0
我有一個概念問題,阻止我解決一個微不足道的問題。我需要將對象發送到Web服務。我有一個端點,我有可以序列化對象的代碼,所以我可以創建包含序列化對象的org.jdom.Document或byte []對象。如何使用axis2編寫客戶端以將序列化的xml對象發送到Web服務?
我還可以創建一個使用axis2調用Web服務的客戶端代碼片段。 最後我試圖發送一個手動創建的消息發送到Web服務(它沒有WSDL() 我已經用查爾斯看到什麼是走出去(請求)
我不知道怎麼辦。要將byte [] org.jdom.Document對象轉換爲OMElement對象,顯然serviceClient.sendReceive(elem)需要OMElement參數
這是我到目前爲止嘗試的(我刪除了OMElement一旦我確信它出去了,我就派出了):
package testAxis2Client01;
import java.util.Map;
import javax.xml.stream.XMLStreamException;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.transport.http.HTTPConstants;
public class testAxis2Client01 {
private static final int MXMOCONNECTIONTIMEOUT = 2;//don't really know what this should be.
/**
* @param args
*/
public static void main(String[] args) {
try {
callAxisWS();
} catch (XMLStreamException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void callAxisWS() throws XMLStreamException, Exception {
//Axis2 client code to call a WS
OMElement response=null;
try{
OMFactory factory = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope theEnvelope = OMAbstractFactory.getSOAP12Factory().getDefaultEnvelope();
theEnvelope.declareNamespace("http://www.w3.org/2001/XMLSchema","xsd");
theEnvelope.declareNamespace("http://www.w3.org/2001/XMLSchema-instance","xsi");
ServiceClient serviceClient = new ServiceClient();
Options options = serviceClient.getOptions();
options.setProperty(HTTPConstants.AUTO_RELEASE_CONNECTION, true); // Another API to release connection.
options.setTimeOutInMilliSeconds(10000); // Setting the connection timeout.
EndpointReference targetEPR = new EndpointReference(theUrl);
options.setTo(targetEPR);
options.setAction("processDocument");
serviceClient.setOptions(options);
//response = serviceClient.sendReceive(myOMElement);
response = serviceClient.sendReceive(elem)
if (response != null) {
System.out.println("SUCCESS!!");
System.out.println(response.toStringWithConsume());
}
}catch(Exception af){
af.printStackTrace();
System.out.println(af.getMessage());
}
}
}
沒有WSDL。他們無法提供WSDL。這項工作很久以前就完成了。 – kishjeff
這段代碼似乎可以正常工作,但偶爾會發生,如果請求達到一定的大小,我會注意到響應丟失了很多孩子: – kishjeff