Typed DataSet serialization over Web Service

A

Adrian

Hello everyone.

I have the following problem:
I want to pass a typed data set parameter to a Web Service method
using the base class (DataSet) type in the parameter declaration. In
the Web Service method I would like to cast this parameter to its
original type but cast operation fails with an exception of type
InvalidCastException. When I checked the type of the parameter in the
WS method it doesn't show the original type but only the base class
type (DataSet). Why the original type is not serialized in the Web
Service call?

Here is a bit of code to see what am I talking about.

public class WS1 : WebService
{
[WebMethod]
public void MethodA(DataSet ds)
{
DSMyType dsX = (DSMyType) ds; // InvalidCastException
}
}

Proxy:
public class WS1 : System.Web.Services.Protocols.SoapHttpClientProtocol
{
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/MethodA",
RequestNamespace="http://tempuri.org/",
ResponseNamespace="http://tempuri.org/",
Use=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public void MethodA(DataSet ds)
{
object[] results = this.Invoke("MethodA ", new object[] {ds});
}
}

Client:
public void MethodB()
{
DSMyType dsX = new DSMyType();
WS1 ws = new WS1();
ws.MethodA(dsX);
}

The DSMyType is not recreated by the proxy but it is shared in the
common .dll.
 

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

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top