基本的な CXF JAX-WS Web サービスを開発しました。Web サービス、インターフェイスの詳細:
import javax.jws.WebService;
@WebService(name = "MesseSEI", targetNamespace = "http://default_package/")
public interface MesseSEI {
public String ResponseMesse(String input);
}
サービスの実装:
import javax.jws.WebService;
@WebService(targetNamespace = "http://default_package/", endpointInterface = "MesseSEI", portName = "MessePort", serviceName = "MesseService")
public class Messe implements MesseSEI {
public String ResponseMesse(String input){
return input + " is a good input!";
}
}
HTML ページ内で Web サービスを呼び出すために、Jquery を使用します。
Jquery 部分は次のようになります。
var URL = 'http://localhost:8080/Messe/services/MessePort?wsdl';
var soapMessage='<?xml version="1.0" encoding="utf-8"?>';
soapMessage +='<soapenv:Envelope xmlns:q0="http://default_package/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org /2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">';
soapMessage +='<soapenv:Body>';
soapMessage +='<q0:ResponseMesse>';
soapMessage +='<arg0>Dolar</arg0>';
soapMessage +='</q0:ResponseMesse>';
soapMessage +='</soapenv:Body>';
soapMessage +='</soapenv:Envelope>';
function CallService()
{
$.ajax({
url: URL,
type: "POST",
dataType: "xml",
data: soapMessage,
dataProcess: false,
cache: false,
success: function(data) {
alert("Success: " + data);
},
complete: function(msg){
alert(msg.status +" " + msg.statusText + " " +msg.readyState + " " + msg.redirect);
}
});
return false;
}
以下を使用する場合、最初に Ajax 呼び出しを行います。
contentType: "application/xml; charset=utf-8",
サーバー側では、リクエスト タイプが POST ではなく OPTIONS として表示されます。ajax 呼び出しから contentType を削除することにより、リクエストは Web サービスによって正常に受信されます。ステータス 200 OK で応答するだけで、SoapEnv が適切に送信されます。ただし、jquery の部分では応答を受信できず、エラー コールバック関数が呼び出され、その中でメッセージのステータスが 0 と表示されます。
同様の問題を検索しているときに、CORSの問題に関連している可能性があることに遭遇しましたが、追加しました:
jQuery.support.cors = true;
私のコードで。
私の問題を明確にするために、Webサービスはリクエストを受け取り、正しいSOAPenvでレスポンスを送り返しましたが、クライアント部分(つまりajax jquery呼び出し)ではレスポンスが受信されなかったので、ステータスを0として返し、statusTextを返すだけですUNDEFINED として。
私の問題について明確に言及したことを願っています。前もって感謝します。
編集: Web サービスに表示される受信メッセージと送信メッセージは次のとおりです。
受信メッセージ
ID: 16
Address: http://localhost:8080/Deneme/services/DeepThoughtPort?wsdl
Encoding: UTF-8
Http-Method: POST
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Headers: {Accept=[application/xml, text/xml, */*; q=0.01], accept-charset=[ISO-8859-1,utf-8;q=0.7,*;q=0.7], accept-encoding=[gzip, deflate], accept-language=[en-us,en;q=0.5], cache-control=[no-cache], connection=[keep-alive], Content-Length=[299], content-type=[application/x-www-form-urlencoded; charset=UTF-8], host=[localhost:8080], origin=[null], pragma=[no-cache], user-agent=[Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1]}
Payload: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://ws.skispike.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><q0:messe><arg0>Dolar</arg0></q0:messe></soapenv:Body></soapenv:Envelope>
送信メッセージ
ID: 16
Encoding: UTF-8
Content-Type: text/xml
Headers: {}
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:messeResponse xmlns:ns2="http://ws.skispike.com/"><return>Dolar is a good input!</return></ns2:messeResponse></soap:Body></soap:Envelope>