passing structure to a web service

Discussion in 'ASP .Net Web Services' started by Sharko, Aug 4, 2006.

  1. Sharko

    Sharko Guest

    Hi,

    I am facing a problem in passing a structure to web service.
    When I pass the structure to the web method, the structure reaches the
    web method with all it's attributes reinitialized based on it's data
    type (attributes of type "int" are set to zero, strings are set to the
    empty string, etc..)

    Below are the settings and some code snippets:

    - All the structures are placed in one DLL, namely, SysObjects.
    - The web service has web methods whose paramaters are structures
    from the SysObjects and passed by reference.

    NOTE:
    The attributes of the structure are internal. When the attributes
    are made "public" instead of internal, everything works fine.

    Code snippets:

    SysObjects DLL: Below is one of the structures used
    -----------------------------------------------------------------------------


    public struct SysItem
    {
    internal int id;

    internal SysItem( int id)
    {
    this.id = id ;
    }

    public int ID
    {
    get { return id ; }
    set { /* empty */ }
    }
    }
    _____________________________

    Web Service DLL: Below is one of the web methods
    ---------------------------------------------------------------------------

    public class TestService : System.Web.Services.WebService
    {
    [WebMethod]
    public void Test (VBCObjects.SysItem item)
    {
    Console.WriteLine (item.ID);
    }

    [WebMethod]
    public SysItem GetItem (int id)
    {
    return SysItem (id);
    }
    }

    __________________________________________

    ClientApp: Below is the code for the web service consumer (client)
    ------------------------------------------------------------------------------------------------
    public Test
    {
    public void TestMethod()
    {
    TestService service = new TestService();

    SysItem item= service.GetItem(100);
    service.Test(item);
    }
    }

    ______________________


    Thanks in advance...
     
    Sharko, Aug 4, 2006
    #1
    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. Dan Higman
    Replies:
    4
    Views:
    3,944
    Scott Allen
    Apr 9, 2005
  2. hocho888
    Replies:
    1
    Views:
    646
  3. Michael Averstegge
    Replies:
    0
    Views:
    4,241
    Michael Averstegge
    Jan 10, 2006
  4. Not Me
    Replies:
    1
    Views:
    3,189
    Not Me
    Jun 5, 2007
  5. Leo Violette
    Replies:
    0
    Views:
    1,055
    Leo Violette
    Apr 17, 2009
Loading...

Share This Page