我正在努力成功地從網頁上對SOAP Web服務進行Web服務調用。 Web服務是使用JAX-WS的Java Web服務。來自Javascript的SOAP網絡服務調用
這裏是Web方法,我試圖打電話:
@WebMethod
public String sayHi(@WebParam(name="name") String name)
{
System.out.println("Hello "+name+"!");
return "Hello "+name+"!";
}
我試着做使用jQuery庫jqSOAPClient(http://plugins.jquery.com/project/jqSOAPClient)的Web服務調用。
下面是代碼,我用:
var processResponse = function(respObj)
{
alert("Response received: "+respObj);
};
SOAPClient.Proxy = url;
var body = new SOAPObject("sayHi");
body.ns = ns;
body.appendChild(new SOAPObject("name").val("Bernhard"));
var sr = new SOAPRequest(ns+"sayHi",body);
SOAPClient.SendRequest(sr,processResponse);
無響應似乎回來了。當我在jqSOAPClient.js
中登錄xData.responseXML
數據成員時,我得到'undefined'。在Web服務,我看到警告2011年3月
24上午十時49分51秒com.sun.xml.ws.transport.http.server.WSHttpHandler handleExchange 警告:不能處理HTTP方法:OPTIONS
我也試過使用JavaScript庫soapclient.js(http://www.codeproject.com/kb/Ajax/JavaScriptSOAPClient.aspx)。我在這裏使用的客戶端代碼是
var processResponse = function(respObj)
{
alert("Response received: "+respObj);
};
var paramaters = new SOAPClientParameters();
paramaters.add("name","Bernhard");
SOAPClient.invoke(url,"sayHi",paramaters,true,processResponse);
我繞過部分,其獲取的WSDL soapclient.js,因爲它不工作 (我得到一個:IOException: An established connection was aborted by the software in your host machine
在Web服務端) 。 WSDL只是檢索適當的名稱空間才能使用,所以我剛剛用實際名稱空間替換了變量ns。
我得到了和以前一樣的web服務警告(無法處理HTTP方法:OPTIONS),並且在瀏覽器的錯誤控制檯中出現錯誤「document is null」。當我在soapclient.js中記錄req.responseXML的值時,我發現它是空的。
任何人都可以建議什麼可能會出錯,我應該怎麼做才能使它工作?
當我將Web服務部署到Glassfish時,客戶端獲得相同的響應(對於jqSOAPClient.js,爲「undefined」,在使用soapclient.js時爲null)。 – bgh 2011-03-24 11:11:28