Web service - business objects don't show up

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Water Cooler v2

    #1

    Web service - business objects don't show up

    I create a test Web service like so:

    [WebService(Name space="http://blah.com")]
    public class ServiceThingy: System.Web.Serv ices.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]

    #2
    RE: Web service - business objects don't show up

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

    --
    Co-founder, Eggheadcafe.com developer portal:

    UnBlog:





    "Water Cooler v2" wrote:
    [color=blue]
    > I create a test Web service like so:
    >
    > [WebService(Name space="http://blah.com")]
    > public class ServiceThingy: System.Web.Serv ices.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?
    >
    >[/color]

    Comment

    • Josh Twist

      #3
      Re: Web service - business objects don't show up

      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
      XmlSerializatio n - 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/de...howwebmeth.asp,
      in particular the section on Mapping XML to Objects.

      Good Luck

      Josh


      Comment

      Working...