Im trying to call a Java web service created using Axis from PHP code.The webservice is hosted on my LAN. I am able to call the web service successfully using SoapUI. I have the PHP Soap Extension installed.
However,im not sure whether my PHP code is correct. Below is my PHP code.
<?php
$client = new SoapClient('http://machinename/axis/services/Compiere?wsdl');
$params = array('in0'=> '124','in1'=>'1');
$result = $client->__SoapCall('createOrder',array($params));
print $result->createOrderReturn;
?>
The WSDL is as follows :
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://compservice.com" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://compservice.com" xmlns:intf="http://compservice.com" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
<wsdl:message name="createOrderRequest">
<wsdl:part name="in0" type="xsd:int"/>
<wsdl:part name="in1" type="xsd:int"/>
</wsdl:message>
<wsdl:message name="createOrderResponse">
<wsdl:part name="createOrderReturn" type="xsd:string"/>
</wsdl:message>
<wsdl:portType name="OrderServiceInt">
<wsdl:operation name="createOrder" parameterOrder="in0 in1">
<wsdl:input message="impl:createOrderRequest" name="createOrderRequest"/>
<wsdl:output message="impl:createOrderResponse" name="createOrderResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="CompiereSoapBinding" type="impl:OrderServiceInt">
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="createOrder">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="createOrderRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://compservice.com" use="encoded"/>
</wsdl:input>
<wsdl:output name="createOrderResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://compservice.com" use="encoded"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="OrderServiceIntService">
<wsdl:port binding="impl:CompiereSoapBinding" name="Compiere">
<wsdlsoap:address location="http://nuca232/axis/services/Compiere"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Is my PHP code correct ?
Please help.
Thank You.
Why don't you try the direct mode?
<?php
$client = new SoapClient('http://machinename/axis/services/Compiere?wsdl');
$params = array('in0'=> '124','in1'=>'1');
$result = $client->createOrder( $parms );
print_r($result);
Instead of using $client->__SoapCall('createOrder',array($params));
As the manual says: "Usually, in WSDL mode, SOAP functions can be called as methods of the SoapClient object"
Related
I am trying to define a SOAP service that consumes OASIS WS-N notification messages.
I do 'WSDL-to-Java' approach but for some reason the incoming message is not being recognized.
Relevant fragments from WSDL:
<wsdl:definitions name="WSNBrokerNotification"
targetNamespace="http://docs.oasis-open.org/wsn/brw-2"
xmlns:tns="http://docs.oasis-open.org/wsn/brw-2"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsntw="http://docs.oasis-open.org/wsn/bw-2"
xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2"
xmlns:wsa="http://www.w3.org/2005/08/addressing"
xmlns:wsrf-rw="http://docs.oasis-open.org/wsrf/rw-2"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsn-br="http://docs.oasis-open.org/wsn/br-2"
xmlns:wstop="http://docs.oasis-open.org/wsn/t-1"
xmlns:wsn-brw="http://docs.oasis-open.org/wsn/brw-2">
...
<wsdl:message name="Notify">
<wsdl:part name="Notify" element="wsnt:Notify"/>
</wsdl:message>
...
<!-- ========= NotificationConsumer PortType Definition =========== -->
<wsdl:portType name="NotificationConsumer">
<wsdl:operation name="Notify">
<wsdl:input message="tns:Notify"/>
</wsdl:operation>
</wsdl:portType>
...
<!-- ========= NotificationConsumer PortType Definition =========== -->
<wsdl:portType name="NotificationConsumer">
<wsdl:operation name="Notify">
<wsdl:input message="tns:Notify"/>
</wsdl:operation>
</wsdl:portType>
...
<wsdl:binding name="NotificationConsumer" type="tns:NotificationConsumer">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="Notify">
<soap:operation soapAction="http://docs.oasis-open.org/wsn/bw-2/NotificationConsumer/Notify"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
</wsdl:operation>
</wsdl:binding>
...
<!-- =============== SERVICE ================= -->
<wsdl:service name="WSNBrokerNotification">
....
<wsdl:port name="NotificationConsumer" binding="tns:NotificationConsumer">
<soap:address location="http://localhost:19001"/>
</wsdl:port>
...
</wsdl:service>
</wsdl:definitions>
When the following SOAP message is arriving:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">http://docs.oasis-open.org/wsn/bw-2/NotificationConsumer/Notify</a:Action>
<a:To s:mustUnderstand="1">http://jenkins.nu.majiic:50918/spsconsumerTest_f4bcbd26-8e96-45fe-b622-563d0e4a8edf</a:To>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Notify xmlns="http://docs.oasis-open.org/wsn/b-2">
<NotificationMessage>
<MyLittleMessage/>
</NotificationMessage>
</Notify>
</s:Body>
</s:Envelope>
my SOAP framework - Apache CXF - reports this:
[qtp558404860-18] WARN org.apache.cxf.phase.PhaseInterceptorChain - Interceptor for {http://consumer.wsn.foo.bar/}WSBrokerNotificationConsumerService has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Message part {http://docs.oasis-open.org/wsn/b-2}Notify was not recognized. (Does it exist in service WSDL?)
at org.apache.cxf.wsdl.interceptors.DocLiteralInInterceptor.validatePart(DocLiteralInInterceptor.java:252)
at org.apache.cxf.wsdl.interceptors.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:191)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:267)
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:247)
at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:79)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1300)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:190)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1215)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:221)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
at org.eclipse.jetty.server.Server.handle(Server.java:500)
at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383)
at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:547)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:273)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806)
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938)
at java.lang.Thread.run(Thread.java:748)
[qtp558404860-18] INFO org.apache.cxf.services.WSBrokerNotificationConsumerService.WSBrokerNotificationConsumerPort.WSBrokerNotificationConsumer - Outbound Message
I am a bit confused, because I can clearly definition of <Notify> elements with proper namespace, unless I am missing something?...
Any help will be greatly appreciated!
solved; the issue was due to the lack of #WebService annotation on the class that was implementing the web service.
I'm trying to work with the Microsoft Exchange EWS protocol, for which Microsoft provide a WSDL file. I'm generate a JAX-WS client library from this using wsimport.
Unfortunately, Microsoft's WSDL file is faulty. One of the things it is getting wrong (apparently) is that all SOAP request parameters are defined as mandatory --- except they're not, they're optional, and in some situations I have to be able to not supply them.
Excerpt from the WSDL file:
<wsdl:operation name="GetUserAvailability">
<soap:operation soapAction="http://schemas.microsoft.com/exchange/services/2006/messages/GetUserAvailability" />
<wsdl:input>
<soap:header message="tns:GetUserAvailabilitySoapIn" part="Impersonation" use="literal"/>
<soap:header message="tns:GetUserAvailabilitySoapIn" part="TimeZoneContext" use="literal"/>
<soap:header message="tns:GetUserAvailabilitySoapIn" part="RequestVersion" use="literal"/>
<soap:body parts="GetUserAvailabilityRequest" use="literal" />
<soap:header message="tns:GetUserAvailabilitySoapIn" part="RequestVersion" use="literal"/>
</wsdl:input>
<wsdl:output>
...skipped...
</wsdl:output>
</wsdl:operation>
<wsdl:message name="GetUserAvailabilitySoapIn">
<wsdl:part name="GetUserAvailabilityRequest" element="tns:GetUserAvailabilityRequest" />
<wsdl:part name="Impersonation" element="t:ExchangeImpersonation"/>
<wsdl:part name="TimeZoneContext" element="t:TimeZoneContext" />
<wsdl:part name="RequestVersion" element="t:RequestServerVersion"/>
</wsdl:message>
<xs:element name="ExchangeImpersonation" type="t:ExchangeImpersonationType"/>
If I call this with, say, service.getUserAvailability(request, null, null, version), then I get an <ExchangeImpersonation xsl:nil="true"/> element in the header, and the Exchange server complains about having an extraneous element.
So, I want to edit the WSDL file to make these parameters properly optional. I've tried adding various combinations of wsdl:required=false and minOccurs=0 to various places according to the docs, but wsimport appears to be ignoring them completely --- the resulting code is unchanged.
How do I do this?
I'm trying to create a webservice using the New -> Web Service from WSDL in Netbeans 7.1.2.
I went ahead and created a WSDL using XML spy. Here is the basic WSDL that I've created:
<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://planningservice.ohs.com/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns="http://docs.oasis-open.org/wsn/t-1" xmlns:ns1="http://www.isotc211.org/2005/gco" xmlns:ns2="http://www.isotc211.org/2005/gmd" xmlns:ns3="http://www.isotc211.org/2005/gsr" xmlns:ns4="http://www.isotc211.org/2005/gss" xmlns:ns5="http://www.isotc211.org/2005/gts" xmlns:ns6="http://www.opengis.net/gml/3.2" xmlns:ns7="http://www.opengis.net/ows/1.1" xmlns:ns8="http://www.opengis.net/sps/2.0" xmlns:ns9="http://www.opengis.net/swe/2.0" xmlns:ns10="http://www.opengis.net/swes/2.0" xmlns:ns11="http://www.w3.org/2005/08/addressing" name="PlanningService" targetNamespace="http://planningservice.ohs.com/">
<wsdl:import namespace="http://www.opengis.net/sps/2.0" location="http://schemas.opengis.net/sps/2.0/spsGetFeasibility.xsd"/>
<wsdl:types>
<xsd:schema>
<xsd:import namespace="http://ps.ca"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="GetFeasibility">
<wsdl:part name="parameters" type="ns8:GetFeasibilityType"/>
</wsdl:message>
<wsdl:message name="GetFeasibilityResponse">
<wsdl:part name="parameters" type="ns8:GetFeasibilityResponseType"/>
</wsdl:message>
<wsdl:portType name="PlanningService">
<wsdl:operation name="GetFeasibility">
<wsdl:input message="tns:GetFeasibility" wsam:Action="http://planningservice.ohs.com/PlanningService/getFeasibility"/>
<wsdl:output message="tns:GetFeasibilityResponse" wsam:Action="http://planningservice.ohs.com/PlanningService/getFeasibilityResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="PlanningSerivcePortBinding" type="tns:PlanningService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetFeasibility">
<soap:operation soapAction="' '"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="PlanningSerivce">
<wsdl:port name="PlanningService" binding="tns:PlanningSerivcePortBinding">
<soap:address location="http://localhost:8080/PlanningService/"/>
</wsdl:port>
</wsdl:service>
When I try using the above I the 'New Web Service From WSDL' wizard says "There is no service in specified WSDL file."
If I don't specify the location attribute, like so:
<wsdl:service name="PlanningSerivce">
<wsdl:port name="PlanningService" binding="tns:PlanningSerivcePortBinding">
<soap:address/>
</wsdl:port>
</wsdl:service>
I don't have that notification but during the creation of the Web Service I get an error that says the attribute is missing.
So my question is what do I put in the location attribute to get Netbeans to recognize that there is a service defined, given that it isn't deployed anywhere!
Thanks all!
~D
The WSDL document as provided is not entirely valid.
The first issue is the declaration of the document style but the message declaration in the rpc style. Rpc uses message parts defined in terms of 'type's. Document uses message parts defined in terms of 'element's. I looked over the XSD imported into the WSDL and found the 'GetFeasibility' and 'GetFeasibilityResponse' elements defined there. So, changing the wsdl:message nodes to
<wsdl:message name="GetFeasibility">
<wsdl:part name="parameters" element="ns8:GetFeasibility"/>
</wsdl:message>
<wsdl:message name="GetFeasibilityResponse">
<wsdl:part name="parameters" element="ns8:GetFeasibilityResponse"/>
</wsdl:message>
helps by making the message definitions consistent with the document style service.
There is a nice writeup at http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/ about wsdl construction w.r.t. declared styles.
The next issue is the schema import. There are special restrictions around the wsdl:import statement. In general, the proper place to pull in schemas is the wsdl:types section. If you use something like
<wsdl:types>
<xsd:schema>
<xsd:import namespace="http://www.opengis.net/sps/2.0"
schemaLocation="http://schemas.opengis.net/sps/2.0/spsGetFeasibility.xsd"/>
<xsd:import namespace="http://ps.ca"/>
</xsd:schema>
</wsdl:types>
(not sure of the value of the ps.ca import), the relevant types are available for the wsdl import machinery. A writeup of wsdl importing is at http://scn.sap.com/people/kevin.liu/blog/2004/06/28/a-note-on-wsdl-and-xsd-imports
Once these modifications were made, wsimport still saw an error in the form of a name collision in the supporting schemas at opengis.net, but hopefully this gives you enough to move our project along a bit and you can focus on the name collision rather than fighting the wsdl construction.
I generate my web service from WSDL file. But I need t o define in this file that my methods in SkeletonInterface thow Axis Fault Exception.
Smth like:
void method() throws AxisFault{....}
In which way I can do this (in WSDL).
Thanks.
In short, it's bad practice to reuse AxisFault for your own application faults. When I see AxisFault, it signals that something internal to the Axis autogen code failed. This could include your exception wrapped inside of it.
First, I want to address your pseudcode.
void method() throws AxisFault{....}
This pseudocode indicates that you want a method with no input, no output, but still have an exception. If I assume this, then that design is not recommended (I'm not even sure if it is possible). If you want something to trigger something to happen with no output, an empty output message is preferable to an exception. Exceptions should only be used when something uncommon happens.
If you meant the above code as an abstract example and you do have input/output, then the correct approach would be to make up your own fault. Using your own fault allows you to control behavior and more accurately describe what is failing. You may also need several faults in the future so using AxisFault is not beneficial in that case.
<wsdl:definitions ...>
...
<wsdl:message name="MyFault">
<wsdl:part name="parameters" element="def:MyFault">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="MyPortType">
<wsdl:operation name="doStuff">
<wsdl:input message="tns:MyRequest">
</wsdl:input>
<wsdl:output message="tns:MyResponse">
</wsdl:output>
<wsdl:fault name="MyFault" message="tns:MyFault">
</wsdl:fault>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="MyBinding" type="tns:MyPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="doStuff">
<soap:operation soapAction="namespace/operationName"/>
<wsdl:input name="MyRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="MyResponse">
<soap:body use="literal"/>
</wsdl:output>
<wsdl:fault name="MyFault">
<soap:body use="literal"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
...
</wsdl:definitions>
That said, AxisFault does happen for web service operation calls. For your client stub code, it should throw a RemoteException. If you take a look at your autogen Stub code, you should see that does in fact throw an AxisFault which extends RemoteException.
using the faults
<definitions ...>
<message name="empty"/>
<message name="InsufficientFundsFault">
<part name="balance" type="xsd:int"/>
</message>
<portType name="Bank">
<operation name="throwException">
<input message="tns:empty"/>
<output message="tns:empty"/>
<fault name="fault" message="tns:InsufficientFundFault"/>
</operation>
</portType>
...
</definitions>
I am trying to run the wsdl2java command on a WSDL file that was given to me from another group in my company. I know wsdl2java works because I can run the examples but when I try it on the wsdl given to me it fails. The one big difference is that the WSDL given to me uses SSL.
I’m using Java 1.4 (checked it a few time) and made sure all the correct jars are in my class path, jsse.jar is there.
COMMAND: java org.apache.axis.wsdl.WSDL2Java --server-side GenericWebService.wsdl
ERROR:
log4j:WARN No appenders could be found for logger (org.apache.axis.i18n.ProjectResourceBundle).
log4j:WARN Please initialize the log4j system properly.
**java.io.IOException: Emitter failure. Invalid endpoint address in port AC_x0020_Generic_x0020_Web_0020_ServiceSoap in service AC_x0020_Generic_x0020_Web_x0020_ServiceLocator: **
at org.apache.axis.wsdl.toJava.JavaServiceImplWriter.writeFileBody(JavaServiceImplWriter.ja
a:242)
at org.apache.axis.wsdl.toJava.JavaWriter.generate(JavaWriter.java:127)
at org.apache.axis.wsdl.toJava.JavaServiceWriter.generate(JavaServiceWriter.java:112)
at org.apache.axis.wsdl.toJava.JavaGeneratorFactory$Writers.generate(JavaGeneratorFactory.j
va:421)
at org.apache.axis.wsdl.gen.Parser.generate(Parser.java:476)
at org.apache.axis.wsdl.gen.Parser.access$000(Parser.java:45)
at org.apache.axis.wsdl.gen.Parser$WSDLRunnable.run(Parser.java:362)
at java.lang.Thread.run(Thread.java:534)
asdf
<wsdl:portType name="AC_x0020_Generic_x0020_Web_x0020_ServiceSoap">
<wsdl:operation name="Provision">
<wsdl:input message="tns:ProvisionSoapIn" />
<wsdl:output message="tns:ProvisionSoapOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="AC_x0020_Generic_x0020_Web_x0020_ServiceSoap" type="tns:AC_x0020_Generic_x0020_Web_x0020_ServiceSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="Provision">
<soap:operation soapAction="http://xmlns.fmr.com/systems/dev/aar/2008/05/GenericWebService/Provision" style="document" />
<wsdl:input>
<soap:body use="literal" />
<soap:header message="tns:ProvisionServiceProcessingDirectives" part="ServiceProcessingDirectives" use="literal" />
<soap:header message="tns:ProvisionServiceCallContext" part="ServiceCallContext" use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="AC_x0020_Generic_x0020_Web_x0020_Service">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Generic web service definition for provisioning requests callable by AccessCENTRAL</wsdl:documentation>
<wsdl:port name="AC_x0020_Generic_x0020_Web_x0020_ServiceSoap" binding="tns:AC_x0020_Generic_x0020_Web_x0020_ServiceSoap">
<soap:address location="" />
</wsdl:port>
</wsdl:service>
UPDATED SOLUTION:
The problem was that the parser needed a value in the <soap:address location="" /> for it to complete. I added the URL of my service and it worked.
New Lines looked like:
<soap:address location="" http://localhost:8080/axis/services/AC_x0020_Generic_x0020_Web_x0020_Service" />
The location specified by the soap:address is blank. It should be the URI of the SOAP service. See soap:address.
Looking at soapAction, http://xmlns.fmr.com/systems/dev/aar/2008/05/GenericWebService might be the correct value for location.