Link to home
Start Free TrialLog in
Avatar of Farzad Akbarnejad
Farzad AkbarnejadFlag for Iran, Islamic Republic of

asked on

WSDL and Java

Hello,
I have a WSDL file for web service. I need a sample java code to call the method in web service.
How can I use it?

Thanks
-FA
Avatar of ysnky
ysnky
Flag of Türkiye image

you can use wsdl2java tool to create needed classes so you can call the webservice
ASKER CERTIFIED SOLUTION
Avatar of ysnky
ysnky
Flag of Türkiye image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Farzad Akbarnejad

ASKER

Hello,
I have four class created using wsdl2java  tool:

EShopService
EShopServiceLocator
EShopServiceSoap
EShopServiceSoapStub

I don't know how to call my service method from these classes. Would you please get me a sample code using above classes?

Thanks
-FA
if you send your webservice url, i can help you with source code.
it looks like this;
		// Make a service
		EShopService service = new EShopServiceLocator();
 
		// Now use the service to get a stub to the service
		try {
			
			EShop_PortType call = service.getEShopPort();			
			XXX result = call.YYY(...);
						
		} catch (Exception e) {
			e.printStackTrace();
		} 		

Open in new window

Hi,
Here is my wsdl file.
Would you please send me the exact code.

Thanks
-FA



<?xml version="1.0" encoding="utf-8"?>
<definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:s0="http://tempuri.org/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" targetNamespace="http://tempuri.org/" xmlns="http://schemas.xmlsoap.org/wsdl/">
  <types>
    <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
      <s:element name="PinPaymentRequest">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="pin" type="s:string" />
            <s:element minOccurs="1" maxOccurs="1" name="amount" type="s:int" />
            <s:element minOccurs="1" maxOccurs="1" name="orderId" type="s:int" />
            <s:element minOccurs="0" maxOccurs="1" name="callbackUrl" type="s:string" />
            <s:element minOccurs="1" maxOccurs="1" name="authority" type="s:long" />
            <s:element minOccurs="1" maxOccurs="1" name="status" type="s:unsignedByte" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="PinPaymentRequestResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="authority" type="s:long" />
            <s:element minOccurs="1" maxOccurs="1" name="status" type="s:unsignedByte" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="PinPaymentEnquiry">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="pin" type="s:string" />
            <s:element minOccurs="1" maxOccurs="1" name="authority" type="s:long" />
            <s:element minOccurs="1" maxOccurs="1" name="status" type="s:unsignedByte" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="PinPaymentEnquiryResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="status" type="s:unsignedByte" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="PinVoidPayment">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="pin" type="s:string" />
            <s:element minOccurs="1" maxOccurs="1" name="orderId" type="s:int" />
            <s:element minOccurs="1" maxOccurs="1" name="orderToVoid" type="s:int" />
            <s:element minOccurs="1" maxOccurs="1" name="status" type="s:unsignedByte" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="PinVoidPaymentResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="status" type="s:unsignedByte" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="PinRefundPayment">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="pin" type="s:string" />
            <s:element minOccurs="1" maxOccurs="1" name="orderId" type="s:int" />
            <s:element minOccurs="1" maxOccurs="1" name="orderToRefund" type="s:int" />
            <s:element minOccurs="1" maxOccurs="1" name="amount" type="s:int" />
            <s:element minOccurs="1" maxOccurs="1" name="status" type="s:unsignedByte" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="PinRefundPaymentResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="status" type="s:unsignedByte" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="PinReversal">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="pin" type="s:string" />
            <s:element minOccurs="1" maxOccurs="1" name="orderId" type="s:int" />
            <s:element minOccurs="1" maxOccurs="1" name="orderToReversal" type="s:int" />
            <s:element minOccurs="1" maxOccurs="1" name="status" type="s:unsignedByte" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="PinReversalResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="status" type="s:unsignedByte" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="PinSetDefaultCallbackUrl">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="pin" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="url" type="s:string" />
            <s:element minOccurs="1" maxOccurs="1" name="status" type="s:unsignedByte" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="PinSetDefaultCallbackUrlResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="status" type="s:unsignedByte" />
          </s:sequence>
        </s:complexType>
      </s:element>
    </s:schema>
  </types>
  <message name="PinPaymentRequestSoapIn">
    <part name="parameters" element="s0:PinPaymentRequest" />
  </message>
  <message name="PinPaymentRequestSoapOut">
    <part name="parameters" element="s0:PinPaymentRequestResponse" />
  </message>
  <message name="PinPaymentEnquirySoapIn">
    <part name="parameters" element="s0:PinPaymentEnquiry" />
  </message>
  <message name="PinPaymentEnquirySoapOut">
    <part name="parameters" element="s0:PinPaymentEnquiryResponse" />
  </message>
  <message name="PinVoidPaymentSoapIn">
    <part name="parameters" element="s0:PinVoidPayment" />
  </message>
  <message name="PinVoidPaymentSoapOut">
    <part name="parameters" element="s0:PinVoidPaymentResponse" />
  </message>
  <message name="PinRefundPaymentSoapIn">
    <part name="parameters" element="s0:PinRefundPayment" />
  </message>
  <message name="PinRefundPaymentSoapOut">
    <part name="parameters" element="s0:PinRefundPaymentResponse" />
  </message>
  <message name="PinReversalSoapIn">
    <part name="parameters" element="s0:PinReversal" />
  </message>
  <message name="PinReversalSoapOut">
    <part name="parameters" element="s0:PinReversalResponse" />
  </message>
  <message name="PinSetDefaultCallbackUrlSoapIn">
    <part name="parameters" element="s0:PinSetDefaultCallbackUrl" />
  </message>
  <message name="PinSetDefaultCallbackUrlSoapOut">
    <part name="parameters" element="s0:PinSetDefaultCallbackUrlResponse" />
  </message>
  <portType name="EShopServiceSoap">
    <operation name="PinPaymentRequest">
      <input message="s0:PinPaymentRequestSoapIn" />
      <output message="s0:PinPaymentRequestSoapOut" />
    </operation>
    <operation name="PinPaymentEnquiry">
      <input message="s0:PinPaymentEnquirySoapIn" />
      <output message="s0:PinPaymentEnquirySoapOut" />
    </operation>
    <operation name="PinVoidPayment">
      <input message="s0:PinVoidPaymentSoapIn" />
      <output message="s0:PinVoidPaymentSoapOut" />
    </operation>
    <operation name="PinRefundPayment">
      <input message="s0:PinRefundPaymentSoapIn" />
      <output message="s0:PinRefundPaymentSoapOut" />
    </operation>
    <operation name="PinReversal">
      <input message="s0:PinReversalSoapIn" />
      <output message="s0:PinReversalSoapOut" />
    </operation>
    <operation name="PinSetDefaultCallbackUrl">
      <input message="s0:PinSetDefaultCallbackUrlSoapIn" />
      <output message="s0:PinSetDefaultCallbackUrlSoapOut" />
    </operation>
  </portType>
  <binding name="EShopServiceSoap" type="s0:EShopServiceSoap">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
    <operation name="PinPaymentRequest">
      <soap:operation soapAction="http://tempuri.org/PinPaymentRequest" style="document" />
      <input>
        <soap:body use="literal" />
      </input>
      <output>
        <soap:body use="literal" />
      </output>
    </operation>
    <operation name="PinPaymentEnquiry">
      <soap:operation soapAction="http://tempuri.org/PinPaymentEnquiry" style="document" />
      <input>
        <soap:body use="literal" />
      </input>
      <output>
        <soap:body use="literal" />
      </output>
    </operation>
    <operation name="PinVoidPayment">
      <soap:operation soapAction="http://tempuri.org/PinVoidPayment" style="document" />
      <input>
        <soap:body use="literal" />
      </input>
      <output>
        <soap:body use="literal" />
      </output>
    </operation>
    <operation name="PinRefundPayment">
      <soap:operation soapAction="http://tempuri.org/PinRefundPayment" style="document" />
      <input>
        <soap:body use="literal" />
      </input>
      <output>
        <soap:body use="literal" />
      </output>
    </operation>
    <operation name="PinReversal">
      <soap:operation soapAction="http://tempuri.org/PinReversal" style="document" />
      <input>
        <soap:body use="literal" />
      </input>
      <output>
        <soap:body use="literal" />
      </output>
    </operation>
    <operation name="PinSetDefaultCallbackUrl">
      <soap:operation soapAction="http://tempuri.org/PinSetDefaultCallbackUrl" style="document" />
      <input>
        <soap:body use="literal" />
      </input>
      <output>
        <soap:body use="literal" />
      </output>
    </operation>
  </binding>
  <service name="EShopService">
    <port name="EShopServiceSoap" binding="s0:EShopServiceSoap">
      <soap:address location="https://www.pec24.com/pecpaymentgateway/EShopService.asmx" />
    </port>
  </service>
</definitions>

Open in new window

there is problem with wsdl with setOmittable method.

code looks like this;
		// Make a service
		EShopService service = new EShopServiceLocator();
 
		// Now use the service to get a stub to the service
		try {
			
			EShopServiceSoap_PortType call = service.getEShopServiceSoap();
			call.pinPaymentEnquiry(null, 0, null); // any method with your params
			
			System.out.println("service called...");
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 		

Open in new window

Hello,
Thanks. I generate stub classes and want to invoke PinPaymentRequest function with proper parameters but I got the following exception. Do you have any idea?


AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Client
 faultSubcode:
 faultString: System.Web.Services.Protocols.SoapException: Server was unable to read request. ---&gt; System.InvalidOperationException: There is an error in XML document (9, 28). ---&gt; System.FormatException: Input string was not in a correct format.
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at System.Byte.Parse(String s, NumberStyles style, IFormatProvider provider)
   at System.Xml.XmlConvert.ToByte(String s)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read2_PinPaymentRequest()
   at Microsoft.Xml.Serialization.GeneratedAssembly.PinPaymentRequestSerializer.Deserialize(XmlSerializationReader reader)
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
   --- End of inner exception stack trace ---
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, XmlDeserializationEvents events)
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader)
   at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
   --- End of inner exception stack trace ---
   at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
   at System.Web.Services.Protocols.WebServiceHandler.Invoke()
   at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
 faultActor:
 faultNode:
 faultDetail:
      {http://xml.apache.org/axis/}stackTrace:System.Web.Services.Protocols.SoapException: Server was unable to read request. ---&gt; System.InvalidOperationException: There is an error in XML document (9, 28). ---&gt; System.FormatException: Input string was not in a correct format.
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at System.Byte.Parse(String s, NumberStyles style, IFormatProvider provider)
   at System.Xml.XmlConvert.ToByte(String s)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read2_PinPaymentRequest()
   at Microsoft.Xml.Serialization.GeneratedAssembly.PinPaymentRequestSerializer.Deserialize(XmlSerializationReader reader)
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
   --- End of inner exception stack trace ---
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, XmlDeserializationEvents events)
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader)
   at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
   --- End of inner exception stack trace ---
   at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
   at System.Web.Services.Protocols.WebServiceHandler.Invoke()
   at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
      at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
      at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
      at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
      at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
      at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
      at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
      at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
      at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
      at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
      at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
      at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
      at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
      at javax.xml.parsers.SAXParser.parse(Unknown Source)
      at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
      at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
      at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
      at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
      at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
      at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
      at org.apache.axis.client.Call.invoke(Call.java:2767)
      at org.apache.axis.client.Call.invoke(Call.java:2443)
      at org.apache.axis.client.Call.invoke(Call.java:2366)
      at org.apache.axis.client.Call.invoke(Call.java:1812)
      at org.tempuri.EShopServiceSoapStub.pinPaymentRequest(EShopServiceSoapStub.java:195)
      at com.liferay.portlet.shopping.util.ShoppingParsian.PinPaymentRequest(ShoppingParsian.java:28)
      at com.liferay.portlet.shopping.action.CheckoutAction.forwardCheckout(CheckoutAction.java:208)
      at com.liferay.portlet.shopping.action.CheckoutAction.processAction(CheckoutAction.java:99)
      at com.liferay.portal.struts.PortletRequestProcessor.process(PortletRequestProcessor.java:172)
      at com.liferay.portlet.StrutsPortlet.processAction(StrutsPortlet.java:95)
      at com.liferay.portlet.CachePortlet._invoke(CachePortlet.java:357)
      at com.liferay.portlet.CachePortlet.processAction(CachePortlet.java:157)
      at com.liferay.portal.action.LayoutAction._processPortletRequest(LayoutAction.java:269)
      at com.liferay.portal.action.LayoutAction._processActionRequest(LayoutAction.java:290)
      at com.liferay.portal.action.LayoutAction.execute(LayoutAction.java:113)
      at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
      at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
      at com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:156)
      at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
      at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
      at com.liferay.portal.servlet.MainServlet.callParentService(MainServlet.java:479)
      at com.liferay.portal.servlet.MainServlet.service(MainServlet.java:877)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at com.liferay.filters.secure.SecureFilter.doFilter(SecureFilter.java:143)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter.doFilter(VirtualHostFilter.java:169)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
      at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
      at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
      at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
      at com.liferay.portal.servlet.FriendlyURLServlet.service(FriendlyURLServlet.java:126)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at com.liferay.filters.strip.StripFilter.doFilter(StripFilter.java:94)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at com.liferay.filters.secure.SecureFilter.doFilter(SecureFilter.java:143)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at com.liferay.filters.compression.CompressionFilter.doFilter(CompressionFilter.java:115)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at com.liferay.portal.servlet.filters.layoutcache.LayoutCacheFilter.doFilter(LayoutCacheFilter.java:197)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at com.liferay.portal.servlet.filters.autologin.AutoLoginFilter.doFilter(AutoLoginFilter.java:117)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter.doFilter(VirtualHostFilter.java:169)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
      at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
      at java.lang.Thread.run(Thread.java:595)
Hello,
Thanks and sorry for delay in accepting solution.

-FA