这个是服务接口....
public Document addCustomer(Document dom)throws Exception{
String customerNo;
String custName;
String custType;
String custPhone;
String custAddr;
java.util.Map returnMessage = new HashMap();
Element XMLInfo = dom.getDocumentElement();
NodeList customerinfos = XMLInfo.getElementsByTagName("customerinfo");
Element customerinfo = (Element)customerinfos.item(0);
NodeList CustomerID = customerinfo.getElementsByTagName("customerID");
NodeList customerName = customerinfo.getElementsByTagName("customername");
NodeList customerType = customerinfo.getElementsByTagName("customertype");
NodeList phone = customerinfo.getElementsByTagName("phone");
NodeList address = customerinfo.getElementsByTagName("address");
customerNo = null;
custName = null;
custType = null;
custPhone = null;
custAddr = null;
if (CustomerID.item(0).getFirstChild() != null)
customerNo = CustomerID.item(0).getFirstChild().getNodeValue();
if (customerName.item(0).getFirstChild() != null)
custName = customerName.item(0).getFirstChild().getNodeValue();
if (customerType.item(0).getFirstChild() != null)
custType = customerType.item(0).getFirstChild().getNodeValue();
if (phone.item(0).getFirstChild() != null)
custPhone = phone.item(0).getFirstChild().getNodeValue();
if (address.item(0).getFirstChild() != null)
custAddr = address.item(0).getFirstChild().getNodeValue();
由于之前做webservice 都是用cxf 实现的..现在的项目用的是axis 这个玩意...
情急之下到这来向各位大侠求助了..这个我该怎么调用它???
以下是我的实现..但是总是不成功:
public static void main(String[] args) throws Exception {
Options option = new Options();
EndpointReference endPoint = new EndpointReference("http://localhost:8077/test/services/testService");
option.setTo(endPoint);
ServiceClient sender = new ServiceClient();
sender.setOptions(option);
OMFactory factory = OMAbstractFactory.getOMFactory();
OMNamespace nameSpace = factory.createOMNamespace("http://webservice/org", "");
OMElement root = factory.createOMElement("XMLinfo", nameSpace);
OMElement cusinfo = factory.createOMElement("customerinfo", nameSpace);
OMElement element1 = factory.createOMElement("customerID", nameSpace);
element1.setText("01");
OMElement element2 = factory.createOMElement("customername", nameSpace);
element2.setText("大任");
OMElement element3 = factory.createOMElement("customertype", nameSpace);
element3.setText("1");
OMElement element4 = factory.createOMElement("phone", nameSpace);
element4.setText("12345");
OMElement element5 = factory.createOMElement("address", nameSpace);
element5.setText("地府");
cusinfo.addChild(element1);
cusinfo.addChild(element2);
cusinfo.addChild(element3);
cusinfo.addChild(element4);
cusinfo.addChild(element5);
root.addChild(cusinfo);
System.out.println("--------------------------------------2 "+cusinfo);
Document document = (Document)sender.sendReceive(root);
}
错误提示如下:
Exception in thread "main" org.apache.axis2.AxisFault: org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:512)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:370)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:416)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:548)
at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:528)
at test.testClient.main(testClient.java:56)
望各位大侠指点...
public Document addCustomer(Document dom)throws Exception{
String customerNo;
String custName;
String custType;
String custPhone;
String custAddr;
java.util.Map returnMessage = new HashMap();
Element XMLInfo = dom.getDocumentElement();
NodeList customerinfos = XMLInfo.getElementsByTagName("customerinfo");
Element customerinfo = (Element)customerinfos.item(0);
NodeList CustomerID = customerinfo.getElementsByTagName("customerID");
NodeList customerName = customerinfo.getElementsByTagName("customername");
NodeList customerType = customerinfo.getElementsByTagName("customertype");
NodeList phone = customerinfo.getElementsByTagName("phone");
NodeList address = customerinfo.getElementsByTagName("address");
customerNo = null;
custName = null;
custType = null;
custPhone = null;
custAddr = null;
if (CustomerID.item(0).getFirstChild() != null)
customerNo = CustomerID.item(0).getFirstChild().getNodeValue();
if (customerName.item(0).getFirstChild() != null)
custName = customerName.item(0).getFirstChild().getNodeValue();
if (customerType.item(0).getFirstChild() != null)
custType = customerType.item(0).getFirstChild().getNodeValue();
if (phone.item(0).getFirstChild() != null)
custPhone = phone.item(0).getFirstChild().getNodeValue();
if (address.item(0).getFirstChild() != null)
custAddr = address.item(0).getFirstChild().getNodeValue();
由于之前做webservice 都是用cxf 实现的..现在的项目用的是axis 这个玩意...
情急之下到这来向各位大侠求助了..这个我该怎么调用它???
以下是我的实现..但是总是不成功:
public static void main(String[] args) throws Exception {
Options option = new Options();
EndpointReference endPoint = new EndpointReference("http://localhost:8077/test/services/testService");
option.setTo(endPoint);
ServiceClient sender = new ServiceClient();
sender.setOptions(option);
OMFactory factory = OMAbstractFactory.getOMFactory();
OMNamespace nameSpace = factory.createOMNamespace("http://webservice/org", "");
OMElement root = factory.createOMElement("XMLinfo", nameSpace);
OMElement cusinfo = factory.createOMElement("customerinfo", nameSpace);
OMElement element1 = factory.createOMElement("customerID", nameSpace);
element1.setText("01");
OMElement element2 = factory.createOMElement("customername", nameSpace);
element2.setText("大任");
OMElement element3 = factory.createOMElement("customertype", nameSpace);
element3.setText("1");
OMElement element4 = factory.createOMElement("phone", nameSpace);
element4.setText("12345");
OMElement element5 = factory.createOMElement("address", nameSpace);
element5.setText("地府");
cusinfo.addChild(element1);
cusinfo.addChild(element2);
cusinfo.addChild(element3);
cusinfo.addChild(element4);
cusinfo.addChild(element5);
root.addChild(cusinfo);
System.out.println("--------------------------------------2 "+cusinfo);
Document document = (Document)sender.sendReceive(root);
}
错误提示如下:
Exception in thread "main" org.apache.axis2.AxisFault: org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:512)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:370)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:416)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:548)
at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:528)
at test.testClient.main(testClient.java:56)
望各位大侠指点...