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