I have run into this problem occasionally, and have crude ways of
getting around it, but I'm wondering if anyone else has a better, more
elegant solution.
I have a web service and a client application that share a class. For
one of my web service methods, for example, I return an object of the
given class type. However, when I try to cast the object in my
client, I run into a namespace conflict. This makes sense to me, but
if I simply use the object provided from the web service, I lose all
of the methods due to serialization. I don't want to have to use
remoting, but I do want the class methods available to me. I can't do
a direct cast, as I said, due to namespace issues. What's the best
way to handle this? I assume it will include reflection, but I'm no
reflection expert.
I'm sure this has been asked and answered many times, but my quick
scan failed to find the answer.
Thanks!
Brad. 6 4019
I believe the issue of namespaces remains. If I serialize the object
from the web service, the namespace persists, making the
deserialization fail (or at least not produce the desired results),
since deserialization is to the client object's namespace. That's why
I was hoping for some sample code that dealt with this issue. Ideas?
Thanks again,
Brad.
On Wed, 18 Jul 2007 15:53:32 -0500, "Sheng Jiang[MVP]"
<sh*********@ho tmail.com.discu sswrote:
>To make your class serializable, see Introducing XML Serialization http://msdn2.microsoft.com/en-us/lib...hh(vs.80).aspx
By the way, it is faster to create typed and properties using XML schema editor and XSD.exe than typing in C# editor.
Hi Brad,
Yes, the question you mentioned does be a typical scenario. Actually, for
XML webservice, it is not recommended that client-side and server-side
share the same class implementation, because XML webservice should only
communicate based on WSDL description. Anyway, since your client and
server are both .NET based, that won't matter. To resolve the problem,
one approach I've suggested is manually modify the autogenerated client
proxy class, change the return type (originally is autogenerated from WSDL)
to your own custom classes(also shared at server-side).
Also, one problem here is that when you update the client proxy, your
modification in the proxy source code will be removed. In .NET framework
2.0, there is a partial class feature, so you can add a partial class file
for your client-side webservice proxy and add those webmethods that use
your own class in the partial class file. Thus, the separate partial class
file won't be affected when you update the service proxy. How do you think?
If there is anything unclear or if you have any other more specific
questions, please feel free to post here.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
=============== =============== =============== =====
Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
This sounds promising, but I think I'd need an example to make sense
of it. I am using .NET 2.0, so the partial class is definitely an
option for me.
Brad.
On Thu, 19 Jul 2007 04:23:25 GMT, st*****@online. microsoft.com (Steven
Cheng[MSFT]) wrote:
>Hi Brad,
Yes, the question you mentioned does be a typical scenario. Actually, for XML webservice, it is not recommended that client-side and server-side share the same class implementation, because XML webservice should only communicate based on WSDL description. Anyway, since your client and server are both .NET based, that won't matter. To resolve the problem, one approach I've suggested is manually modify the autogenerated client proxy class, change the return type (originally is autogenerated from WSDL) to your own custom classes(also shared at server-side).
Also, one problem here is that when you update the client proxy, your modification in the proxy source code will be removed. In .NET framework 2.0, there is a partial class feature, so you can add a partial class file for your client-side webservice proxy and add those webmethods that use your own class in the partial class file. Thus, the separate partial class file won't be affected when you update the service proxy. How do you think?
If there is anything unclear or if you have any other more specific questions, please feel free to post here.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead ============== =============== =============== ======
Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscripti...ult.aspx#notif ications. Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscripti...t/default.aspx.
============== =============== =============== ======
This posting is provided "AS IS" with no warranties, and confers no rights.
Actually, thanks to Jon Skeet in another thread, I may have found as
elegant a solution as I can hope for. Yes, it may have some issues,
but it works for me! :-)
// the idea for this came from http://www.eggheadcafe.com/tutorials...--copy-cl.aspx
private static T SetProperties<T , U>(U fromRecord, T toRecord)
{
foreach (PropertyInfo fromField in
fromRecord.GetT ype().GetProper ties())
{
if (fromField.Name != "Id")
{
foreach (PropertyInfo toField in
toRecord.GetTyp e().GetProperti es())
{
if (fromField.Name == toField.Name)
{
toField.SetValu e(toRecord,
fromField.GetVa lue(fromRecord, null), null);
break;
}
}
}
}
return toRecord;
}
Thanks!
Brad.
On Thu, 19 Jul 2007 01:11:57 -0600, Bradley Plett
<pl****@newsgro up.nospamwrote:
>This sounds promising, but I think I'd need an example to make sense of it. I am using .NET 2.0, so the partial class is definitely an option for me.
Brad.
On Thu, 19 Jul 2007 04:23:25 GMT, st*****@online. microsoft.com (Steven Cheng[MSFT]) wrote:
>>Hi Brad,
Yes, the question you mentioned does be a typical scenario. Actually, for XML webservice, it is not recommended that client-side and server-side share the same class implementation, because XML webservice should only communicate based on WSDL description. Anyway, since your client and server are both .NET based, that won't matter. To resolve the problem, one approach I've suggested is manually modify the autogenerated client proxy class, change the return type (originally is autogenerated from WSDL) to your own custom classes(also shared at server-side).
Also, one problem here is that when you update the client proxy, your modificatio n in the proxy source code will be removed. In .NET framework 2.0, there is a partial class feature, so you can add a partial class file for your client-side webservice proxy and add those webmethods that use your own class in the partial class file. Thus, the separate partial class file won't be affected when you update the service proxy. How do you think?
If there is anything unclear or if you have any other more specific questions, please feel free to post here.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead ============= =============== =============== =======
Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscripti...ult.aspx#notif ications. Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professiona l working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscripti...t/default.aspx.
============= =============== =============== =======
This posting is provided "AS IS" with no warranties, and confers no rights.
Thanks for your followup Brad,
Glad that you've got it working. Just to add some further info on the other
approach I mentioned, here is a former thread discussing on the same issue
and I've included some test code snippet and steps about the "manually
change autogenerated proxy class through partial class file" approach: http://groups.google.com/group/micro...rk.webservices
/browse_thread/thread/b844c512cadd9b2 8/030faf776ee4969 e
Hope this also helps.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Thanks! I may try this method sometime too. :-)
Brad.
On Fri, 20 Jul 2007 02:20:42 GMT, st*****@online. microsoft.com (Steven
Cheng[MSFT]) wrote:
>Thanks for your followup Brad,
Glad that you've got it working. Just to add some further info on the other approach I mentioned, here is a former thread discussing on the same issue and I've included some test code snippet and steps about the "manually change autogenerated proxy class through partial class file" approach:
http://groups.google.com/group/micro...rk.webservices /browse_thread/thread/b844c512cadd9b2 8/030faf776ee4969 e
Hope this also helps.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: tshad |
last post by:
I am trying to set up some shared functions in my Global.asax file and can't
seem to get it to work.
In my Global.asax:
Public Class myUtils
inherits System.Web.HttpApplication
public shared function tom() as string
tom = "This is the shared sub"
|
by: tshad |
last post by:
I am setting up some of my functions in a class called MyFunctions.
I am not clear as to the best time to set a function as Shared and when not
to. For example, I have the following bit manipulation routines in my
Class:
*******************************************************************************
imports System
NameSpace MyFunctions
|
by: Nak |
last post by:
Hi there,
In VB6 if I wanted to make a shared application so to speak I would
create an ActiveX EXE. This would allow me to expose objects of the
application but only have 1 instance loaded. What is the equivilent in
VB.NET? Would I create a normal assembly that can be communicated with
using remoting? or are there other ways?
Thanks in advance.
|
by: Herb |
last post by:
In my design environment this works fine, but when I deploy it I get an error.
I have a class "MessageBox" defined in my "App_Code" folder. My aspx file
contains the line "Imports MessageBox" at the top.
When I deploy and run the website I get the following error.
Server Error in '/' Application.
--------------------------------------------------------------------------------
|
by: Daniel |
last post by:
Hey guys
I had a site in .net 1.1 and have just moved it to .net 2.0.
A strange thing, in .net 1 when you create a project it puts it in a
namespace, in 2.0 it doesn't?
Also when in a namespace one form can't access methods in another, and when
not in a namespace same issue.
| |
by: Jon Ebersole |
last post by:
I am developing a webservice and a windows application that talk to each
other. They are using a standard VB class library in the background. I am
having problems understanding why I can't sync my namespaces properly.
Example;
My Windows namespace is MyCompany.MyWindowsSpace
My Webservice namespace is MyCompany.MyWebService
My Class Library namespace is MyCompany.MyLibrary
I am using typed objects to send back and forth to my...
|
by: Random |
last post by:
Here's a design question I'm curious to know if anyone here has wrestled
with before...
I'm writing my data access methods in classes in the App_Code directory. I
know that I can easily instantiate each class on a page and run it's
functions to get my data from the database. However, I'm wondering if I
could pick up performance if I made all the functions shared/static. Then
I'm wondering if it would be worth it because of the design...
|
by: tshad |
last post by:
I have a Dll I created in VS 2000.
The namespace is MyFunctions and the Class is CryptoUtil.
I have a program that is using the Class but it can't access it directly.
I have a class (below) called CryptoUtil.
The functions are Shared functions. I have this Dll in the bin folder of my
program. If I don't reference it - it can't seem to find it. If I have:
|
by: Web Search Store |
last post by:
Hello,
I made a web page using visual studio.
I also made a public class in the app_code folder called 'allvars'
In the main web page durning the page startup, I can refer to public shared
variables by simply saying:
x=allvars.variable1
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |