I’ve developed a basic CXF JAX-WS web service.
Some details of web service, interface:
import javax.jws.WebService;
@WebService(name = "MesseSEI", targetNamespace = "http://default_package/")
public interface MesseSEI {
public String ResponseMesse(String input);
}
Service implementation:
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!";
}
}
In order to invoke the web service within HTML page I use Jquery.
Jquery part is like this:
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;
}
First in Ajax call when using:
contentType: "application/xml; charset=utf-8",
in the server side Request type is displayed as OPTIONS instead of POST. By removing contentType from ajax call the request is being received normally by web service. It just give response with status 200 OK and SoapEnv is sent properly. However, in the jquery part the response can not be received, to say error call back function is invoked and within there, I just see the status of the message as 0.
While searching for similar issues, I encountered that it may be related to CORS problem but I’ve added:
jQuery.support.cors = true;
in my code.
To be clear my problem now is that, web service receives the request and sent response back with the correct SOAPenv but I guess in the client part (namely ajax jquery call) response is never received, so it just gives status as 0, and statusText as UNDEFINED.
I hope I clearly mentioned about my problem, any suggestions is appreciated. Thanks in advance.
Edit: Here are the Inbound and Outbound messages displayed in web service:
INBOUND MESSAGE
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>
OUTBOUND MESSAGE
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>
After lots of painful days, I solved my problem and I guess it will be helpful to post here. The problem is indeed Cross Domain problem. Adding:
only do not solve the problem. In order to handle the CORS problem you need to do the following:
In my case I publish my webservice under the Tomcat. In tomcat by following the instructions in: http://software.dzhuvinov.com/cors-filter-installation.html the problem is solved. Do not forget to add .jar to both tomcat’s /lib directory and into your service project classpath.