2013-05-10 62 views
0

我想用叫我軸心國的web服務下面的代碼調用webservice的軸從jQuery的

var wsUrl = "http://localhost:8080/TestServ/services/TestCls?wsdl"; 

var soapreq = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:cod=\"http://codon.com\">+"<soapenv:Header/>"+"<soapenv:Body>"+"<cod:testMethod>"+"<cod:name>hai</cod:name>"+"</cod:testMethod>"+"</soapenv:Body>"+"</soapenv:Envelope>"; 

var soapaction = "http://codon.com/testMethod"; 
jQuery.support.cors = true; 
     $.ajax({ 
       type: "POST", 
       url: wsUrl, 
       contentType: 'text/xml; charset=utf-8' , 
       dataType: "xml", 
       data: soapreq , 
       SOAPAction: soapaction, 
     //async: false, 
     //processData: false, 
     crossDomain: true, 
     success: processSuccess, 
       error: processError 
      }); 

但我得到我的weservice側以下錯誤......

May 10, 2013 12:18:52 PM org.apache.axis.transport.http.AxisServlet getSoapAction 
SEVERE: Generating fault class 
AxisFault 
    faultCode: {http://xml.apache.org/axis/}Client.NoSOAPAction 
    faultSubcode: 
    faultString: no SOAPAction header! 
    faultActor: 
faultNode: 
faultDetail: 
{http://xml.apache.org/axis/}stackTrace:no SOAPAction header! 
at org.apache.axis.transport.http.AxisServlet.getSoapAction(AxisServlet.java:1013) 
at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:678) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) 
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 
at  org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) 
    at 

,但我發送SOAPAction頭也..請幫助我出...預先提供

+0

引用此客戶端archive.plugins.jquery.com/project/jqSOAPClient – constantlearner 2013-05-13 19:19:48

+0

使用jqSOAPClient我可以調用webservice方法。但沒有從服務器得到任何迴應。怎麼了? – madas 2013-05-21 13:10:19

回答

0

工作代碼

//webservice calling 
var xmlhttp = new XMLHttpRequest(); 
var wsUrl = "http://localhost:8080/WebSer/services/EmailClient?wsdl"; 
xmlhttp.open('POST', wsUrl, false); 
var soapaction = "http://codon.com/login"; // available in wsdl file 

var soapRequest = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:cod=\"http://codon.com\">"+"<soapenv:Header xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>"+"<soapenv:Body>"+"<cod:login>"+"<acc_name>"+account+"</acc_name>"+"<uname>"+username+"</uname>"+"<pass>"+pwd+"</pass>"+"</cod:login>"+"</soapenv:Body>"+"</soapenv:Envelope>"; // get this from soap UI Tool 

xmlhttp.onreadystatechange = function() { 

    if (xmlhttp.readyState == 4) { 
     if (xmlhttp.status == 200) { 


} 
// Send the POST request 
      xmlhttp.setRequestHeader('Content-Type', 'text/xml'); 
      xmlhttp.setRequestHeader('SOAPAction', soapaction); 
      xmlhttp.send(soapRequest);