How to communicate with JAX-WS based SOAP webservice from java? - java

I searched google, but i cant find a way to do this. I have a SOAP webservice built in netbeans with JAX-WS . Gerated wsdl cannot be accessed by my java client code. Is the way i am trying to access is wrong? someone help..
my web service code
#WebService(serviceName = "HolaMundo")
public class HolaMundo {
#WebMethod(operationName = "hello")
public String hello(#WebParam(name = "name") String txt) {
return "Hello " + txt + " !";
}
}
generated wsdl
<!--
Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2-hudson-740-.
-->
<!--
Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2-hudson-740-.
-->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://publicar.ws.org.mx/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://publicar.ws.org.mx/" name="HolaMundo">
<types>
<xsd:schema>
<xsd:import namespace="http://publicar.ws.org.mx/" schemaLocation="http://localhost:8084/HolaMundo/HolaMundo?xsd=1"/>
</xsd:schema>
</types>
<message name="hello">
<part name="parameters" element="tns:hello"/>
</message>
<message name="helloResponse">
<part name="parameters" element="tns:helloResponse"/>
</message>
<portType name="HolaMundo">
<operation name="hello">
<input wsam:Action="http://publicar.ws.org.mx/HolaMundo/helloRequest" message="tns:hello"/>
<output wsam:Action="http://publicar.ws.org.mx/HolaMundo/helloResponse" message="tns:helloResponse"/>
</operation>
</portType>
<binding name="HolaMundoPortBinding" type="tns:HolaMundo">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="hello">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="HolaMundo">
<port name="HolaMundoPort" binding="tns:HolaMundoPortBinding">
<soap:address location="http://localhost:8084/HolaMundo/HolaMundo"/>
</port>
</service>
</definitions>
Java client code
public class cliente {
public cliente() {
}
public static String consumir(Object[] parametros){
String regresar = null;
Service service = null;
Call call = null;
String endpoint = null;
try {
endpoint = "http://localhost:8084/HolaMundo/HolaMundo";
service = new Service();
call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName("hello");
regresar=String.valueOf(call.invoke(parametros));
}// try
catch (Exception e) {
e.printStackTrace();
}// catch
finally {
return regresar;
}// finally
}
public static void main(String[] args) {
try {
String parametro = "José";
String respuesta = consumir(new Object[]{parametro});
System.out.println("respuesta: --->" + respuesta);
} catch (Exception e) {
System.err.println(e.toString());
}
}
}
but i am getting the error
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Client
faultSubcode:
faultString: Cannot find dispatch method for {}hello
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:Cannot find dispatch method for {}hello
help me. thanks

Related

java web service calculator failing with postman cannot find dispatch method

so I have a simple calculator web service that im deploying locally using Jakarta.
its made up of three classes shown below.
Calculator
/**
* The annotation #WebService signals that this is the
* SEI (Service Endpoint Interface). #WebMethod signals
* that each method is a service operation.
*
* The #SOAPBinding annotation impacts the under-the-hood
* construction of the service contract, the WSDL
* (Web Services Definition Language) document. Style.RPC
* simplifies the contract and makes deployment easier.
*/
#WebService
#SOAPBinding(style = Style.RPC) // more on this later
public interface Calculator {
#WebMethod public double multiply(int i, int j);
#WebMethod public double minus(int i, int j);
#WebMethod public double plus(int i, int j);
#WebMethod double divide(int i, int j);
}
calculatorImpl
#WebService(endpointInterface = "calculator.Calculator")
public class CalculatorImpl implements Calculator {
#Override
public double multiply(int i , int j){
return i * j;
}
#Override
public double minus(int i , int j){
return i - j;
}
#Override
public double plus(int i , int j){
return i + j;
}
#Override
public double divide(int i, int j){
return i / j;
}
}
calculatorPublish
public class CalculatorPublish {
public static void main(String[] args) {
// TODO Auto-generated method stub
Endpoint.publish("http://127.0.0.1:8080/c", new CalculatorImpl());
}
}
so on to the problem. I can publish the webservice and it seems to work fine and generate the wsdl file shown below.
however when attempting to test this via postman I keep getting
Cannot find dispatch method for {}plus
this error happens for all the requests regardless of methods
in regards to postman:
im using post request
this is my url {{CalculatorImp|PortBaseUrl}}/c
I've removed charset from content type and only have xml
I've added SOAPAction with http://calculator/plus
I can't for the life of me work out why this isn't working
if any more info is needed please ask
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://calculator/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://calculator/" name="CalculatorImplService">
<types/>
<message name="multiply">
<part name="arg0" type="xsd:int"/>
<part name="arg1" type="xsd:int"/>
</message>
<message name="multiplyResponse">
<part name="return" type="xsd:double"/>
</message>
<message name="plus">
<part name="arg0" type="xsd:int"/>
<part name="arg1" type="xsd:int"/>
</message>
<message name="plusResponse">
<part name="return" type="xsd:double"/>
</message>
<message name="divide">
<part name="arg0" type="xsd:int"/>
<part name="arg1" type="xsd:int"/>
</message>
<message name="divideResponse">
<part name="return" type="xsd:double"/>
</message>
<message name="minus">
<part name="arg0" type="xsd:int"/>
<part name="arg1" type="xsd:int"/>
</message>
<message name="minusResponse">
<part name="return" type="xsd:double"/>
</message>
<portType name="Calculator">
<operation name="multiply" parameterOrder="arg0 arg1">
<input wsam:Action="http://calculator/Calculator/multiplyRequest" message="tns:multiply"/>
<output wsam:Action="http://calculator/Calculator/multiplyResponse" message="tns:multiplyResponse"/>
</operation>
<operation name="plus" parameterOrder="arg0 arg1">
<input wsam:Action="http://calculator/Calculator/plusRequest" message="tns:plus"/>
<output wsam:Action="http://calculator/Calculator/plusResponse" message="tns:plusResponse"/>
</operation>
<operation name="divide" parameterOrder="arg0 arg1">
<input wsam:Action="http://calculator/Calculator/divideRequest" message="tns:divide"/>
<output wsam:Action="http://calculator/Calculator/divideResponse" message="tns:divideResponse"/>
</operation>
<operation name="minus" parameterOrder="arg0 arg1">
<input wsam:Action="http://calculator/Calculator/minusRequest" message="tns:minus"/>
<output wsam:Action="http://calculator/Calculator/minusResponse" message="tns:minusResponse"/>
</operation>
</portType>
<binding name="CalculatorImplPortBinding" type="tns:Calculator">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
<operation name="multiply">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal" namespace="http://calculator/"/>
</input>
<output>
<soap:body use="literal" namespace="http://calculator/"/>
</output>
</operation>
<operation name="plus">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal" namespace="http://calculator/"/>
</input>
<output>
<soap:body use="literal" namespace="http://calculator/"/>
</output>
</operation>
<operation name="divide">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal" namespace="http://calculator/"/>
</input>
<output>
<soap:body use="literal" namespace="http://calculator/"/>
</output>
</operation>
<operation name="minus">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal" namespace="http://calculator/"/>
</input>
<output>
<soap:body use="literal" namespace="http://calculator/"/>
</output>
</operation>
</binding>
<service name="CalculatorImplService">
<port name="CalculatorImplPort" binding="tns:CalculatorImplPortBinding">
<soap:address location="http://127.0.0.1:8080/c"/>
</port>
</service>
</definitions>

WSDL creating parsing Error

I am trying to expose SOAP web service. For this I am using apache camel. So I have to use apache CXF to expose SOAP web service. But I am getting below error.
org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 223; The
value of the attribute
"prefix="xmlns",localpart="tns",rawname="xmlns:tns"" is invalid.
Prefixed namespace bindings may not be empty.
This is following I have coded.
#WebService(endpointInterface="com.ericsson.fdp.SOAP.FulfillmentService", targetNamespace = "http://apache.org/hello_world_soap_http",portName="FulfillmentServicePort",serviceName="FulfillmentService")
public class FulfillmentServiceImpl implements FulfillmentService{
#Produce(uri = "servlet:///fulfillmentService?servletName=FulfillmentService&matchOnUriPrefix=false")
private ProducerTemplate template;
#Override
public FulfillmentResponse buyProduct(String input, String userName, String password, String msisdn, String iname) {
Map<String,Object> queryMap = new HashMap<>();
queryMap.put("input", input);
queryMap.put("password", password);
queryMap.put("msisdn", msisdn);
queryMap.put("iname", iname);
String response = (String) template.requestBodyAndHeaders(null, queryMap);
FulfillmentResponse responseObject=null;
try {
responseObject = XmlUtil.unmarshall(response, FulfillmentResponse.class);
} catch (JAXBException e) {
e.printStackTrace();
}
return responseObject;
}
}
This is interface for above implementation
#WebService(name="fulfillmentService", targetNamespace = "http://apache.org/hello_world_soap_http",portName="FulfillmentServicePort",serviceName="FulfillmentService")
public interface FulfillmentService {
public FulfillmentResponse buyProduct(String input,String userName, String password,String msisdn,String iname);
}
I tried to check into. This is WSDL that is created for above code.
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="fulfillmentService" targetNamespace="" xmlns:ns2="http://schemas.xmlsoap.org/soap/http" xmlns:ns1="http://apache.org/hello_world_soap_http" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<wsdl:import namespace="http://apache.org/hello_world_soap_http" location="fulfillmentService.wsdl">
</wsdl:import>
<wsdl:binding name="fulfillmentServiceSoapBinding" type="ns1:fulfillmentService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="buyProduct">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="buyProduct">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="buyProductResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="fulfillmentService">
<wsdl:port name="fulfillmentServicePort" binding="fulfillmentServiceSoapBinding">
<soap:address location="http://127.0.0.1:8980/cisBusiness/services/fulFillment"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
How I can fix this error?
Try adding same namespace to the following.
xmlns:tns="http://www.example.org" targetNamespace="http://www.example.org"
Ofcourse, you can change the "http://www.example.org" to something of your liking...

PHP SoapClient calling Java Web-Service

this is first day I'm looking into Web-Services and I'm already stuck.
I got a simple Java-Code:
#WebService
public class ProductCatalog {
public void getCategory(String category) {
System.out.println(category);
}
}
Then I got the PHP-Code to call this function:
try{
$client = new SoapClient("link/to/wsdl");
$category = "music";
$client->getCategory($category);
}
catch(SoapFault $exception){
echo $exception->getMessage();
}
The console output is null.
The following
public void getProducts() {
System.out.println("Works");
}
with the same PHP-Code works, so the method call itself is working.
As said, it's my first day, so please don't go too hard on me!
edit: here is the WSDL
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://main/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://main/" name="ProductCatalogService">
<types>
<xsd:schema>
<xsd:import namespace="http://main/" schemaLocation="http://127.0.0.1:8080/Testmart/ProductCatalogService?xsd=1"/>
</xsd:schema>
</types>
<message name="getProducts">
<part name="parameters" element="tns:getProducts"/>
</message>
<message name="getProductsResponse">
<part name="parameters" element="tns:getProductsResponse"/>
</message>
<portType name="ProductCatalog">
<operation name="getProducts">
<input wsam:Action="http://main/ProductCatalog/getProductsRequest" message="tns:getProducts"/>
<output wsam:Action="http://main/ProductCatalog/getProductsResponse" message="tns:getProductsResponse"/>
</operation>
</portType>
<binding name="ProductCatalogPortBinding" type="tns:ProductCatalog">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="getProducts">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="ProductCatalogService">
<port name="ProductCatalogPort" binding="tns:ProductCatalogPortBinding">
<soap:address location="http://127.0.0.1:8080/Testmart/ProductCatalogService"/>
</port>
</service>
</definitions>
I encountered the same problem.
Call the function like this:
$response = $client->getCategory(array("arg0"=> $category));
I don't know why, but the first parameters of the function is arg0,
if it's not working, check the webservice with programs that can connect to webservice, and than you'll get the name of params.

Invoke a webservice from Android using SOAP

I'm consuming a webservice using java, i'm using the below WSDL, but i'm confused with the SOAP_ACTION:
NAMESPACE:
URL:
METHOD_NAME:
WSDL
<wsdl:definitions
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soapjms="http://www.w3.org/2010/soapjms/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://cloudx623.company.com:5555/ws/Monish:TestWebservice/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"name="TestWebservice"
targetNamespace="http://cloudx623.company.com:5555/ws/Monish:TestWebservice/myTest">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://localhost:8080/Monish/TestWebservice"
targetNamespace="http://localhost:8080/Monish/TestWebservice">
<xsd:element name="myTest" type="tns:myTest"/>
<xsd:element name="myTestResponse" type="tns:myTestResponse"/>
<xsd:complexType name="myTest">
<xsd:sequence>
<xsd:element name="a" nillable="true" type="xsd:string"/>
<xsd:element name="b" nillable="true" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="myTestResponse">
<xsd:sequence>
<xsd:element name="output" nillable="true" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
<wsdl:message name="TestWebservice_PortType_myTestResponse">
<wsdl:part name="parameters" element="tns:myTestResponse"></wsdl:part>
</wsdl:message>
<wsdl:message name="TestWebservice_PortType_myTest">
<wsdl:part name="parameters" element="tns:myTest"></wsdl:part>
</wsdl:message>
<wsdl:portType name="TestWebservice_PortType">
<wsdl:operation name="myTest">
<wsdl:input message="tns:TestWebservice_PortType_myTest"></wsdl:input>
<wsdl:output message="tns:TestWebservice_PortType_myTestResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="Monish_TestWebservice_Binder" type="tns:TestWebservice_PortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="myTest">
<soap:operation soapAction="Monish_TestWebservice_Binder_myTest" style="document"/>
<wsdl:input>
<soap:body parts="parameters" use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body parts="parameters" use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="TestWebservice">
<wsdl:port name="Monish_TestWebservice_Port" binding="tns:Monish_TestWebservice_Binder">
<soap:address location="http://192.28.50.46:5555/ws/Monish:TestWebservice/Monish_TestWebservice_Port"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
The Java code using ksoap2 is as below
private static final String SOAP_ACTION = "http://cloudx623.company.com:5555/ws/Monish:TestWebservice/myTest";
private static final String METHOD_NAME = "myTest";
private static final String NAMESPACE = "Monish_TestWebservice_Binder_myTest";
// !!!!! IMPORTANT!!!!! THE URL OF THE CoLDFUSION WEBSERVER NOT LOCALHOST BECAUSE LOCALHOST IS THE ANDROID EMULATOR !!!!!
private static final String URL = "http://192.28.50.46:5555/ws/Monish:TestWebservice?WSDL";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
//CALL the web service method with the two parameters vname and nname
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("a", "3");
request.addProperty("b", "4");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE (URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
// Get the SAOP Envelope back and the extract the body
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
Vector Vec = (Vector) resultsRequestSOAP.getProperty("getMessageReturn");
//Count of the arrays beneath starting from 0
//You can see the buildup with the php site with nusoap http://localhost/DA/nusoapclient_test2.php
int testat = Vec.size();
// It depends on how many arrays we have we can get to the attributs of one of them with get(0), get(1) ....
SoapObject test = (SoapObject) Vec.get(0);
System.out.println(envelope.getResponse());
//Get the attributes in the array
String tem = (String) test.getProperty("a");
tem = tem + " " + (String) test.getProperty("b");
//Just show it in a text area field called lblStatus
((TextView)findViewById(R.id.lblStatus)).setText(tem.toString());
// with androidhttptransport you need a catch block
} catch(Exception E) {
((TextView)findViewById(R.id.lblStatus)).setText("ERROR:" + E.getClass().getName() + ": " + E.getMessage());
}
}
Kindly let me know what the issue is. I'm getting a HTTP error status 500 in Android
I think you need to achieve like this.
You can see full example from here.
Part - 1 : Calling Web Service from Android
Part - 2: Webservice running in Android with Database
I hope this will help you.
Be sure that your are using right namespace or soap action. When you use wrong one, that error occures.

WS JUnit Testing: Cannot find dispatch method for {}

I have to develop several WS in Java. Cause I have no previous experience with this, I started with a simple example. Here the WS:
#WebService
public interface DataExchangeWebService {
public int doubleIt(int numberToDouble);
}
#WebService(targetNamespace = "http://www.example.com/ws/DataExchange",
portName = "DataExchangePort",
serviceName = "DataExchangeService",
endpointInterface = "xyz.DataExchangeWebService")
public class DataExchangeWebServiceImpl implements DataExchangeWebService {
#Override
public int doubleIt(int numberToDouble) {
return numberToDouble * 2;
}
}
Now I would like to test this Service only via JUnit. I found this blog entry, which builds the starting point for my test case. To keep it simple, I used the Java Endpoint class.
protected static URL wsdlURL;
protected static QName serviceName;
protected static QName portName;
protected static Endpoint endpoint;
protected static String address;
static {
serviceName = new QName("http://www.example.com/ws/DataExchange", "DataExchangeService");
portName = new QName("http://www.example.com/ws/DataExchange", "DataExchangePort");
}
#BeforeClass
public static void setUp() throws MalformedURLException {
address = "http://localhost:9000/ws/DataExchange";
wsdlURL = new URL(address + "?wsdl");
endpoint = Endpoint.publish(address, new DataExchangeWebServiceImpl());
}
#AfterClass
public static void tearDown() {
endpoint.stop();
}
This publishes the WS and generates the following WSDL:
<!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is
JAX-WS RI 2.1.6 in JDK 6. -->
<!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is
JAX-WS RI 2.1.6 in JDK 6. -->
<definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.example.com/ws/DataExchange" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://www.example.com/ws/DataExchange"
name="DataExchangeService">
<import namespace="http://dataexchange.sys.cs.iface.service.appserver.xyz/"
location="http://localhost:9000/ws/DataExchange?wsdl=1" />
<binding xmlns:ns1="http://dataexchange.sys.cs.iface.service.appserver.xyz/"
name="DataExchangePortBinding" type="ns1:DataExchangeWebService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="document" />
<operation name="doubleIt">
<soap:operation soapAction="" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
</binding>
<service name="DataExchangeService">
<port name="DataExchangePort" binding="tns:DataExchangePortBinding">
<soap:address location="http://localhost:9000/ws/DataExchange" />
</port>
</service>
</definitions>
Now I have two test cases. The first one, uses the plain service to make the request:
public void raw_service() {
Service service = Service.create(wsdlURL, serviceName);
DataExchangeWebService dataExchangeWebService = service.getPort(portName, DataExchangeWebService.class);
int resp = dataExchangeWebService.doubleIt(10);
assertEquals(20, resp);
}
This one is working fine. The problematic is the second one. It uses a a SOAP message to make the request:
public void raw_service_with_full_soap_message() throws DOMException, SOAPException, IOException {
Service service = Service.create(wsdlURL, serviceName);
Dispatch<SOAPMessage> disp = service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);
InputStream is = getClass().getClassLoader().getResourceAsStream("fullSOAPMessage.xml");
SOAPMessage reqMsg = MessageFactory.newInstance().createMessage(null, is);
assertNotNull(reqMsg);
SOAPMessage response = disp.invoke(reqMsg);
assertEquals("Double-It not doubling zero correctly", "0", response.getSOAPBody().getTextContent().trim());
}
The fullSOAPMessage.xml looks as follows:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:doubleIt xmlns:ns2="http://www.example.com/ws/DataExchange">
<numberToDouble>0</numberToDouble>
</ns2:doubleIt>
</soap:Body>
</soap:Envelope>
JUnit fails with:
javax.xml.ws.soap.SOAPFaultException: Cannot find dispatch method for {http://www.example.com/ws/DataExchange}doubleIt
The research I have done so far only revealed, that this has something to do with conflicts between the target namespace of the WS and the SOAP message. But in my eyes thats not the case here.
Some ideas about how to solve this or whats going on?

Categories