WebService changed the name of my class

Discussion in 'ASP .Net Web Services' started by DAXU@HOTMAIL.COM, Oct 30, 2007.

  1. Guest

    Hi,
    I am new to web service and I have a class called Pair like this:
    [Serializable]
    public class Pair<A, B>
    {
    public Pair()
    {
    First = default(A);
    Second = default(B);
    }
    ......
    }

    I created a web method to return a Pair class (e.g. Pair<int,
    DataSet>), and then have a web page to consume the returned Pair
    class. However, from metadata the return of the web method become:
    public class PairOfInt32DataSet
    {
    public PairOfInt32DataSet();

    public int First { get; set; }
    public DataSet Second { get; set; }
    }

    Can someone tell me why?
     
    , Oct 30, 2007
    #1
    1. Advertising

  2. <> wrote in message
    news:...
    > Hi,
    > I am new to web service and I have a class called Pair like this:
    > [Serializable]
    > public class Pair<A, B>
    > {
    > public Pair()
    > {
    > First = default(A);
    > Second = default(B);
    > }
    > ......
    > }
    >
    > I created a web method to return a Pair class (e.g. Pair<int,
    > DataSet>), and then have a web page to consume the returned Pair
    > class. However, from metadata the return of the web method become:
    > public class PairOfInt32DataSet
    > {
    > public PairOfInt32DataSet();
    >
    > public int First { get; set; }
    > public DataSet Second { get; set; }
    > }
    >
    > Can someone tell me why?


    Web services don't process objects - they process XML. The service is
    described by a WSDL, and the WSDL uses XML Schema to describe the XML to be
    sent and received.

    XML Schema has no way to describe generics.

    When you "have a web service that returns a Pair<int,DataSet>", .NET will
    produce a WSDL that includes an XML Schema that describes an XML complexType
    named PairOfInt32DataSet. When you create proxy classes for your client
    using Add Web Reference, .NET will create the proxy class PairOfIntDataSet,
    as you have seen.

    If you were consuming this web service from a platform other than .NET,
    things would be even worse, as the .NET class "DataSet" does not exist on
    platforms other than .NET.

    So, two things:

    1) What you see is the expected behavior. Platform-specific types will not
    translate across web services
    2) It is a bad idea to pass DataSet objects or other platform-specific
    types, as they will not translate across platforms.
    --
    --------------------------------------------------------------------------------
    John Saunders | MVP - Windows Server System - Connected System Developer
     
    John Saunders [MVP], Nov 3, 2007
    #2
    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. Fabian
    Replies:
    2
    Views:
    2,042
    Fabian
    Sep 9, 2004
  2. Newbie

    changed sql server db name

    Newbie, Jan 24, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    1,116
    Peter Chadwick (MCP)
    Jan 25, 2005
  3. Replies:
    1
    Views:
    698
    Rosanne
    Oct 11, 2005
  4. E11
    Replies:
    1
    Views:
    4,800
    Thomas Weidenfeller
    Oct 12, 2005
  5. mxbrunet
    Replies:
    1
    Views:
    221
Loading...

Share This Page