473,498 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert proxy type to class type

Joe
I have a web service which returns many types (classes) to match the return
type. I want to cast the return type to the actual class type.

For example:

namespace Test
{
class MyClass
{
...
}
}

[WebMethod]
public MyClass Test();

the proxy will be a deserialized version of MyClass but under the namespace
of the generated proxy.

I would like to do something like this:

MyClass myClass = webService.Test();

This of course won't work because the cast fails.

Then I thought of creating another proxy in the lib were MyClass is defined
and add a constructor which takes the proxy MyClass. BUT, the new proxy now
falls under another namespace and again fails.

I than thought of using one proxy for both instances (the calling app and
the lib) but this isn't really practical.
I also thought of using the Convert.ToType but that means the generated
proxy needs to implement IConvertible.

Are there any suggestions on how to handle this?

Thanks,
Joe
Nov 16 '05 #1
8 3638
Joe,

Why not do an implicit cast? For example:

MyClass myClass=(MyClass) webService.Test();

Basically, you're telling the compiler that you KNOW that this object that's
being returned is of the type MyClass, even though it thinks it isn't. If
it really isn't of that type, this line will fail, however.

Also, this probably isn't the best design. You may want to re-evaluate why
this particular approach is being used. You may also want to overload your
Test() method for each return type.

Robert
"Joe" <J_no_spam@_no_spam_Fishinbrain.com> wrote in message
news:ew**************@tk2msftngp13.phx.gbl...
I have a web service which returns many types (classes) to match the return
type. I want to cast the return type to the actual class type.

For example:

namespace Test
{
class MyClass
{
...
}
}

[WebMethod]
public MyClass Test();

the proxy will be a deserialized version of MyClass but under the
namespace
of the generated proxy.

I would like to do something like this:

MyClass myClass = webService.Test();

This of course won't work because the cast fails.

Then I thought of creating another proxy in the lib were MyClass is
defined
and add a constructor which takes the proxy MyClass. BUT, the new proxy
now
falls under another namespace and again fails.

I than thought of using one proxy for both instances (the calling app and
the lib) but this isn't really practical.
I also thought of using the Convert.ToType but that means the generated
proxy needs to implement IConvertible.

Are there any suggestions on how to handle this?

Thanks,
Joe

Nov 16 '05 #2
Joe
The cast fails. I think this is because the compiler sees them as 2 separate
classes rather than based on signature.

How would overloading Test() help? The WebMethod is supposed to return an
instance of class MyClass which contains all the data needed by the calling
application.

I was playing with the idea of using reflection to copy all the members from
one type to the other but that's time consuming (plus I haven't done it
before).

The other idea is to modify the proxy that was created so both namespaces
and class names match. This will allow it to work but that means having to
make the change anytime I need to update the proxy due to a change in the
web service.
"Robert May" <ra****************@hotmail.com> wrote in message
news:ul**************@TK2MSFTNGP09.phx.gbl...
Joe,

Why not do an implicit cast? For example:

MyClass myClass=(MyClass) webService.Test();

Basically, you're telling the compiler that you KNOW that this object that's being returned is of the type MyClass, even though it thinks it isn't. If
it really isn't of that type, this line will fail, however.

Also, this probably isn't the best design. You may want to re-evaluate why this particular approach is being used. You may also want to overload your Test() method for each return type.

Robert
"Joe" <J_no_spam@_no_spam_Fishinbrain.com> wrote in message
news:ew**************@tk2msftngp13.phx.gbl...
I have a web service which returns many types (classes) to match the return type. I want to cast the return type to the actual class type.

For example:

namespace Test
{
class MyClass
{
...
}
}

[WebMethod]
public MyClass Test();

the proxy will be a deserialized version of MyClass but under the
namespace
of the generated proxy.

I would like to do something like this:

MyClass myClass = webService.Test();

This of course won't work because the cast fails.

Then I thought of creating another proxy in the lib were MyClass is
defined
and add a constructor which takes the proxy MyClass. BUT, the new proxy
now
falls under another namespace and again fails.

I than thought of using one proxy for both instances (the calling app and the lib) but this isn't really practical.
I also thought of using the Convert.ToType but that means the generated
proxy needs to implement IConvertible.

Are there any suggestions on how to handle this?

Thanks,
Joe


Nov 16 '05 #3
Joe
I think what I'll do is create another lib with one proxy in it and share
the proxy with both the application and the other lib.

"Joe" <J_no_spam@_no_spam_Fishinbrain.com> wrote in message
news:ew**************@tk2msftngp13.phx.gbl...
I have a web service which returns many types (classes) to match the return type. I want to cast the return type to the actual class type.

For example:

namespace Test
{
class MyClass
{
...
}
}

[WebMethod]
public MyClass Test();

the proxy will be a deserialized version of MyClass but under the namespace of the generated proxy.

I would like to do something like this:

MyClass myClass = webService.Test();

This of course won't work because the cast fails.

Then I thought of creating another proxy in the lib were MyClass is defined and add a constructor which takes the proxy MyClass. BUT, the new proxy now falls under another namespace and again fails.

I than thought of using one proxy for both instances (the calling app and
the lib) but this isn't really practical.
I also thought of using the Convert.ToType but that means the generated
proxy needs to implement IConvertible.

Are there any suggestions on how to handle this?

Thanks,
Joe

Nov 16 '05 #4
Joe:

If I understand your question it sounds as if you want to tightly
couple the web service and the client by sharing a common type. This
can cause difficulties down the road as one or the other starts to
version and change - you'll need to keep them in sync.

--
Scott
http://www.OdeToCode.com/

On Tue, 19 Oct 2004 18:37:13 -0400, "Joe"
<J_no_spam@_no_spam_Fishinbrain.com> wrote:
I have a web service which returns many types (classes) to match the return
type. I want to cast the return type to the actual class type.

For example:

namespace Test
{
class MyClass
{
...
}
}

[WebMethod]
public MyClass Test();

the proxy will be a deserialized version of MyClass but under the namespace
of the generated proxy.

I would like to do something like this:

MyClass myClass = webService.Test();

This of course won't work because the cast fails.

Then I thought of creating another proxy in the lib were MyClass is defined
and add a constructor which takes the proxy MyClass. BUT, the new proxy now
falls under another namespace and again fails.

I than thought of using one proxy for both instances (the calling app and
the lib) but this isn't really practical.
I also thought of using the Convert.ToType but that means the generated
proxy needs to implement IConvertible.

Are there any suggestions on how to handle this?

Thanks,
Joe


Nov 16 '05 #5
Joe
I thought about the sync issue but since the client needs all the data
produced by the web service method it seems this won't be too big of an
issue.

What is another way to do this?

I have a web service, class library (this class library is used in many
other places) and a winforms app. The app consumes the service and uses the
classes in the class library for data management. So, for simplicity and
clarity, I thought it would be best to either have a constructor of these
classes that will take the generated proxy class and create a new class from
it or over load the = to perform the same task.

I've been throwing this idea around for a while because I hate iterating
through the data (class) returned from web service and populating
(essentially the same class) with its data.

I way open to better suggestions :)

Thanks,
Joe

"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:g6********************************@4ax.com...
Joe:

If I understand your question it sounds as if you want to tightly
couple the web service and the client by sharing a common type. This
can cause difficulties down the road as one or the other starts to
version and change - you'll need to keep them in sync.

--
Scott
http://www.OdeToCode.com/

On Tue, 19 Oct 2004 18:37:13 -0400, "Joe"
<J_no_spam@_no_spam_Fishinbrain.com> wrote:
I have a web service which returns many types (classes) to match the returntype. I want to cast the return type to the actual class type.

For example:

namespace Test
{
class MyClass
{
...
}
}

[WebMethod]
public MyClass Test();

the proxy will be a deserialized version of MyClass but under the namespaceof the generated proxy.

I would like to do something like this:

MyClass myClass = webService.Test();

This of course won't work because the cast fails.

Then I thought of creating another proxy in the lib were MyClass is definedand add a constructor which takes the proxy MyClass. BUT, the new proxy nowfalls under another namespace and again fails.

I than thought of using one proxy for both instances (the calling app and
the lib) but this isn't really practical.
I also thought of using the Convert.ToType but that means the generated
proxy needs to implement IConvertible.

Are there any suggestions on how to handle this?

Thanks,
Joe

Nov 16 '05 #6
Well, one approach would be to handcraft the proxy classes. You could
take a look at what the WSDL tool generates and work from there - it
is pretty much boilerplate code. I don't advise this appraoach of
course, but I can understand if you have a special circumstance.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Wed, 20 Oct 2004 00:01:30 -0400, "Joe"
<J_no_spam@_no_spam_Fishinbrain.com> wrote:
I thought about the sync issue but since the client needs all the data
produced by the web service method it seems this won't be too big of an
issue.

What is another way to do this?

I have a web service, class library (this class library is used in many
other places) and a winforms app. The app consumes the service and uses the
classes in the class library for data management. So, for simplicity and
clarity, I thought it would be best to either have a constructor of these
classes that will take the generated proxy class and create a new class from
it or over load the = to perform the same task.

I've been throwing this idea around for a while because I hate iterating
through the data (class) returned from web service and populating
(essentially the same class) with its data.

I way open to better suggestions :)

Thanks,
Joe

"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:g6********************************@4ax.com.. .
Joe:

If I understand your question it sounds as if you want to tightly
couple the web service and the client by sharing a common type. This
can cause difficulties down the road as one or the other starts to
version and change - you'll need to keep them in sync.

--
Scott
http://www.OdeToCode.com/

On Tue, 19 Oct 2004 18:37:13 -0400, "Joe"
<J_no_spam@_no_spam_Fishinbrain.com> wrote:
>I have a web service which returns many types (classes) to match thereturn >type. I want to cast the return type to the actual class type.
>
>For example:
>
>namespace Test
>{
>class MyClass
>{
> ...
>}
>}
>
>[WebMethod]
>public MyClass Test();
>
>the proxy will be a deserialized version of MyClass but under thenamespace >of the generated proxy.
>
>I would like to do something like this:
>
>MyClass myClass = webService.Test();
>
>This of course won't work because the cast fails.
>
>Then I thought of creating another proxy in the lib were MyClass isdefined >and add a constructor which takes the proxy MyClass. BUT, the new proxynow >falls under another namespace and again fails.
>
>I than thought of using one proxy for both instances (the calling app and
>the lib) but this isn't really practical.
>I also thought of using the Convert.ToType but that means the generated
>proxy needs to implement IConvertible.
>
>Are there any suggestions on how to handle this?
>
>Thanks,
>Joe
>


Nov 16 '05 #7
Joe,

You are on the right track with defining the types in a separate
assembly, and then having the proxy code reference that assembly.

If you are using the classes generated by VS.NET, then you will have to
go to the IDE-generated code and remove all of the definitions for the
classes that are read from the WSDL which are used as return types and
parameter types. Then, you just have to make sure that the appropriate
namespaces are in scope (through a using statement), and it should work.

If you wanted to be really slick, you could use the WSDL tool and define
the namespace that the proxies are in. You would define it to be in the
same namespace as the rest of the types that are passed around. This way,
all you have to do is remove the definitions, and not worry about the fully
qualified type names (I'm not sure if the web service proxy generator does
this).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Joe" <J_no_spam@_no_spam_Fishinbrain.com> wrote in message
news:ew**************@tk2msftngp13.phx.gbl...
I have a web service which returns many types (classes) to match the return
type. I want to cast the return type to the actual class type.

For example:

namespace Test
{
class MyClass
{
...
}
}

[WebMethod]
public MyClass Test();

the proxy will be a deserialized version of MyClass but under the
namespace
of the generated proxy.

I would like to do something like this:

MyClass myClass = webService.Test();

This of course won't work because the cast fails.

Then I thought of creating another proxy in the lib were MyClass is
defined
and add a constructor which takes the proxy MyClass. BUT, the new proxy
now
falls under another namespace and again fails.

I than thought of using one proxy for both instances (the calling app and
the lib) but this isn't really practical.
I also thought of using the Convert.ToType but that means the generated
proxy needs to implement IConvertible.

Are there any suggestions on how to handle this?

Thanks,
Joe

Nov 16 '05 #8
Interestingly enough, Joe, this just turned up today:

http://pluralsight.com/wiki/default....uildingWsdlExe

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Tue, 19 Oct 2004 18:37:13 -0400, "Joe"
<J_no_spam@_no_spam_Fishinbrain.com> wrote:
I have a web service which returns many types (classes) to match the return
type. I want to cast the return type to the actual class type.

For example:

namespace Test
{
class MyClass
{
...
}
}

[WebMethod]
public MyClass Test();

the proxy will be a deserialized version of MyClass but under the namespace
of the generated proxy.

I would like to do something like this:

MyClass myClass = webService.Test();

This of course won't work because the cast fails.

Then I thought of creating another proxy in the lib were MyClass is defined
and add a constructor which takes the proxy MyClass. BUT, the new proxy now
falls under another namespace and again fails.

I than thought of using one proxy for both instances (the calling app and
the lib) but this isn't really practical.
I also thought of using the Convert.ToType but that means the generated
proxy needs to implement IConvertible.

Are there any suggestions on how to handle this?

Thanks,
Joe


Nov 16 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1443
by: nitrogenycs | last post by:
Hello, I need a way to get a notification whenever a variable of an object changes. The approach should be non-intrusive so that I can use existing objects without modifying them. I want to be...
1
9880
by: ffhansix | last post by:
Hi, I am having problems with generating a c# proxy class from a IBM websphere WSDL file, when running the wsdl.exe to create the c# proxy file command i recieve an error: Warning: one or...
8
2733
by: Joe | last post by:
I have a web service which returns many types (classes) to match the return type. I want to cast the return type to the actual class type. For example: namespace Test { class MyClass { ...
3
5736
by: MIGUEL | last post by:
Hi all, I'm quite lost with how adding web references to a project creates proxy classes. I've developed a web service with two classes inside and that contains three references to three...
2
1454
by: Seli | last post by:
Hello I have a BusinessClass CreditCardInfo defined in a library: namespace Cockpit.TrackingLibrary { /// <summary> /// Summary description for OPCSignal. /// </summary> public class...
9
3182
by: MSDNAndi | last post by:
Hi, I have a set of simple webservices calls that worked fine using .NET Framework 1.0. I am calling a Java/Apache based webservices, the calling side is not able to supply a proper WSDL. ...
1
2839
by: louis_la_brocante | last post by:
Dear all, I am having trouble generating a client proxy for a webservice whose methods return a "complex" type. The type is complex in that it is a class whose members are a mix of primitive...
3
14175
by: Joseph Geretz | last post by:
System.InvalidOperationException: WebServiceBindingAttribute is required on proxy classes. My environment: Visual Studio 2005, targeting FX 2.0; I've developed a Web Service which uses DIME to...
2
2510
by: Gabriel Genellina | last post by:
En Tue, 29 Jul 2008 13:13:51 -0300, Magnus Schuster <magnusschuster@yahoo.comescribi�: __magic__ methods on new style classes are searched in the class, *not* in the instance. prx_i+1 looks...
0
7121
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6993
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7197
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6881
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7375
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4899
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4584
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.