web service structure

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • asha

    web service structure

    Hi, I am new to .net so excuse me.

    I need to create mutiple webservices (for multiple clients). The webmethods
    would essentially have the same parameters except for the return values. say
    they pass us an id, then depending on webserice called I might need to return
    values, if client A calls methodA then just return name and phone but for
    client B calling methodA return name,phone and adress.. I want some
    reuasability in code (since I read the same data from database each time but
    some other processing differ) and want to return the output as custom object.

    I have been trying to use abstract class to define all the webmethods.. not
    very successful ..
    If I create a custom object having all possible fields is it possible to
    hide the non-required fields (i.e. Address when client A access the service
    for them), should I return XMLDocument..

    what is the best design pattern for webservice..



  • François Lemaire

    #2
    RE: web service structure

    For me, the best pattern for web service is :
    - create XML schemas describing your data and the XML messages you will
    send. There is a functionality (xs:extension) which permits you to create a
    complex data type that "inherit" from another complex data type.
    - create classes from your XML schema with the xsd.exe tool
    - define the operations your service needs and prepare your service class
    - code your service

    You can code an abstract class extending the WebService class containing all
    the operations you need for your clients, and inherit from it for each of
    your client ; in this concrete class, you expose the right methods as web
    service methods (the WebMethod attribute is not inherited, too bad...)

    You can check this article :

    ( I'm not from the family of the guy writing the book, I swear, but it's
    very good if you want to learn web services the right way)

    Regards

    François

    "asha" wrote:
    [color=blue]
    > Hi, I am new to .net so excuse me.
    >
    > I need to create mutiple webservices (for multiple clients). The webmethods
    > would essentially have the same parameters except for the return values. say
    > they pass us an id, then depending on webserice called I might need to return
    > values, if client A calls methodA then just return name and phone but for
    > client B calling methodA return name,phone and adress.. I want some
    > reuasability in code (since I read the same data from database each time but
    > some other processing differ) and want to return the output as custom object.
    >
    > I have been trying to use abstract class to define all the webmethods.. not
    > very successful ..
    > If I create a custom object having all possible fields is it possible to
    > hide the non-required fields (i.e. Address when client A access the service
    > for them), should I return XMLDocument..
    >
    > what is the best design pattern for webservice..
    >
    >
    >[/color]

    Comment

    • Todd Plambeck

      #3
      Re: web service structure

      You could parse the dataset returned from the database into another dataset
      then return the resulting product. For example, you return a dataset with 1
      table with columns name, phone, address. Since client A is calling,
      determine this however you have planned, we create a new datatable, copy the
      2 datacolumns we want into a new datatable, add that to a new dataset and
      return it. I don't think you can serialize a datatable, at least I never
      could, so the need for putting the new table into a new dataset. Client B,
      same deal just include the address as well. If you are sending any sizeable
      amounts of data through you web services, I would strongly recommend using
      WSE and creating a compression/decompression extension. After it serializes
      the data into XML, you'll have more data fluff then a gallon of Cool Whip.
      It'll speed up your app immensely.

      HTH

      Todd

      "asha" <asha@discussio ns.microsoft.co m> wrote in message
      news:9FF6A622-1257-4BB2-9F5E-BBE57A9F8092@mi crosoft.com...[color=blue]
      > Hi, I am new to .net so excuse me.
      >
      > I need to create mutiple webservices (for multiple clients). The
      > webmethods
      > would essentially have the same parameters except for the return values.
      > say
      > they pass us an id, then depending on webserice called I might need to
      > return
      > values, if client A calls methodA then just return name and phone but for
      > client B calling methodA return name,phone and adress.. I want some
      > reuasability in code (since I read the same data from database each time
      > but
      > some other processing differ) and want to return the output as custom
      > object.
      >
      > I have been trying to use abstract class to define all the webmethods..
      > not
      > very successful ..
      > If I create a custom object having all possible fields is it possible to
      > hide the non-required fields (i.e. Address when client A access the
      > service
      > for them), should I return XMLDocument..
      >
      > what is the best design pattern for webservice..
      >
      >
      >[/color]


      Comment

      Working...