locked
How to consume java web service RRS feed

  • Question

  • User1007181483 posted

    Maybe this isn't an MVC question but a general asp.net question, but I happen to be working in MVC4 and maybe I can't do this because of something in MVC.  I haven't tried doing it in asp.net yet.

    I have been handed a java web service with several methods including ListCountry.  I've added the service to my project as a Service Reference.  Great, it builds all the objects I need - almost.  As shown below, I can make all kinda neat things:

    CountryRecord countryRecord = new CountryRecord();
    List<CountryRecord> list = new List<CountryRecord>();
    ListCountryInput countryInput = new ListCountryInput();
    CountryList countryList = new CountryList();
    ListCountryOutput countryOutput = new ListCountryOutput();
    List<CountryList> country = new List<CountryList>();
    CountryList cList = new CountryList();
    cList = countryOutput.CountryList;
    ListCountryRequest1 listCountryRequest = new ListCountryRequest1();
    ListCountryResponse1 listCountryResponse = new ListCountryResponse1();

    What I really want to do however, is just return a list of countries:

    listCountryResponse = ctry.ListCountry(listCountryRequest);

    But, the gotcha is "ctry".  I can't declare it because it's an abstract class or interface, but ListCountry just does not exist except via ctry.

    Country ctry = new Country();

    "Cannot create an instance of the abstract class or interface 'Country'".

    I've read a little about derived classes and subclassing, but I'm not sure how to apply that in this case.  Or, am I just doing something wrong?  Or should I go to an asp.net forum?

    Thanks!

     




     

    Wednesday, October 9, 2013 5:39 PM

Answers

  • User-1426144113 posted

    Hi,

    I don't understand clearly that you said.

    But for the abstract class and interface, you should have one or more class inhert from the abstract class and iimplement the interface.

    For example for abstract class:

     abstract class ShapesClass
        {
            abstract public int Area();
        }
        class Square : ShapesClass
        {
            int side = 0;
    
            public Square(int n)
            {
                side = n;
            }
          
            public override int Area()
            {
                return side * side;
            }
         }
     ShapesClass shap = new Square(5);
                shap.Area();

    For below code, we shouldn't Instantiation the ShapsClass use this code: ShapesClass shap=new ShapesClass(). The abstract class can't be Instantiation. We should instantiation the class that inhert from the abstract class.

    If you still have issues, please provide the detail information to me.

    Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 11, 2013 11:35 AM

All replies

  • User-1426144113 posted

    Hi,

    I don't understand clearly that you said.

    But for the abstract class and interface, you should have one or more class inhert from the abstract class and iimplement the interface.

    For example for abstract class:

     abstract class ShapesClass
        {
            abstract public int Area();
        }
        class Square : ShapesClass
        {
            int side = 0;
    
            public Square(int n)
            {
                side = n;
            }
          
            public override int Area()
            {
                return side * side;
            }
         }
     ShapesClass shap = new Square(5);
                shap.Area();

    For below code, we shouldn't Instantiation the ShapsClass use this code: ShapesClass shap=new ShapesClass(). The abstract class can't be Instantiation. We should instantiation the class that inhert from the abstract class.

    If you still have issues, please provide the detail information to me.

    Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 11, 2013 11:35 AM
  • User1007181483 posted

    I'm going to mark this as the answer, although I'm still having trouble consuming the java webservice in .Net.  However, you gave me a vital clue and after some digging looking for the implemented interface, I found that creating the Service Reference created the desired interface, "CountryClient" from which I can do the service operations.

    The problems I'm having now have more to do with the structure of the java web service, so that's really a different issue.

    Thanks!

    Monday, October 14, 2013 10:09 AM