Magento API: Publish a new method in soap V2 - api

I'm new in Magento and I'd like to create a my own API v2 method.
I've built a simple project...
Mycompany
Mymodule
etc
api.xml
config.xml
wsdl.xml
Model
Api
V2.php
Api.php
These are the main files...
(1) api.xml
<config>
<api>
<resources>
<mymodule translate="title" module="mymodule">
<title>mymodule</title>
<model>mymodule/api</model>
<methods>
<myapimethod translate="title" module="mymodule">
<title>myapimethod</title>
<acl>mymodule/myapimethod</acl>
</myapimethod>
</methods>
</mymodule>
</resources>
<v2>
<resources_function_prefix>
<mymodule>mymodule</mymodule>
</resources_function_prefix>
</v2>
<acl>
<resources>
<mymodule translate="title" module="mymodule">
<title>Mymodule</title>
<sort_order>2000</sort_order>
<myapimethod translate="title" module="mymodule">
<title>myapimethod</title>
</myapimethod>
</mymodule>
</resources>
</acl>
</api>
</config>
(2) wsdl.xml
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:typens="urn:{{var wsdl.name}}" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/"
name="{{var wsdl.name}}" targetNamespace="urn:{{var wsdl.name}}">
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/" />
</schema>
</types>
<message name="myapimethodRequest">
<part name="sessionId" type="xsd:string"/>
<part name="message" type="xsd:string" />
</message>
<message name="myapimethodResponse">
<part name="result" type="xsd:string" />
</message>
<portType name="{{var wsdl.handler}}PortType">
<operation name="myapimethod">
<documentation>this is an example of api method...</documentation>
<input message="typens:myapimethodRequest" />
<output message="typens:myapimethodResponse" />
</operation>
</portType>
<binding name="{{var wsdl.handler}}Binding" type="typens:{{var wsdl.handler}}PortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="myapimethod">
<soap:operation soapAction="urn:{{var wsdl.handler}}Action" />
<input>
<soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
</binding>
<service name="{{var wsdl.name}}Service">
<port name="{{var wsdl.handler}}Port" binding="typens:{{var wsdl.handler}}Binding">
<soap:address location="{{var wsdl.url}}" />
</port>
</service>
</definitions>
(3) Api.php
<?php
class Mycompany_Mymodule_Model_Api extends Mage_Api_Model_Resource_Abstract
{
public function myapimethod($sessionId, $message)
{
return "This is the message : ".$message;
}
}
(4) V2.php
<?php
class Mycompany_Mymodule_Model_Api_V2 extends Mycompany_Mymodule_Model_Api
{
}
(5) test.php
<?php
try {
define("SOAP_WSDL",'http://localhost:8080/magento/index.php/api/?wsdl');
define("SOAP_WSDL2",'http://localhost:8080/magento/index.php/api/v2_soap?wsdl=1');
define("SOAP_USER","dtsSoapUser");
define("SOAP_PASS","casares");
if($_GET['ver'] == '2') {
$client = new SoapClient(SOAP_WSDL2, array('trace' => 1,'cache_wsdl' => 0));
echo "<br>version 2 <br>";
}
else {
$client = new SoapClient(SOAP_WSDL,array('trace' => 1,'cache_wsdl' => 0));
echo "<br>version 1 <br>";
}
$session = $client->login(SOAP_USER, SOAP_PASS);
$result = array();
try {
if($_GET['ver'] == '2') {
$result = $client->Myapimethod($session, "My message....");
var_dump ( $result);
} else {
$result= $client->call($session, 'mymodule.myapimethod', array($session, "My message ...."));
var_dump($result);
}
} catch (SoapFault $exception) {
echo 'EXCEPTION='.$exception;
}
echo "<br>end test<br>";
} catch (Exception $e){
echo var_dump($e);
throw $e;
}
?>
Using the following Url, the result is:
.../test.php/?ver=1
version 1
string 'This is the message : My message ....' (length=37)
end test
It's to say: using Soap v1, the method works!.
But if I use the soap v2 call...
.../test.php/?ver=2
the result is:
version 2
EXCEPTION=SoapFault exception: [3] Invalid api path. in C:\wamp\www\PruebasPHP\test.php:22 Stack trace: #0 C:\wamp\www\PruebasPHP\test.php(22): SoapClient->__call('Myapimethod', Array) #1 C:\wamp\www\PruebasPHP\test.php(22): SoapClient->Myapimethod('b9e1e8d15a61398...', 'My message....') #2 {main}
end test
The role has access to all the api resources...
I don't know what is wrong? can anyone help me with this problem?
Can be anything related to acl's?
Thanks in advance!!!

It's a problem of path.
I've solve the problems as follows...
The folder structure of my project is:
Mycompany->
Mymodule->
etc->
api.xml
config.xml
wsdl.xml
wsi.xml
Model->
Folder->
Api.php
Api->
V2.ph
(1) api.xml
<?xml version="1.0"?>
<config>
<api>
<resources>
<mymodule_folder translate="title" module="mymodule">
<title>mymodule</title>
<!-- acl>mymodule/api</acl>-->
<model>mymodule/folder_api</model>
<acl>mymodule/folder</acl>
<methods>
<myapimethod translate="title" module="mymodule">
<title>myapimethod</title>
<acl>mymodule/folder/myapimethod</acl>
</myapimethod>
</methods>
</mymodule_folder>
</resources>
<resources_alias>
<folder>mymodule_folder</folder>
</resources_alias>
<v2>
<resources_function_prefix>
<folder>folder</folder>
</resources_function_prefix>
</v2>
<acl>
<resources>
<mymodule translate="title" module="mymodule">
<title>mymodule</title>
<sort_order>1</sort_order>
<folder translate="title" module="mymodule">
<title>Folder</title>
<sort_order>2000</sort_order>
<myapimethod translate="title" module="mymodule">
<title>myapimethod</title>
</myapimethod>
</folder>
</mymodule>
</resources>
</acl>
</api>
</config>
Pay attention to the name of the api method "myapimethod" and the folder "Model\Folder".
(2) wsdl.xml
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:typens="urn:{{var wsdl.name}}" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/"
name="{{var wsdl.name}}" targetNamespace="urn:{{var wsdl.name}}">
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/" />
</schema>
</types>
<message name="folderMyapimethodRequest">
<part name="sessionId" type="xsd:string"/>
<part name="message" type="xsd:string" />
</message>
<message name="folderMyapimethodResponse">
<part name="result" type="xsd:string" />
</message>
<portType name="{{var wsdl.handler}}PortType">
<operation name="folderMyapimethod">
<documentation>this is an example of api method...</documentation>
<input message="typens:folderMyapimethodRequest" />
<output message="typens:folderMyapimethodResponse" />
</operation>
</portType>
<binding name="{{var wsdl.handler}}Binding" type="typens:{{var wsdl.handler}}PortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="folderMyapimethod">
<soap:operation soapAction="urn:{{var wsdl.handler}}Action" />
<input>
<soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
</binding>
<service name="{{var wsdl.name}}Service">
<port name="{{var wsdl.handler}}Port" binding="typens:{{var wsdl.handler}}Binding">
<soap:address location="{{var wsdl.url}}" />
</port>
</service>
</definitions>
The name of the api method must be: folderMethodname", where "folder" is the name of the folder under the "Model" where the api method is declared.., in our case : "folderMyapimethod"
(3) api.php
<?php
class Mycompany_Mymodule_Model_Folder_Api extends Mage_Api_Model_Resource_Abstract
{
public function myapimethod( $message)
{
return "This is the message: ".$message;
}
}
(4) V2.php
<?php
class Mycompany_Mymodule_Model_Folder_Api_V2 extends Mycompany_Mymodule_Model_Folder_Api
{
//empty
}
(5) test.php
$result = $client->folderMyapimethod($session,$message);
This line shows how to call to my api method...
It works!

Your code is excellent ! there's no mistake on
As far as i know (from my experience). that exception shown because your tag placement on your api.xml doesn't match with you called function.
check on files
core\Mage\Catalog\Model\Product\Api.php
and
core\Mage\Catalog\Model\Product\Api\V2.php
there is a function named items on both class.
maybe you must add your code on api_v1 on api_v2 class like this:
<?php
class Mycompany_Mymodule_Model_Api_V2 extends Mycompany_Mymodule_Model_Api
{
public function myapimethod($sessionId, $message)
{
return "This is the message : ".$message;
}
}
or
maybe it's cache.
The cache is strong, because it's API V2. try to clear your cache on:
admin -> system -> cache management -> clear magento cache.
try to clear wsdl.xml cache on /tmp/wsdl.xml (hidden on your server) try to grep it.
remove all files on var/log/*

Related

Why I can't save logging to database via NLog?

Why I can't save logging to database via NLog? Then I save to file is working perfectly, but to database not.
My nLog.config:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="alllogs" xsi:type="File" fileName="C:\Users\Artyrik\Desktop\RVT\RVT_Administrator\RVT_Administrator\file.txt" />
<target name="database" xsi:type="Database" connectionString="Server=DESKTOP-GDI15RS\\SQLEXPRESS;Database=RVTLogs;Trusted_Connection=True;MultipleActiveResultSets=true"
commandText="insert into dbo.Administrator (
MachineName, Logged, Level, Message,
Logger, Callsite, Exception
) values (
#MachineName, #Logged, #Level, #Message,
#Logger, #Callsite, #Exception
);">
<parameter name="#MachineName" layout="${machinename}" />
<parameter name="#Logged" layout="${date}" />
<parameter name="#Level" layout="${level}" />
<parameter name="#Message" layout="${message}" />
<parameter name="#Logger" layout="${logger}" />
<parameter name="#Callsite" layout="${callsite}" />
<parameter name="#Exception" layout="${exception:tostring}" />
</target>
</targets>
<rules>
<!--<logger name="Admin" minlevel="Trace" writeTo="alllogs" />
<logger name="User" minlevel="Trace" writeTo="alllogs" />-->
<logger name="AdminLog" minlevel="Trace" writeTo="database" />
</rules>
</nlog>
Implement in a Class:
```
private static Logger _nLog = LogManager.GetLogger("AdminLog");
_nLog.Info(data.IP + " tried to auth.");```
You need to add internalLogFile parameter to your nlog tag. You will have an internal log and see what is wrong with your configuration if an error occured :
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogLevel="Info"
internalLogFile="c:\temp\internal-nlog.txt">

Namespace not matching in WLS Published WSDL for JAX-WS RPC Style webservice

After deploying a JAX-WS, RPC Style webservice, the WSDL published in
Weblogic server 12.1.3 does not corresponds to initial WSDL. The namespace in
is not matching.
ISSUE:
Initial WSDL Contains:
<soap12:body parts="helloReq" use="literal" namespace=""/>
Published WSDL Contains:
<soap12:body use="literal" namespace="http://sample"/>
Due to this, inappropriate SOAP Request is getting formed which is throwing
error on invocation : "Cannot find dispatch method for {}hello".
Initial WSDL:
<?xml version="1.0" encoding="UTF-8"?>
<types>
<xsd:schema targetNamespace="http://sample">
<xsd:complexType name="hello">
<xsd:sequence>
<xsd:element type="xsd:string" name="input" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="helloResponse">
<xsd:sequence>
<xsd:element type="xsd:string" name="output" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</types>
<message name="hello">
<part name="helloReq" type="tns:hello" />
</message>
<message name="helloResponse">
<part name="helloRes" type="tns:helloResponse" />
</message>
<portType name="HelloServicePort">
<operation name="hello">
<input message="tns:hello" />
<output message="tns:helloResponse" />
</operation>
</portType>
<binding type="tns:HelloServicePort" name="HelloServicePort">
<soap12:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="hello">
<soap12:operation style="rpc" soapAction="" />
<input>
<soap12:body parts="helloReq" use="literal" namespace="" />
</input>
<output>
<soap12:body parts="helloRes" use="literal" namespace="" />
</output>
</operation>
</binding>
<service name="HelloService">
<port name="HelloServicePort" binding="tns:HelloServicePort">
<soap12:address location="http://localhost:7201/hello/HelloService" />
</port>
</service>
Published 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:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://sample"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://sample" name="HelloService">
<types>
<xsd:schema>
<xsd:import namespace="http://sample"
schemaLocation="http://localhost:7022/hello/jaxws/HelloService?xsd=1" />
</xsd:schema>
</types>
<message name="hello">
<part name="helloReq" type="tns:hello" />
</message>
<message name="helloResponse">
<part name="helloRes" type="tns:helloResponse" />
</message>
<portType name="HelloServicePort">
<operation name="hello">
<input wsam:Action="http://sample/HelloServicePort/helloRequest"
message="tns:hello" />
<output wsam:Action="http://sample/HelloServicePort/helloResponse"
message="tns:helloResponse" />
</operation>
</portType>
<binding name="HelloServicePortBinding" type="tns:HelloServicePort">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http"
style="rpc" />
<operation name="hello">
<soap12:operation soapAction="" />
<input>
<soap12:body use="literal" namespace="http://sample" />
</input>
<output>
<soap12:body use="literal" namespace="http://sample" />
</output>
</operation>
</binding>
<service name="HelloService">
<port name="HelloServicePort" binding="tns:HelloServicePortBinding">
<soap12:address location="http://localhost:7022/hello/jaxws/HelloService" />
</port>
</service>
Is this the default behavior or a bug in JAX-WS? Is there any workaround to make this work without changing the wsdl?
Please share some pointers.
Thanks.

Magento Custom Api Code can't pass in parameters (Undefined variable error)

Hello fellow Magento hackers,
I am trying to create a custom API handler and while I can get the function to run, passing in variables for some reason does not work and I get an empty parameter called in. System.log returns the error: DEBUG (7): Undefined variable: inputvar. Please help!
First things first, my directory structure at app/code/local is as follows:
Company
-Customapi
-etc
-api.xml
-config.xml
-wsdl.xml
-Model
-Order
-Api.php
-Api
-V2.php
Now for the code.
Api.php
class Company_Customapi_Model_Order_Api extends Mage_Api_Model_Resource_Abstract
{
public function test($inputvar){
echo $inputvar;
$result = $inputvar;
return $result;
}
}
V2.php
class Company_Customapi_Model_Order_Api_V2 extends Company_Customapi_Model_Order_Api {}
wsdl.xml:
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:typens="urn:{{var wsdl.name}}" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/"
name="{{var wsdl.name}}" targetNamespace="urn:{{var wsdl.name}}">
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"
schemaLocation="http://schemas.xmlsoap.org/soap/encoding/"/>
</schema>
</types>
<message name="getTestRequest">
<part name="inputvar" type="xsd:string"/>
</message>
<message name="getTestResponse">
<part name="result" type="xsd:string"/>
</message>
<portType name="{{var wsdl.handler}}PortType">
<operation name="customapiOrderTest">
<documentation>Test the API.</documentation>
<input message="typens:getTestRequest"/>
<output message="typens:getTestResponse"/>
</operation>
</portType>
<binding name="{{var wsdl.handler}}Binding" type="typens:{{var wsdl.handler}}PortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="customapiOrderTest">
<soap:operation soapAction="urn:{{var wsdl.handler}}Action"/>
<input>
<soap:body namespace="urn:{{var wsdl.name}}" use="encoded"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body namespace="urn:{{var wsdl.name}}" use="encoded"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="{{var wsdl.name}}Service">
<port name="{{var wsdl.handler}}Port" binding="typens:{{var wsdl.handler}}Binding">
<soap:address location="{{var wsdl.url}}"/>
</port>
</service>
</definitions>
api.xml:
<?xml version="1.0"?>
<config>
<api>
<resources>
<customapi_order translate="title" module="company_customapi">
<model>company_customapi_model_order_api</model>
<title>company Order API</title>
<acl>order</acl>
<methods>
<test translate="title" module="company_customapi">
<title>A test function.</title>
<acl>test</acl>
</test>
</methods>
</customapi_order>
</resources>
<v2>
<resources_function_prefix>
<customapi_order>customapiOrder</customapi_order>
<!-- prefix+functionname = customapiOrderTest -->
</resources_function_prefix>
</v2>
</api>
</config>
config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Company_Customapi>
<version>0.1.0</version>
</Company_Customapi>
</modules>
<global>
<models>
<Company_Customapi>
<class>Company_Customapi_Model</class>
</Company_Customapi>
</models>
</global>
</config>
test.php:
$session = $client->login(SOAP_USER, SOAP_PASS);
$result = $client->customapiOrderTest($session, "inputvaluehere");
var_dump ( $result);
Found the answer. In Wsdl.xml you have to specify the session parameter as one of your inputs (your function on the server can't see it but you do pass it in from the client)
<message name="getTestRequest">
<part name="sessionId" type="xsd:string"/>
<part name="inputvar" type="xsd:string"/>
</message>
Only took me 2 days to find the answer. Don't you just love Magento!

Cannot find dispatch method for Request=[SOAPAction="",Payload={http://domain

I am newbie to web services, I am trying to create a Weblogic webservice from wsdl.
I am able to work with the service If i have only 1 operation inside wsdl, but if I add second operation, I am receiving the error Cannot find dispatch method for Request=[SOAPAction="",Payload={//domain . I am just adding the operation in portType and binding. . I am really not sure what I am missing.
I have just added operation in portType and binding . . Do I need to change anything else apart from this ?
here is my wsdl
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is
JAX-WS RI 2.2.6hudson-86 svn-revision#12773. -->
<definitions targetNamespace="http://service.training.indus.com/"
name="CalculatorService" xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsp="http://www.w3.org/ns/ws-policy"
xmlns:calSvc="http://service.training.indus.com/"
xmlns:calciInOut="http://domain.training.indus.com/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<types>
<xsd:schema>
<xsd:import namespace="http://domain.training.indus.com/"
schemaLocation="../xsd/CalculatorService_schema1.xsd" />
</xsd:schema>
</types>
<message name="calciInputMsg">
<part name="parameters" element="calciInOut:calciInputRequest" />
</message>
<message name="calciOutputMsg">
<part name="parameters" element="calciInOut:calciOutputResponse" />
</message>
<portType name="CalculatorPort">
<operation name="multiply">
<inputwsam:Action="http://service.training.indus.com/Calculator/multiplyRequest"
message="calSvc:calciInputMsg" />
<output wsam:Action="http://service.training.indus.com/Calculator/multiplyResponse"
message="calSvc:calciOutputMsg" />
</operation>
<operation name="addition">
<input wsam:Action="http://service.training.indus.com/Calculator/multiplyRequest"
message="calSvc:calciInputMsg" />
<output
wsam:Action="http://service.training.indus.com/Calculator/multiplyResponse"
message="calSvc:calciOutputMsg" />
</operation>
</portType>
<binding name="CalculatorPortBinding" type="calSvc:CalculatorPort">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="document" />
<operation name="multiply">
<soap:operation soapAction="" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
<operation name="addition">
<soap:operation soapAction="" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
</binding>
<service name="CalculatorService">
<port name="CalculatorSvcPort" binding="calSvc:CalculatorPortBinding">
<soap:address location="http://localhost:9010/TestTopDown/CalculatorService" />
</port>
</service>
</definitions>
Is because of this:
<soap:operation soapAction="" />
To solve your problem, put this in your method in your class:
#WebMethod(action="add")

Axis2 client Unexpected subelement apple

I developed both a server and client application using Axis2 version 1.5.4, Java 1.6 and the server is deployed on tomcat 6.
The services are declared using annotations, so there is no .aar files or anything of that sort.
The WSDL was created automatically by Axis2.
The client was made using the stubs and parameters generated by WSDL2Java using the command:
%axis2_home%\bin\WSDL2Java -p com.audaxys.leaseclient.servicestub.generic -d adb -Eosv -s -g -u -uw -or -sp -S src/main/java -R src/main/resources --noBuildXML -uri %baseurl%/AppleFinderService.Rpc?wsdl
When the client app calls the method public Apple loadApple(String appType) the server responds returning one instance of Apple class, but the client is unable to de-serialize the response and throws this exception.
If you know how to fix this, could you please share it with me?
Any clues would be greatly appreciated, really!
Full stack trace:
org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement apple
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
at com.audaxys.leaseclient.servicestub.generic.AppleFinderServiceStub.fromOM(AppleFinderServiceStub.java:1015)
at com.audaxys.leaseclient.servicestub.generic.AppleFinderServiceStub.loadApple(AppleFinderServiceStub.java:343)
at com.audaxys.lease.ws.client.TestDummyServices.testLoadApple(TestDummyServices.java:107)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.Exception: org.apache.axis2.databinding.ADBException: Unexpected subelement apple
at com.audaxys.www.namespaces.leasews.LoadAppleResponse$Factory.parse(LoadAppleResponse.java:454)
at com.audaxys.leaseclient.servicestub.generic.AppleFinderServiceStub.fromOM(AppleFinderServiceStub.java:981)
... 18 more
Caused by: org.apache.axis2.databinding.ADBException: Unexpected subelement apple
at com.audaxys.www.namespaces.leasews.LoadAppleResponse$Factory.parse(LoadAppleResponse.java:448)
... 19 more
ServiceDeclaration
package com.audaxys.lease.model.generic;
import .....;
#WebService(name="AppleFinderService", serviceName="AppleFinderService", portName="Rpc", targetNamespace="http://www.audaxys.com/namespaces/leasews")
#SOAPBinding(style = Style.RPC, parameterStyle = ParameterStyle.WRAPPED)
public class AppleFinderImpl {
#WebResult(name = "apple")
public Apple loadApple(String appType) {
Apple a = new Apple();
a.setAppleType(appType);
return a;
}
}
Apple class
package com.audaxys.lease.model.generic;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement(namespace="http://www.audaxys.com/namespaces/leasews")
public class Apple {
private String appleType;
public Apple() {
super();
}
public String getAppleType() {
return appleType;
}
public void setAppleType(String appleType) {
this.appleType = appleType;
}
}
WSDL
<?xml version="1.0" encoding="UTF-8" ?>
<definitions name="AppleFinderService" targetNamespace="http://www.audaxys.com/namespaces/leasews" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.audaxys.com/namespaces/leasews" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://jaxb.dev.java.net/array">
<types>
<xsd:schema>
<xsd:import namespace="http://www.audaxys.com/namespaces/leasews" schemaLocation="AppleFinderService.Rpc?xsd=AppleFinderService_schema1.xsd" />
</xsd:schema>
<xsd:schema>
<xsd:import namespace="http://jaxb.dev.java.net/array" schemaLocation="AppleFinderService.Rpc?xsd=AppleFinderService_schema2.xsd" />
</xsd:schema>
</types>
<message name="loadAppleResponse">
<part name="apple" type="tns:apple" />
</message>
<message name="getAppleArray">
<part name="arg0" type="xsd:string" />
</message>
<message name="loadApple">
<part name="arg0" type="xsd:string" />
</message>
<portType name="AppleFinderService">
<operation name="getAppleArray">
<input message="tns:getAppleArray" />
<output message="tns:getAppleArrayResponse" />
</operation>
<operation name="loadApple">
<input message="tns:loadApple" />
<output message="tns:loadAppleResponse" />
</operation>
</portType>
<binding name="RpcBinding" type="tns:AppleFinderService">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="getAppleArray">
<soap:operation soapAction="" />
<input>
<soap:body use="literal" namespace="http://www.audaxys.com/namespaces/leasews" />
</input>
<output>
<soap:body use="literal" namespace="http://www.audaxys.com/namespaces/leasews" />
</output>
</operation>
<operation name="loadApple">
<soap:operation soapAction="" />
<input>
<soap:body use="literal" namespace="http://www.audaxys.com/namespaces/leasews" />
</input>
<output>
<soap:body use="literal" namespace="http://www.audaxys.com/namespaces/leasews" />
</output>
</operation>
</binding>
<service name="AppleFinderService">
<port name="Rpc" binding="tns:RpcBinding">
<soap:address location="http://10.10.5.25:8080/lease.services/soap/services/AppleFinderService.Rpc/" />
</port>
</service>
</definitions>
XSD
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.audaxys.com/namespaces/leasews" attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://www.audaxys.com/namespaces/leasews">
<xs:element name="apple" type="tns:apple" />
<xs:complexType name="apple">
<xs:sequence>
<xs:element minOccurs="0" name="appleType" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType final="#all" name="appleArray">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="item" nillable="true" type="tns:apple" />
</xs:sequence>
</xs:complexType>
</xs:schema>
Request
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<loadApple xmlns="http://www.audaxys.com/namespaces/leasews">
<arg0>Red</arg0>
</loadApple>
</soapenv:Body>
</soapenv:Envelope>
Responsse
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<rpcOp:loadAppleResponse xmlns:rpcOp="http://www.audaxys.com/namespaces/leasews">
<rpcOp:apple xmlns:ns3="http://com.audaxys.lease/" xmlns="">
<appleType>Red</appleType>
</rpcOp:apple>
</rpcOp:loadAppleResponse>
</soapenv:Body>
</soapenv:Envelope>
Your post is hard to read but I believe the problem is in the WSDL and XSD. You have an element, complexType and message part all with the same name "apple". I would try reworking the WSDL following the convention here:
<element name="Apple" type="tns:AppleType"/>
<complexType name="AppleType">
...
</complexType>
<message name="loadAppleResponse">
<part name="apple" element="tns:Apple"/>
</message>
I have faced the similiar kind of problem, I have annotated the EJB SLSB using JAX-WS API's and used RPC as the SOAP Bindind style.Deployed the EJB in JBoss5.1 and JBOSSWS generates the WSDL.
When I tested the Web Services by Axis1 client it worked fine, But while testing with Axis2 client, the request has sent to the server and even the DB transactions also was successfull.
But when the response came to the client, it says the Unexpected subelement return and so on. Then I changed the SOAP binding style it worked with Axis2.
#WebService
#SOAPBinding(style=Style.DOCUMENT, parameterStyle = ParameterStyle.WRAPPED)
public interface BillingAccountManagement_SEI { // TODO}