Data types returned by web service

  • Thread starter J. Garth Ogzewalla
  • Start date
J

J. Garth Ogzewalla

I'm trying to figure out how to architect web services,
and am running into problems with incompatible
namespaces. Here is the scenario: I have a user created
type such as a typed dataset, or an enum. I want to use
these data types to declare the parameters of the web
service's procedures, in my clients that call the web
service, and in the server components that the web service
calls, etc. In other words, I want to use the same data
class on both sides of the web services. However, when I
try to do so, what the web service actually exposes to the
clients is a new type which is in a namespace that .Net
has created for the web service. Since the namespace is
different, the compiler doesn't recognize the objects as
being of the same type, despite the fact that I declared
them in my code using the same class.

I tried to get around this by casting my dataset and enum,
etc, but the compiler won't let me as it doesn't know how
to make the conversion. Thus I have to code the
conversion with something like merging the dataset
returned from the web service into my typed dataset, or
wrapping my web service calls with a switch statement in
which if it's myEnum.Value1 then call with
webServiceEnum.Value1 and myEnum.Value2 then call with
webServiceEnum.Value2. This seems like a hack to me. I
assume it consumes resources and adversely impacts
performance unnecessarily.

What's the recommended way to do this? Am I missing
something in how my namespaces are set up? Can I tell the
web service to use a particular namespace instead of
creating it's own? And if so, does that cause the proxies
and stubs run into problems?

What I'm trying to do is something like:

//My Type Declarations
namespace myTypes
{
public class dsMyDataSet : DataSet
{
...
}
}

//Client
namespace myClient
{
public class myWebPage
{
// Return data set of my type
private myTypes.dsMyDataSet GetData ()
{
myWebService.WSData wsData = new myWebService.WSData
();
// But here's where it breaks,
// because the web service returns a data
sets of type myWebService.dsMyDataSet
// instead of myTypes.dsMyDataSet!
return wsData.GetData();
}
}
}

//Web Service
namespace myWebService
{
public class WSData
{
// Return data set of my type
[WebMethod]
public myTypes.dsMyDataSet GetData ()
{
return myComponent.ComponentData.GetData ();
}
}
}

//Server Component
namespace myComponent
{
public class ComponentData
{
// Return data set of my type
public myTypes.dsMyDataType GetData ()
{
myTypes.dsMyDataSet dsMyData = new
myTypes.dsMyDataSet();
...
return dsMyData;
}
}
}

The work around I have so far is something like:

//Client
namespace myClient
{
public class myWebPage
{
private myTypes.dsMyDataSet GetData ()
{
// Declare: web service
// data set of type returned by web service
// and data set of my type
myWebService.WSData wsData = new
myWebService.WSData();
myWebService.myDataSet dsMyWebData;
myTypes.dsMyDataSet dsMyData = new
myTypes.dsMyDataSet();

// Get data set of type returned by web service
// and merge the data into dataset of my type
dsMyWebData = wsData.GetData();
dsMyData.Merge (dsMyWebData);
return wsData.GetData();
}
}
}

Is there any way to get around the extra code to translate
the data types? Any help would be very appreciated.

Garth
 
E

Ed Smith[msft]

Create a disco file that has a link to both web services in it. then add a
web reference to the .disco file. This will create 1 proxy, that has
everything in it. You will then be able to share your types.


Hope this helps;
-Ed Smith
VB QA Team



--------------------
Content-Class: urn:content-classes:message
From: "J. Garth Ogzewalla" <[email protected]>
Sender: "J. Garth Ogzewalla" <[email protected]>
Subject: Data types returned by web service
Date: Mon, 6 Oct 2003 09:44:09 -0700
Lines: 125
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcOMKRB25Scst8vNSzil3I6REuwrPA==
Newsgroups: microsoft.public.dotnet.framework.aspnet.webservices
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet.webservices:19781
NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservices

I'm trying to figure out how to architect web services,
and am running into problems with incompatible
namespaces. Here is the scenario: I have a user created
type such as a typed dataset, or an enum. I want to use
these data types to declare the parameters of the web
service's procedures, in my clients that call the web
service, and in the server components that the web service
calls, etc. In other words, I want to use the same data
class on both sides of the web services. However, when I
try to do so, what the web service actually exposes to the
clients is a new type which is in a namespace that .Net
has created for the web service. Since the namespace is
different, the compiler doesn't recognize the objects as
being of the same type, despite the fact that I declared
them in my code using the same class.

I tried to get around this by casting my dataset and enum,
etc, but the compiler won't let me as it doesn't know how
to make the conversion. Thus I have to code the
conversion with something like merging the dataset
returned from the web service into my typed dataset, or
wrapping my web service calls with a switch statement in
which if it's myEnum.Value1 then call with
webServiceEnum.Value1 and myEnum.Value2 then call with
webServiceEnum.Value2. This seems like a hack to me. I
assume it consumes resources and adversely impacts
performance unnecessarily.

What's the recommended way to do this? Am I missing
something in how my namespaces are set up? Can I tell the
web service to use a particular namespace instead of
creating it's own? And if so, does that cause the proxies
and stubs run into problems?

What I'm trying to do is something like:

//My Type Declarations
namespace myTypes
{
public class dsMyDataSet : DataSet
{
...
}
}

//Client
namespace myClient
{
public class myWebPage
{
// Return data set of my type
private myTypes.dsMyDataSet GetData ()
{
myWebService.WSData wsData = new myWebService.WSData
();
// But here's where it breaks,
// because the web service returns a data
sets of type myWebService.dsMyDataSet
// instead of myTypes.dsMyDataSet!
return wsData.GetData();
}
}
}

//Web Service
namespace myWebService
{
public class WSData
{
// Return data set of my type
[WebMethod]
public myTypes.dsMyDataSet GetData ()
{
return myComponent.ComponentData.GetData ();
}
}
}

//Server Component
namespace myComponent
{
public class ComponentData
{
// Return data set of my type
public myTypes.dsMyDataType GetData ()
{
myTypes.dsMyDataSet dsMyData = new
myTypes.dsMyDataSet();
...
return dsMyData;
}
}
}

The work around I have so far is something like:

//Client
namespace myClient
{
public class myWebPage
{
private myTypes.dsMyDataSet GetData ()
{
// Declare: web service
// data set of type returned by web service
// and data set of my type
myWebService.WSData wsData = new
myWebService.WSData();
myWebService.myDataSet dsMyWebData;
myTypes.dsMyDataSet dsMyData = new
myTypes.dsMyDataSet();

// Get data set of type returned by web service
// and merge the data into dataset of my type
dsMyWebData = wsData.GetData();
dsMyData.Merge (dsMyWebData);
return wsData.GetData();
}
}
}

Is there any way to get around the extra code to translate
the data types? Any help would be very appreciated.

Garth
 

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,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top