如下这是saop的消息,我想用Java访问这个webservice接口,要怎么实现?

javame 发布于 2014/09/25 10:58
阅读 795
收藏 0
  • <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
      <soap:Header>
         <tem:etoneSoapHeader>
            <tem:UserName>admin</tem:UserName>
            <tem:Password>123456</tem:Password>
         </tem:etoneSoapHeader>
      </soap:Header>
      <soap:Body>
         <tem:etoneYeQuery>
            <!--Optional:-->
            <tem:dlyh>yueke</tem:dlyh>
         </tem:etoneYeQuery>
      </soap:Body>
    </soap:Envelope>

    下面这样实现为什么请求不可以啊?

    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(); 


    }

加载中
0
木木三
木木三
wsimport 命令是否可用? 不可用那就只能自己构造报文了
0
蠢猪

看soap消息干啥 你不是可以看wsdl吗 根据wsdl调用很简单的事情吧

http://122.228.134.30:2121/EtoneWebService.asmx?WSDL

返回顶部
顶部