用Axis请求WebService,我的代码哪边错了?

javame 发布于 2014/09/25 10:28
阅读 404
收藏 0
代码内容:
import java.rmi.RemoteException;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
import javax.xml.soap.SOAPException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.message.SOAPHeaderElement;


public class SOAPHepler1 {
public static void main(String[] args) throws ServiceException, RemoteException {
try {
String endpointURL = "http://122.228.134.30:2121/EtoneWebService.asmx?WSDL";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpointURL));
call.setSOAPActionURI("http://tempuri.org/" + "etoneYeQuery");
call.setOperationName("etoneYeQuery");
SOAPHeaderElement soapHeaderElement = new SOAPHeaderElement("http://tempuri.org/", "etoneSoapHeader");
soapHeaderElement.setNamespaceURI("http://tempuri.org/");
try {
soapHeaderElement.addChildElement("UserName").setValue("admin");
soapHeaderElement.addChildElement("Password").setValue("123456");
}
catch (SOAPException e) {
e.printStackTrace();
}
call.addHeader(soapHeaderElement);
call.setReturnType(XMLType.XSD_STRING);
call.addParameter("dlyh", XMLType.XSD_STRING, ParameterMode.IN);
String ret = (String) call.invoke(new Object[]{ "yueke" });
System.out.println(call.getMessageContext().getCurrentMessage().toString());
System.out.println(ret);
}
catch (Exception e) {
e.printStackTrace();
}
}

}

我想用上面的代码,获得如下的报文内容: 但我不知道程序哪边错了?

(因为我用上面的代码请求WebService会出错,而用soapUI通过下面的XML,请求可以成功。)


<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
   <soap:Header>
      <tem:etoneSoapHeader>
         <!--Optional:-->
         <tem:UserName>admin</tem:UserName>
         <!--Optional:-->
         <tem:Password>123456</tem:Password>
         <!--Optional:-->
         <tem:StateLt>?</tem:StateLt>
         <!--Optional:-->
         <tem:StateYd>?</tem:StateYd>
         <!--Optional:-->
         <tem:StateDx>?</tem:StateDx>
         <!--Optional:-->
         <tem:Ydinterface>?</tem:Ydinterface>
      </tem:etoneSoapHeader>
   </soap:Header>
   <soap:Body>
      <tem:etoneYeQuery>
         <!--Optional:-->
         <tem:dlyh>yueke</tem:dlyh>
      </tem:etoneYeQuery>
   </soap:Body>
</soap:Envelope>

加载中
0
batManBack
batManBack
我会告诉你有个东西叫wsdl2java吗
返回顶部
顶部