PHP SoapClient calling Java Web-Service - java

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.

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>

How to communicate with JAX-WS based SOAP webservice from 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

Android ksoap2 web service gets me the XML description of WSDL?

I'm using ksoap2 to call a simple method but at response I get the XML description on web service? This method simply get username and password and returns user balance.
My Code:
public class FaraSMSActivity extends Activity {
private final String NAMESPACE = "http://farasms.com/SMSSYSTEM";
private final String URL = "http://farasms.com/webservice/v2.02.php?wsdl";
private final String SOAP_ACTION = "http://farasms.com/SMSSYSTEM#WSGETBalance__";
private final String METHOD_NAME = "WSGETBalance__";
private String TAG = "PGGURU";
private static String res;
Button b;
TextView tv;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView) findViewById(R.id.tv_result);
b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
AsyncCallWS task = new AsyncCallWS();
task.execute();
}
});
}
public void getBalance() {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo usernamePI = new PropertyInfo();
usernamePI.setName("username");
usernamePI.setValue("faramobile");
usernamePI.setType(String.class);
request.addProperty(usernamePI);
PropertyInfo PasswordPI = new PropertyInfo();
PasswordPI.setName("password");
PasswordPI.setValue("09142168375");
PasswordPI.setType(String.class);
request.addProperty(PasswordPI);
//Create envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
//Set output SOAP object
envelope.setOutputSoapObject(request);
//Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envelope);
//Get the response
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
res = response.toString();
} catch (Exception e) {
Log.e("1111", e.getMessage());
e.printStackTrace();
}
Log.e("2222", androidHttpTransport.responseDump);
}
private class AsyncCallWS extends AsyncTask<String, Void, Void> {
#Override
protected Void doInBackground(String... params) {
getBalance();
return null;
}
#Override
protected void onPostExecute(Void result) {
tv.setText(res);
}
#Override
protected void onPreExecute() {
tv.setText("Connecting...");
}
#Override
protected void onProgressUpdate(Void... values) {
}
}
}
using this line I can log the result :
Log.e("2222", androidHttpTransport.responseDump);
It show exactly the thing when I explore "farasms.com/webservice/v2.02.php?wsdl" using web browser!!!!
This is the result :
<?xml version="1.0" encoding="ISO-8859-1"?>
<definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://farasms.com/SMSSYSTEM" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://farasms.com/SMSSYSTEM">
<types>
<xsd:schema targetNamespace="http://farasms.com/SMSSYSTEM">
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/>
<xsd:complexType name="authentication">
<xsd:all>
<xsd:element name="username" type="xsd:string"/>
<xsd:element name="password" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="returnCode">
<xsd:all>
<xsd:element name="msgid" type="xsd:string"/>
<xsd:element name="status" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="message">
<xsd:all>
<xsd:element name="fromNum" type="xsd:string"/>
<xsd:element name="toNum" type="xsd:string"/>
<xsd:element name="msg" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="fullmessage">
<xsd:all>
<xsd:element name="fromNum" type="xsd:string"/>
<xsd:element name="toNum" type="xsd:string"/>
<xsd:element name="msg" type="xsd:string"/>
<xsd:element name="date" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="returnCodes">
<xsd:complexContent>
<xsd:restriction base="SOAP-ENC:Array">
<xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:returnCode[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="msgids">
<xsd:complexContent>
<xsd:restriction base="SOAP-ENC:Array">
<xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="xsd:string[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="messages">
<xsd:complexContent>
<xsd:restriction base="SOAP-ENC:Array">
<xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:message[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="fullmessages">
<xsd:complexContent>
<xsd:restriction base="SOAP-ENC:Array">
<xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:fullmessage[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>
</types>
<message name="WSGETBalanceRequest">
<part name="authentication" type="tns:authentication"/>
<part name="username" type="xsd:string"/>
</message>
<message name="WSGETBalanceResponse">
<part name="result" type="xsd:string"/>
</message>
<message name="WSGETBalance__Request">
<part name="username" type="xsd:string"/>
<part name="password" type="xsd:string"/>
</message>
<message name="WSGETBalance__Response">
<part name="result" type="xsd:string"/>
</message>
<message name="WSdoSendSMS1Request">
<part name="authentication" type="tns:authentication"/>
<part name="message" type="tns:message"/>
</message>
<message name="WSdoSendSMS1Response">
<part name="result" type="xsd:string"/>
</message>
<message name="WSdoSendSMS3Request">
<part name="username" type="xsd:string"/>
<part name="password" type="xsd:string"/>
<part name="from" type="xsd:string"/>
<part name="to" type="xsd:string"/>
<part name="msg" type="xsd:string"/>
</message>
<message name="WSdoSendSMS3Response">
<part name="result" type="xsd:string"/>
</message>
<message name="WSdoSendSMS4Request">
<part name="authentication" type="tns:authentication"/>
<part name="message" type="tns:fullmessage"/>
</message>
<message name="WSdoSendSMS4Response">
<part name="result" type="xsd:string"/>
</message>
<message name="WSgetDeliveryRequest">
<part name="authentication" type="tns:authentication"/>
<part name="msgids" type="tns:msgids"/>
</message>
<message name="WSgetDeliveryResponse">
<part name="result" type="tns:returnCodes"/>
</message>
<message name="WSchangePasswordRequest">
<part name="authentication" type="tns:authentication"/>
<part name="newPassword" type="xsd:string"/>
</message>
<message name="WSchangePasswordResponse">
<part name="result" type="xsd:string"/>
</message>
<message name="WSgetMessagesRequest">
<part name="authentication" type="tns:authentication"/>
<part name="numRows" type="xsd:int"/>
</message>
<message name="WSgetMessagesResponse">
<part name="result" type="tns:messages"/>
</message>
<message name="WSgetNewMessagesRequest">
<part name="authentication" type="tns:authentication"/>
</message>
<message name="WSgetNewMessagesResponse">
<part name="result" type="tns:messages"/>
</message>
<portType name="SMSSYSTEMPortType">
<operation name="WSGETBalance">
<documentation>WSGETBalance</documentation>
<input message="tns:WSGETBalanceRequest"/>
<output message="tns:WSGETBalanceResponse"/>
</operation>
<operation name="WSGETBalance__">
<documentation>WSGETBalance__</documentation>
<input message="tns:WSGETBalance__Request"/>
<output message="tns:WSGETBalance__Response"/>
</operation>
<operation name="WSdoSendSMS1">
<documentation>WSdoSendSMS1</documentation>
<input message="tns:WSdoSendSMS1Request"/>
<output message="tns:WSdoSendSMS1Response"/>
</operation>
<operation name="WSdoSendSMS3">
<documentation>WSdoSendSMS3</documentation>
<input message="tns:WSdoSendSMS3Request"/>
<output message="tns:WSdoSendSMS3Response"/>
</operation>
<operation name="WSdoSendSMS4">
<documentation>WSdoSendSMS4</documentation>
<input message="tns:WSdoSendSMS4Request"/>
<output message="tns:WSdoSendSMS4Response"/>
</operation>
<operation name="WSgetDelivery">
<documentation>WSgetDelivery</documentation>
<input message="tns:WSgetDeliveryRequest"/>
<output message="tns:WSgetDeliveryResponse"/>
</operation>
<operation name="WSchangePassword">
<documentation>WSchangePassword</documentation>
<input message="tns:WSchangePasswordRequest"/>
<output message="tns:WSchangePasswordResponse"/>
</operation>
<operation name="WSgetMessages">
<documentation>WSgetMessages</documentation>
<input message="tns:WSgetMessagesRequest"/>
<output message="tns:WSgetMessagesResponse"/>
</operation>
<operation name="WSgetNewMessages">
<documentation>WSgetNewMessages</documentation>
<input message="tns:WSgetNewMessagesRequest"/>
<output message="tns:WSgetNewMessagesResponse"/>
</operation>
</portType>
<binding name="SMSSYSTEMBinding" type="tns:SMSSYSTEMPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="WSGETBalance">
<soap:operation soapAction="http://farasms.com/SMSSYSTEM#WSGETBalance" style="rpc"/>
<input>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="WSGETBalance__">
<soap:operation soapAction="http://farasms.com/SMSSYSTEM#WSGETBalance__" style="rpc"/>
<input>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="WSdoSendSMS1">
<soap:operation soapAction="http://farasms.com/SMSSYSTEM#WSdoSendSMS1" style="rpc"/>
<input>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="WSdoSendSMS3">
<soap:operation soapAction="http://farasms.com/SMSSYSTEM#WSdoSendSMS3" style="rpc"/>
<input>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="WSdoSendSMS4">
<soap:operation soapAction="http://farasms.com/SMSSYSTEM#WSdoSendSMS4" style="rpc"/>
<input>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="WSgetDelivery">
<soap:operation soapAction="http://farasms.com/SMSSYSTEM#WSgetDelivery" style="rpc"/>
<input>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="WSchangePassword">
<soap:operation soapAction="http://farasms.com/SMSSYSTEM#WSchangePassword" style="rpc"/>
<input>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="WSgetMessages">
<soap:operation soapAction="http://farasms.com/SMSSYSTEM#WSgetMessages" style="rpc"/>
<input>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="WSgetNewMessages">
<soap:operation soapAction="http://farasms.com/SMSSYSTEM#WSgetNewMessages" style="rpc"/>
<input>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="SMSSYSTEM">
<port name="SMSSYSTEMPort" binding="tns:SMSSYSTEMBinding">
<soap:address location="http://farasms.com/webservice/v2.02.php"/>
</port>
</service>
</definitions>
What wrong am i doing ?
OK, after searching a lot, I found the reason. The correct URL is this :
private final String URL = "http://farasms.com/webservice/v2.02.php";
I pointed the URL to WSDL itself not the webservice!

Axis WSDL2Java generation issue

I've wrote some simple service that consists of several files (wsdl, xsd).
In xsd file I've got following definition:
<xs:complexType name="ServerMessage">
<xs:sequence>
<xs:element name="type" type="xs:int"/>
<xs:element name="info" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ServerMessage" type="tns:ServerMessage"/>
Then this element is referenced in wsdl file like this
<wsdl:message name="createItemFault">
<wsdl:part name="createItemFault" element="tns:ServerMessage"/>
</wsdl:message>
<wsdl:portType name="Service">
<wsdl:operation name="createItem">
<wsdl:input message="tns:createItemRequest"/>
<wsdl:output message="tns:createItemResponse"/>
<wsdl:fault name="Fault" message="tns:createItemFault"/>
</wsdl:operation>
And at last
<wsdl:binding name="ServiceBinding" type="intf:Service">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="createItem">
<soap:operation soapAction="http://test.com/createItem"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
<wsdl:fault name="Fault">
<soap:fault name="Fault" use="literal"/>
</wsdl:fault>
</wsdl:operation>
After launching WSDL2Java I receive the following code
public interface ServerMessage extends org.apache.xmlbeans.XmlObject
{
How come ServerMessage becomes defined like this? When I've used WSDL2Java provided by Axis1 final definition in java file was like this
public class ServerMessage extends org.apache.axis.AxisFault implements java.io.Serializable
And after Axis2 generation resulting "item" is drastically differs, it's not even throwable. What am I doing wrong?
From that WSDL you should get a CreateItemFault (due to the wsdl:message name) that looks something like:
public class CreateItemFault extends java.lang.Exception {
private org.example.www.service.ServerMessageDocument faultMessage;
...
}
That ServerMessageDocument probably looks like:
public interface ServerMessageDocument extends org.apache.xmlbeans.XmlObject {
...
org.example.www.service.ServerMessage getServerMessage();
void setServerMessage(org.example.www.service.ServerMessage serverMessage);
org.example.www.service.ServerMessage addNewServerMessage();
...
}
And here's where we get to your ServerMessage:
public interface ServerMessage extends org.apache.xmlbeans.XmlObject {
...
}
The method signature should throw a CreateItemFault, though.

Problem with deserialization of String sent over wire with XStream

I am trying to create a simple webservice which takes a String as input and returns string as output.
I am using Ecelipse Helios and Axis 2.15.
I am writing simple WSDL for the same.
I am generating the stubs using code generator.
New ->code generator -> java class from wsdl-> give WSDL and generates the java skeletons.
And in the skelton I am just print the value what is coming as parameter. and returning the same value.
I have written client code to invoke the method of the webservice. which takes a String.
but when I am trying to invoke the method I am getting following exception and it's not hitting the webservice.
Infact I am using XStream along with Client/WebService.
Code goes like this for the webservice skeleton:
public com.url.pkg.ShowInputResponse showInput(
com.url.pkg.ShowInput showInput) {
// TODO : fill this with the necessary business logic
String inputString = showInput.getInputString();
System.out.println("INput String is :\n" + inputString);
XStream xStream = new XStream();
System.out.println("After XStream Declaration...");
SOVO vo = null;
try {
vo = (SOVO) xStream.fromXML(inputString);
} catch (Throwable e) {
System.out.println(e);
e.printStackTrace();
}
System.out.println("After SOVO casting from XML");
System.out.println(vo.getName());
System.out.println(vo.getParams());
// TODO: business logic
ShowInputResponse response = new ShowInputResponse();
response.set_return(inputString);
return response;
}
My client code goes like this :
public static void main(String[] args) throws Exception {
BasicServiceStub stub = new BasicServiceStub();
ShowInput request = new ShowInput();
SOVO sovo = new SOVO();
sovo.setName("I am the post for SO");
Map params = new HashMap();
params.put("key1", "val1");
params.put("key2", "val2");
sovo.setParams(params);
XStream xStream = new XStream();
String soVoString = xStream.toXML(sovo);
// System.out.println(soVoString);
request.setInputString(soVoString);
ShowInputResponse response = stub.showInput(request);
System.out.println("....................................");
System.out.println("response = " + response.get_return());
}
SOVO is a simple POJO which is present at both client and webservice side.
public class SOVO {
private String name;
private Map params;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Map getParams() {
return params;
}
public void setParams(Map params) {
this.params = params;
}
}
And last but most important WSDL is here:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ns="http://pkg.url.com" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://pkg.url.com">
<wsdl:types>
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://pkg.url.com">
<xs:element name="showInput">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="inputString" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="showInputResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="showInputRequest">
<wsdl:part name="parameters" element="ns:showInput"/>
</wsdl:message>
<wsdl:message name="showInputResponse">
<wsdl:part name="parameters" element="ns:showInputResponse"/>
</wsdl:message>
<wsdl:portType name="BasicServicePortType">
<wsdl:operation name="showInput">
<wsdl:input message="ns:showInputRequest" wsaw:Action="urn:showInput"/>
<wsdl:output message="ns:showInputResponse" wsaw:Action="urn:showInputResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicServiceSoap11Binding" type="ns:BasicServicePortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="showInput">
<soap:operation soapAction="urn:showInput" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="BasicServiceSoap12Binding" type="ns:BasicServicePortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="showInput">
<soap12:operation soapAction="urn:showInput" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="BasicServiceHttpBinding" type="ns:BasicServicePortType">
<http:binding verb="POST"/>
<wsdl:operation name="showInput">
<http:operation location="BasicService/showInput"/>
<wsdl:input>
<mime:content type="text/xml" part="showInput"/>
</wsdl:input>
<wsdl:output>
<mime:content type="text/xml" part="showInput"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="BasicService">
<wsdl:port name="BasicServiceHttpSoap11Endpoint" binding="ns:BasicServiceSoap11Binding">
<soap:address location="http://localhost:8080/axis2/services/BasicService"/>
</wsdl:port>
<wsdl:port name="BasicServiceHttpSoap12Endpoint" binding="ns:BasicServiceSoap12Binding">
<soap12:address location="http://localhost:8080/axis2/services/BasicService"/>
</wsdl:port>
<wsdl:port name="BasicServiceHttpEndpoint" binding="ns:BasicServiceHttpBinding">
<http:address location="http://localhost:8080/axis2/services/BasicService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
And the Stack trace for the exception I must modify :
I am not very sure if its hitting the webservice layer.
Caused by: org.apache.axis2.AxisFault: string
at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:446)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:371)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:417)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at com.url.pkg.BasicServiceStub.showInput(BasicServiceStub.java:184)
at com.url.pkg.Client.main(Client.java:30)
It looks like more its some problem with XStream desirialization. Even though SOVO is in the classpath why its happening? Am I missing something?
When I try sending XXXXX as string it tells:
only whitespace content allowed before start tag and not X (position: START_DOCUMENT seen X... #1:1)
When i try sending "some value" it says:
only whitespace content allowed before start tag and not s (position: START_DOCUMENT seen s... #1:1)
I am not sure what's wrong.
I would suggest the following:
Test the service with another client
Use soapUI to generate a valid test request for your showInput method. If you don't get any errors using this tool, you know your service is working fine. If you do get an error, then you know to start digging around in your service code.
Enable client side logging for SOAP messages
Add these JVM options when running your client:
-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
-Dorg.apache.commons.logging.simplelog.showdatetime=true
-Dorg.apache.commons.logging.simplelog.log.httpclient.wire=debug
-Dorg.apache.commons.logging.simplelog.log.org.apache.commons.httpclient=debug
This will let you to see the SOAP messages that get transmitted. Pay close attention to content appearing before your start tags like the error message says.

Categories