2 Replies Latest reply: Sep 11, 2009 5:54 AM by 800479 RSS

    Consume Web Services in Java

    801466
      Hello,

      Is there a way that Java can consume Web services?I found this link that says that it is possible.
      http://www.codeproject.com/KB/java/edujini_webservice_java.aspx

      But when i was trying to type in the code
      wsimport –p com.srav.webservices –s src –d bin http://localhost/xxxxxx.wsdl?wsdl

      It gave me an error saying there is no src and bin folder and so I created one in "My Documents" because thats where my JAX WS folder is been extracted.Once I issue the command again in the prompt I am getting errors as follows:

      C:\Documents and Settings\syendluri>wsimport -p com.sravanthi.webservices -s src
      -d bin http://10.1.250.20/ttsoapcgi.wsdl?WSDL
      parsing WSDL...


      [WARNING] src-resolve.4.2: Error resolving component 'SOAP-ENC:Array'. It was de
      tected that 'SOAP-ENC:Array' is in namespace 'http://schemas.xmlsoap.org/soap/en
      coding/', but components from this namespace are not referenceable from schema d
      ocument 'http://10.1.250.20/ttsoapcgi.wsdl?WSDL#types?schema1'. If this is the i
      ncorrect namespace, perhaps the prefix of 'SOAP-ENC:Array' needs to be changed.
      If this is the correct namespace, then an appropriate 'import' tag should be add
      ed to 'http://10.1.250.20/ttsoapcgi.wsdl?WSDL#types?schema1'.
      line 34 of http://10.1.250.20/ttsoapcgi.wsdl?WSDL#types?schema1

      [ERROR] undefined simple or complex type 'SOAP-ENC:Array'
      line 34 of http://10.1.250.20/ttsoapcgi.wsdl?WSDL

      [ERROR] undefined attribute 'SOAP-ENC:arrayType'
      line 38 of http://10.1.250.20/ttsoapcgi.wsdl?WSDL

      [ERROR] undefined simple or complex type 'SOAP-ENC:Array'
      line 52 of http://10.1.250.20/ttsoapcgi.wsdl?WSDL

      [ERROR] undefined attribute 'SOAP-ENC:arrayType'
      line 56 of http://10.1.250.20/ttsoapcgi.wsdl?WSDL

      [ERROR] undefined simple or complex type 'SOAP-ENC:Array'
      line 70 of http://10.1.250.20/ttsoapcgi.wsdl?WSDL

      [ERROR] undefined attribute 'SOAP-ENC:arrayType'
      line 74 of http://10.1.250.20/ttsoapcgi.wsdl?WSDL

      [ERROR] undefined simple or complex type 'SOAP-ENC:Array'
      line 88 of http://10.1.250.20/ttsoapcgi.wsdl?WSDL

      [ERROR] undefined attribute 'SOAP-ENC:arrayType'
      line 92 of http://10.1.250.20/ttsoapcgi.wsdl?WSDL

      [ERROR] undefined simple or complex type 'SOAP-ENC:Array'
      line 106 of http://10.1.250.20/ttsoapcgi.wsdl?WSDL

      [ERROR] undefined attribute 'SOAP-ENC:arrayType'
      line 110 of http://10.1.250.20/ttsoapcgi.wsdl?WSDL

      [ERROR] undefined simple or complex type 'SOAP-ENC:Array'
      line 124 of http://10.1.250.20/ttsoapcgi.wsdl?WSDL

      [ERROR] undefined attribute 'SOAP-ENC:arrayType'
      line 128 of http://10.1.250.20/ttsoapcgi.wsdl?WSDL

      [ERROR] undefined simple or complex type 'SOAP-ENC:Array'
      line 142 of http://10.1.250.20/ttsoapcgi.wsdl?WSDL

      [ERROR] undefined attribute 'SOAP-ENC:arrayType'
      line 146 of http://10.1.250.20/ttsoapcgi.wsdl?WSDL

      [ERROR] undefined simple or complex type 'SOAP-ENC:Array'
      line 160 of http://10.1.250.20/ttsoapcgi.wsdl?WSDL

      [ERROR] undefined attribute 'SOAP-ENC:arrayType'
      line 164 of http://10.1.250.20/ttsoapcgi.wsdl?WSDL

      [ERROR] undefined simple or complex type 'SOAP-ENC:Array'
      line 263 of http://10.1.250.20/ttsoapcgi.wsdl?WSDL

      [ERROR] undefined attribute 'SOAP-ENC:arrayType'
      line 267 of http://10.1.250.20/ttsoapcgi.wsdl?WSDL

      [ERROR] undefined simple or complex type 'SOAP-ENC:Array'
      line 283 of http://10.1.250.20/ttsoapcgi.wsdl?WSDL

      [ERROR] undefined attribute 'SOAP-ENC:arrayType'
      line 287 of http://10.1.250.20/ttsoapcgi.wsdl?WSDL

      [ERROR] undefined simple or complex type 'SOAP-ENC:Array'
      line 316 of http://10.1.250.20/ttsoapcgi.wsdl?WSDL

      [ERROR] undefined attribute 'SOAP-ENC:arrayType'
      line 320 of http://10.1.250.20/ttsoapcgi.wsdl?WSDL

      [ERROR] undefined simple or complex type 'SOAP-ENC:Array'
      line 427 of http://10.1.250.20/ttsoapcgi.wsdl?WSDL

      [ERROR] undefined attribute 'SOAP-ENC:arrayType'
      line 431 of http://10.1.250.20/ttsoapcgi.wsdl?WSDL


      What is the solution for these errors?

      Is there any other Java tool that I can use that can consume a web service?Can anyone give me a walk through as I am really very new to this.
      It seems pretty complex to consume a web-service using Java compared to other languages!

      Thanks,
      Sravanthi.

      Edited by: sravanthi on Jan 8, 2009 2:54 PM
        • 1. Re: Consume Web Services in Java
          843802
          Are you still having trouble? I was able to get around this issue by placing the SOAP xsd locally in soap.xsd and using this command:
          wsimport.sh -b soap.xsd <your.wsdl>

          Paul
          • 2. Re: Consume Web Services in Java
            800479
            Hello,

            problem is you are using wsimport on web-service which uses RPC/encoding. Wsimport use JAX-WS so it is not able read it.
            You should wscompile.bat instead it.

            Here is example :

            wscompile.bat -gen:client -d build/classes -s src -keep config.xml

            (-gen:client -says to generate classes for client
            -d - directory where to store classes
            -s - directory where to store sources
            -keep - to keep source file
            xml file
            )

            Where config.xml looks like

            <?xml version="1.0" encoding="UTF-8"?>
            <configuration
            xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">
            <wsdl location=
            "http://something/yourws?wsdl"
            packageName="org.your.package.client"/>
            </configuration>

            I hope it will help.

            best regards