Web service - business objects don't show up

Discussion in 'ASP .Net Web Services' started by Water Cooler v2, Feb 28, 2006.

  1. I create a test Web service like so:

    [WebService(Namespace="http://blah.com")]
    public class ServiceThingy: System.Web.Services.WebService
    {
    [WebMethod]
    public int ReturnFour()
    {
    return 4;
    }
    }


    I create another class other than this, like so:

    class BusinessObject
    {
    public string doBusiness()
    {
    return "Did business. It was nice.";
    }
    }


    I compile.
    I make a new Console application project.
    I add a Web Reference to this service asmx in my new console
    application project.
    When I do this:

    localhost.

    I expect the BusinessObject class also to show up, but it doesn't. The
    main service class shows up, though.

    Now, earlier on, only a few days ago, I developed a huge Web Service
    app with a lot of business objects and all the business object/classes
    showed up in the client. What's the deal here? Am I missing something
    obvious?
     
    Water Cooler v2, Feb 28, 2006
    #1
    1. Advertising

  2. Yes.
    Notice that the ReturnFour method is attributed with [WebMethod], and that
    the doBusiness method is not.
    Peter

    --
    Co-founder, Eggheadcafe.com developer portal:
    http://www.eggheadcafe.com
    UnBlog:
    http://petesbloggerama.blogspot.com




    "Water Cooler v2" wrote:

    > I create a test Web service like so:
    >
    > [WebService(Namespace="http://blah.com")]
    > public class ServiceThingy: System.Web.Services.WebService
    > {
    > [WebMethod]
    > public int ReturnFour()
    > {
    > return 4;
    > }
    > }
    >
    >
    > I create another class other than this, like so:
    >
    > class BusinessObject
    > {
    > public string doBusiness()
    > {
    > return "Did business. It was nice.";
    > }
    > }
    >
    >
    > I compile.
    > I make a new Console application project.
    > I add a Web Reference to this service asmx in my new console
    > application project.
    > When I do this:
    >
    > localhost.
    >
    > I expect the BusinessObject class also to show up, but it doesn't. The
    > main service class shows up, though.
    >
    > Now, earlier on, only a few days ago, I developed a huge Web Service
    > app with a lot of business objects and all the business object/classes
    > showed up in the client. What's the deal here? Am I missing something
    > obvious?
    >
    >
     
    Peter Bromberg [C# MVP], Feb 28, 2006
    #2
    1. Advertising

  3. Water Cooler v2

    Josh Twist Guest

    The ASMX runtime will add all types exposed in your webmethod to the
    WSDL (and thus, in turn, to your client projects when you add web
    reference). In this case your WebMethod exposes only an int.

    To prove the point create another WebMethod that returns an instance of
    your BusinessObject....

    However, the process by which objects enter and leave a Web Service is
    XmlSerialization - and this is capable of serializing data only - so
    your doBusiness() method wouldn't be visible.

    It's important to get a grip on all this before venturing too far with
    Web Services - so I recommend you read this:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwebsrv/html/howwebmeth.asp,
    in particular the section on Mapping XML to Objects.

    Good Luck

    Josh
    http://www.thejoyofcode.com/
     
    Josh Twist, Feb 28, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    307
    Fredrik Lundh
    Sep 27, 2006
  2. Scott M.

    Server Objects don't show up

    Scott M., Sep 6, 2008, in forum: ASP .Net
    Replies:
    0
    Views:
    291
    Scott M.
    Sep 6, 2008
  3. Chris Kennedy
    Replies:
    0
    Views:
    254
    Chris Kennedy
    Apr 17, 2009
  4. Chris Kennedy
    Replies:
    1
    Views:
    353
    Gregory A. Beamer
    Jul 19, 2009
  5. Henrik Skak Pedersen

    Architectual advice on Web Service. DataSet vs Business Objects?

    Henrik Skak Pedersen, Mar 25, 2006, in forum: ASP .Net Web Services
    Replies:
    5
    Views:
    223
    Josh Twist
    Mar 27, 2006
Loading...

Share This Page