WCF returns empty objects, although I can see from a fiddler trace that data is being returned. I am sure it is namespace issue, but after reading all the docs I can't see what is wrong! Request and response SOAP below:
Request:
POST https://x.x.x.x:9001/soap/ HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 4.0.30319.34209)
VsDebuggerCausalityData: uIDPo0Xy/aB8aeVEhMD2Z4yiT1MAAAAAKokUeOFUmEaRRFeDK7Ihn37dui0ez7tEhWItLBqEHq0ACQAA
Content-Type: text/xml; charset=utf-8
SOAPAction: "get_wsdl_version"
Host: x.x.x.x:9001
Content-Length: 236
Expect: 100-continue
Connection: Keep-Alive
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body />
</soap:Envelope>
Response:
HTTP/1.1 200 OK
Date: Thu, 05 Feb 2015 10:10:18 GMT
Server: Apache
Vary: Accept-Encoding,User-Agent
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/xml
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<get_wsdl_versionResponse>
<get_wsdl_versionResult xsi:type="xs:int">2002</get_wsdl_versionResult>
</get_wsdl_versionResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Edit: adding (very simple) client code
Dim TestClient = New ServiceReference1.TableLampServiceClient
Dim Creds = New ServiceReference1.AuthInfo()
Creds.username = "xxx"
Creds.password = "yyy"
Dim TestVersion = TestClient.get_wsdl_version()
Edit: adding WDSL snippet - pulled from VS
<?xml version="1.0" encoding="utf-8"?>
<definitions xmlns:tns="cust_service.TableLampService" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-link/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:typens="cust_service.TableLampService" name="TableLampService" targetNamespace="cust_service.TableLampService" xmlns="http://schemas.xmlsoap.org/wsdl/">
<plnk:partnerLinkType name="TableLampService">
<plnk:role name="TableLampService">
<plnk:portType name="tns:TableLampService" />
</plnk:role>
</plnk:partnerLinkType>
<types>
<xs:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="cust_service.TableLampService">
<xs:element name="get_wsdl_versionResponse" type="typens:get_wsdl_versionResponse" />
<xs:complexType name="get_wsdl_versionResponse">
<xs:sequence>
<xs:element name="get_wsdl_versionResult" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:schema>
</types>
<message name="get_wsdl_version" />
<message name="get_wsdl_versionResponse">
<part name="get_wsdl_versionResponse" element="typens:get_wsdl_versionResponse" />
</message>
<portType name="TableLampService">
<operation name="get_wsdl_version" parameterOrder="get_wsdl_version">
<documentation>
get_wsdl_version() -> int
Return the SOAP server's WSDL version. This is used to check
client/server compatibility.
Parameters: None
Exceptions: None
</documentation>
<input name="get_wsdl_version" message="typens:get_wsdl_version" />
<output name="get_wsdl_versionResponse" message="typens:get_wsdl_versionResponse" />
</operation>
</portType>
<binding name="TableLampService" type="typens:TableLampService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="get_wsdl_version">
<soap:operation soapAction="get_wsdl_version" style="document" />
<input name="get_wsdl_version">
<soap:body use="literal" />
</input>
<output name="get_wsdl_versionResponse">
<soap:body use="literal" />
</output>
</operation>
</binding>
</definitions>
It may be worth mentioning that I have no control over the server-side. I just need to consume the service in my code however I can.
Thanks in advance!
Related
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!
I am trying to run a apache axis2 webservice client and Im getting thrown an exeption like given below
org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement {http://schemas.xmlsoap.org/soap/envelope/}Body
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
Here is the wsdl for the webservice
<?xml version="1.0" encoding="UTF-8"?>
-
<wsdl:definitions targetNamespace="http://wtp"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
xmlns:ns="http://wtp" xmlns:ns1="http://org.apache.axis2/xsd"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:documentation> Please Type your service description here
</wsdl:documentation>
-
<wsdl:types>
-
<xs:schema targetNamespace="http://wtp" elementFormDefault="qualified"
attributeFormDefault="qualified">
-
<xs:element name="authenticate">
-
<xs:complexType>
-
<xs:sequence>
<xs:element name="loginname" type="xs:string" nillable="true"
minOccurs="0" />
<xs:element name="password" type="xs:string" nillable="true"
minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
-
<xs:element name="authenticateResponse">
-
<xs:complexType>
-
<xs:sequence>
<xs:element name="return" type="xs:int" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
-
<wsdl:message name="authenticateRequest">
<wsdl:part name="parameters" element="ns:authenticate" />
</wsdl:message>
-
<wsdl:message name="authenticateResponse">
<wsdl:part name="parameters" element="ns:authenticateResponse" />
</wsdl:message>
-
<wsdl:portType name="LoginPortType">
-
<wsdlperation name="authenticate">
<wsdl:input wsaw:Action="urn:authenticate" message="ns:authenticateRequest" />
<wsdlutput wsaw:Action="urn:authenticateResponse"
message="ns:authenticateResponse" />
</wsdlperation>
</wsdl:portType>
-
<wsdl:binding name="LoginSoap11Binding" type="ns:LoginPortType">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
-
<wsdlperation name="authenticate">
<soapperation style="document" soapAction="urn:authenticate" />
-
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
-
<wsdlutput>
<soap:body use="literal" />
</wsdlutput>
</wsdlperation>
</wsdl:binding>
-
<wsdl:binding name="LoginSoap12Binding" type="ns:LoginPortType">
<soap12:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
-
<wsdlperation name="authenticate">
<soap12peration style="document" soapAction="urn:authenticate" />
-
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
-
<wsdlutput>
<soap12:body use="literal" />
</wsdlutput>
</wsdlperation>
</wsdl:binding>
-
<wsdl:binding name="LoginHttpBinding" type="ns:LoginPortType">
<http:binding verb="POST" />
-
<wsdlperation name="authenticate">
<httpperation location="authenticate" />
-
<wsdl:input>
<mime:content type="text/xml" part="parameters" />
</wsdl:input>
-
<wsdlutput>
<mime:content type="text/xml" part="parameters" />
</wsdlutput>
</wsdlperation>
</wsdl:binding>
-
<wsdl:service name="Login">
-
<wsdl:port name="LoginHttpSoap11Endpoint" binding="ns:LoginSoap11Binding">
<soap:address
location="http://localhost:8080/Navigato/services/Login.LoginHttpSoap11Endpoint/" />
</wsdl:port>
-
<wsdl:port name="LoginHttpSoap12Endpoint" binding="ns:LoginSoap12Binding">
<soap12:address
location="http://localhost:8080/Navigato/services/Login.LoginHttpSoap12Endpoint/" />
</wsdl:port>
-
<wsdl:port name="LoginHttpEndpoint" binding="ns:LoginHttpBinding">
<http:address
location="http://localhost:8080/Navigato/services/Login.LoginHttpEndpoint/" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Following are the soap request and response packets from soap ui
SOAP REQUEST
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns1:authenticate xmlns:ns1="http://wtp">
<ns1:loginname>john</ns1:loginname>
<ns1:password>123</ns1:password>
</ns1:authenticate>
</soapenv:Body>
</soapenv:Envelope>
SOAP RESPONSE
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns:authenticateResponse xmlns:ns="http://wtp">
<ns:return>1</ns:return>
</ns:authenticateResponse>
</soapenv:Body>
</soapenv:Envelope>
But by the time the response is reaching the client stub, stub receives it
as follows
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<soapenv:Envelope>
<soapenv:Body>
<ns:authenticateResponse xmlns:ns="http://wtp">
<ns:return>1</ns:return>
</ns:authenticateResponse>
</soapenv:Body>
</soapenv:Envelope>
</soapenv:Body>
</soapenv:Envelope>
Here the Soap and Body are encapsulated twice
As a result of this, client stub is unable to parse and throwing the
following error.
org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement {http://schemas.xmlsoap.org/soap/envelope/}Body
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
Client Code
public class LoginClient
{
public static void main(String args[])
{
try {
LoginStub stub = new LoginStub();
Authenticate auth = new Authenticate();
auth.setLoginname("john");
auth.setPassword("123");
AuthenticateResponse res = stub.authenticate(auth);
System.out.println(res.get_return());
} catch (AxisFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
How is your client code is written?..Have you set the content-type of the messagecorrectly..
At some point, axis2 thinks the message is not a soap message and wraps again with a soap envelope..
When you receive the response in axis2 check the content-type of it..it should be text/xml
I'm trying to connect with an external Java Web service with WS-Security enabled over https with a WCF client.
The service use UserNameToken authentication.
When the client call the service, I get this exception:
Cannot find a token authenticator for the 'System.IdentityModel.Tokens.X509SecurityToken' token type. Tokens of that type cannot be accepted according to current security settings.
I use a custom binding with this configuration:
The endpoint:
<endpoint address="https://des-afirma.redsara.es/afirmaws/services/ValidarFirma"
binding="customBinding" bindingConfiguration="ValidarFirmaBinding"
contract="AFirma.Firma" name="ValidarFirma" />
</endpoint>
The binding:
<binding name="ValidarFirmaBinding">
<textMessageEncoding messageVersion="Soap11" />
<security
allowSerializedSigningTokenOnReply="true"
authenticationMode="UserNameOverTransport">
<secureConversationBootstrap />
</security>
<httpsTransport>
<extendedProtectionPolicy policyEnforcement="Never" />
</httpsTransport>
</binding>
I read this link http://webservices20.blogspot.co.uk/2010/10/wcf-cannot-find-token-authenticator.html and I configured the allowSerializedSigningTokenOnReply value, but it failed.
This is the message generated by WCF:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<soap:Header>
<wsa:Action />
<wsa:MessageID>urn:uuid:5b36bb8b-4a59-4c5f-9c67-065543db51d5</wsa:MessageID>
<wsa:ReplyTo>
<wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>
</wsa:ReplyTo>
<wsa:To>http://des-afirma.redsara.es/afirmaws/services/ValidarFirma</wsa:To>
<wsse:Security soap:mustUnderstand="1">
<wsu:Timestamp wsu:Id="Timestamp-cef53b94-4432-4ede-89ea-7a42b7a686d2">
<wsu:Created>2012-11-13T13:49:32Z</wsu:Created>
<wsu:Expires>2012-11-13T13:54:32Z</wsu:Expires>
</wsu:Timestamp>
<wsse:UsernameToken wsu:Id="SecurityToken-40deaa3d-fe02-4462-963e-7705e4648b24">
<wsse:Username>UserName</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">[Password]</wsse:Password>
<wsse:Nonce>G5CU1R6lKSTpBQ0FAF01rA==</wsse:Nonce>
<wsu:Created>2012-11-13T13:49:32Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
<soap:Body>
<ValidarFirma xmlns="http://afirmaws/services/ValidarFirma">
<paramIn xmlns="">[Param value (XML String)]</paramIn>
</ValidarFirma>
</soap:Body>
</soap:Envelope>
And this is the response:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<wsse:Security soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0">
<wsse:BinarySecurityToken EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" wsu:Id="binaryToken">
MIIG2TCCBcGgAwIBAgIISXHqSo0f+C0wDQYJKoZIhvcNAQEFBQAwUjERMA8GA1UEAxMIQUNDVi1D
[...]
</wsse:BinarySecurityToken>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#" Id="Signature-BDFADICIJJIDI81">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments" />
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<Reference URI="#SignedBody-BDFADICIJJIDI81">
<Transforms>
<Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#WithComments" />
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<DigestValue>TFKLyv9zd1G7RXK4sJV+hG2WfqQ=</DigestValue>
</Reference>
<Reference URI="#keyInfo-BDFADICIJJIDI81">
<Transforms>
<Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments" />
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<DigestValue>SWO3sIcC16EcT17pBREoGe3CVes=</DigestValue>
</Reference>
<Reference URI="#binaryToken">
<Transforms>
<Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#WithComments" />
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<DigestValue>GT+8/UoUzQgUAhvc25bn+DL6T1E=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue Id="SignatureValue-BDFADICIJJIDI81">
sTVgtvYlVuwhQ9XGcTfHh7lKdUcsf8vF6vyJ/5LVxuwarRDAjMzHcQlvFBlZTn8f
[..]
</SignatureValue>
<KeyInfo Id="keyInfo-BDFADICIJJIDI81">
<KeyValue>
<RSAKeyValue>
<Modulus>
tCxb/yk9DgCJmdxshvm6RwQtRMHqTdI2nDzQ2C761KEGmAaz7jrv8PtVSoNMRVr9
[...]
</Modulus>
<Exponent>AQAB</Exponent>
</RSAKeyValue>
</KeyValue>
<X509Data>
<X509Certificate>
MIIG2TCCBcGgAwIBAgIISXHqSo0f+C0wDQYJKoZIhvcNAQEFBQAwUjERMA8GA1UE
[...]
</X509Certificate>
<X509IssuerSerial>
<X509IssuerName>Certificate name</X509IssuerName>
<X509SerialNumber>Serial number</X509SerialNumber>
</X509IssuerSerial>
</X509Data>
<wsse:SecurityTokenReference xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:Reference URI="#binaryToken" />
</wsse:SecurityTokenReference>
</KeyInfo>
</Signature>
</wsse:Security>
</soapenv:Header>
<soapenv:Body wsu:Id="SignedBody-BDFADICIJJIDI81">
<ValidarFirmaResponse xmlns="http://afirmaws/services/ValidarFirma">
<ValidarFirmaReturn xmlns="" xsi:type="c0bxsd:string">
[return value (XML String)]
</ValidarFirmaReturn>
</ValidarFirmaResponse>
</soapenv:Body>
</soapenv:Envelope>
I tried the web service with WSE 3.0 and it works, but I can't install the package in the server because it is Windows Server 2008 and the installation failed.
Try to play with MessageSecurityVersion (for example
WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11) and security tag. And look at soap envelop.
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/*
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}