WebService changed the name of my class

D

DAXU

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?
 
J

John Saunders [MVP]

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,814
Latest member
SpicetreeDigital

Latest Threads

Top