7 Replies Latest reply: Jun 1, 2009 9:13 AM by 843830 RSS

    How to access .asmx Web Service using JAVA? Newbie

    843830
      Hello Experts,

      Currently, I have a project where in I have to access a ,NET web service. It is made of C#. I just want to ask how will I start the accessing process? I made this simple equation on how my project is.

      Java Project + C#.Net Web Service = Integration



      1. Do i need to create a Web Service too for the Java Project? If yes, What are the necessary tools needed for the creation of this Java Web Service?

      2. The .NET Web Service is available online. (It is made by other people).

      3. Based on the equation, what is the equivalent technology for the + sign?

      4. Can you site a concrete example for accessing a web service?

      5. I'm new here. Totally I have no idea where to start.

      6. Thank you experts.

      Edited by: Benedict.Aluan on 05 30, 08 1:38 PM

      Edited by: Benedict.Aluan on 05 30, 08 1:39 PM
        • 1. Re: How to access .asmx Web Service using JAVA? Newbie
          843830
          Hi,

          You can just about access any kind of webservice using java, because communication is in a standardized format (SOAP and WSDL).

          First thing you need is the WSDL file for the webservice (Web Service Description Language).
          You can either contact the people who created this webservice to provide this file to you. Most probably, it can be taken directly from the URI of the webservice.

          eg. If the webservice URI is http://www.somehost.com/Mywebservice.asmx, then you can get the wsdl from
          http://www.somehost.com/Mywebservice.asmx?wsdl (Not always the case from my exp...)

          Once you have the wsdl file, there a number of ways in which you can call the web service from a java app.( Using jax-ws, apache axis etc)

          Simple tutorial using jax-ws
          http://www.netbeans.org/kb/60/websvc/client.html

          Check this out. I feel this is the simplest option for you to start off with.....
          • 2. Re: How to access .asmx Web Service using JAVA? Newbie
            843830
            Daddycoool wrote:
            Hi,

            You can just about access any kind of webservice using java, because communication is in a standardized format (SOAP and WSDL).

            First thing you need is the WSDL file for the webservice (Web Service Description Language).
            You can either contact the people who created this webservice to provide this file to you. Most probably, it can be taken directly from the URI of the webservice.

            eg. If the webservice URI is http://www.somehost.com/Mywebservice.asmx, then you can get the wsdl from
            http://www.somehost.com/Mywebservice.asmx?wsdl (Not always the case from my exp...)

            Once you have the wsdl file, there a number of ways in which you can call the web service from a java app.( Using jax-ws, apache axis etc)

            Simple tutorial using jax-ws
            http://www.netbeans.org/kb/60/websvc/client.html

            Check this out. I feel this is the simplest option for you to start off with.....
            You explained it very clear. :-) Thanks! Now it is more clear to me now how it goes. I'll ask you again if i got some questions. :-)
            • 3. Re: How to access .asmx Web Service using JAVA? Newbie
              843830
              I want to access .asmx file using java application. I am using Eclipse IDE and created
              some samples from this url: http://www.eclipse.org/webtools/jst/components/ws/M5/tutorials/BottomUpWebService.html

              I got the Soap request and response format from wsdl file. But, i don't know access
              the .asmx file. If u have any samples or give some suggestions that will be helpful for me to
              proceed.
              • 4. Re: How to access .asmx Web Service using JAVA? Newbie
                843830
                Hello
                Thanks a lot for your help ...
                I am developing simple J2EE based web service client using IBM WSAD 5.1. I have used the following code to call .asmx web service in Java
                String url = "http://www.w3schools.com/webservices/tempconvert.asmx?wsdl";
                     String namespace = "http://tempuri.org/";
                     name = request.getParameter("txtName");
                     
                     try
                     {
                          System.out.println("In Internet Service");
                          ServiceFactory factory = ServiceFactory.newInstance();
                          Service serv = factory.createService(new URL(url),new QName(namespace,"TempConvert"));
                          System.out.println("Got Service......");
                          Call obj = (Call)serv.createCall();
                          
                          System.out.println("Got Call......");
                          
                          obj.setProperty(Call.ENCODINGSTYLE_URI_PROPERTY,"");
                          obj.setProperty(Call.OPERATION_STYLE_PROPERTY,"wrapped");
                          obj.setTargetEndpointAddress(url);
                          obj.setPortTypeName(new QName(namespace,"TempConvertSoap"));
                          obj.setOperationName(new QName(namespace,"FahrenheitToCelsius"));
                          obj.addParameter("param1",XMLType.XSD_STRING,String.class,ParameterMode.IN);
                          obj.setReturnType(XMLType.XSD_STRING);
                          
                          System.out.println("Parameters Set.....");
                          Object[] params = new Object[]{name};
                          
                          k = (String)obj.invoke(params);
                          System.out.println("Result: "+k);
                     }
                     catch(Exception e)
                     {
                        System.out.println("Exception is : "+e);
                    }
                But this code is throwing exception that
                Invalid Address "http://www.w3schools.com/webservices/tempconvert.asmx?wsdl"
                I have also tried this URL with Java Proxy. But it showing the same error.
                Plz can u tell me how to access .asmx web service ?
                Waiting 4 reply.
                • 5. Re: How to access .asmx Web Service using JAVA? Newbie
                  843830
                  hrishi_k86 wrote:
                  But this code is throwing exception that
                  Invalid Address "http://www.w3schools.com/webservices/tempconvert.asmx?wsdl"
                  I have also tried this URL with Java Proxy. But it showing the same error.
                  Plz can u tell me how to access .asmx web service ?
                  Waiting 4 reply.
                  Hi hrishi_86,

                  The URL works perfectly. I've just build a WS stand alone client using JAX-WS with NetBeans 6.0 and it works nicely !
                  package main;
                  
                  import service.TempConvert;
                  import service.TempConvertSoap;
                  
                  public class Main {
                  
                      public static void main(String[] args) { new Main().execute(); }
                      
                      private void execute() {
                          TempConvertSoap service = new TempConvert().getTempConvertSoap();
                          System.out.println(service.celsiusToFahrenheit("20"));
                          System.out.println(service.fahrenheitToCelsius("99.9"));
                      }
                  }
                  • 6. Re: How to access .asmx Web Service using JAVA? Newbie
                    843830
                    hi Chicon
                    thanx 4 ur reply....
                    But can u tell me which Web Server u r using ? And can u plz send me detail steps for creating above example of web service in NetBeans ?? I m using WSAD 5.12.
                    Waiting 4 ur reply...
                    • 7. Re: How to access .asmx Web Service using JAVA? Newbie
                      843830
                      hrishi_k86 wrote:
                      But can u tell me which Web Server u r using ?
                      I don't use any web server.
                      hrishi_k86 wrote:
                      And can u plz send me detail steps for creating above example of web service in NetBeans ??
                      With NetBeans, I build a simple Java application with a classical Main class. There's a wizzard to implement a WS client package from the WSDL; it generates the needed Java classes. It is well explained in the help utilities of NetBeans.