Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > WebService returns object - storing that object in ViewState

Reply
Thread Tools

WebService returns object - storing that object in ViewState

 
 
Mark
Guest
Posts: n/a
 
      07-17-2006
I'm consuming a webservice that makes a simple object available. The object
class is marked in the web service as [serializable]. I have a web
application that consumes and uses this web service's class. When I receive
the object from the web service, I'm interested in storing that object in
ViewState in the web application, but I receive the error below. I'm not
shocked that the web application can't serialize the object as the
[seralizable] attribute isn't something that cann be passed through the web
via the WSDL. Moreover, overriding the method for serialization in the web
service's code will not pass through the WSDL either.

This suggests that the only way for me to store this information in
ViewState on my client web application is to create my own local
object/objects, "copy" the data from the web service's object to my own, and
then store that object in ViewState. Correct or incorrect? This didn't
strike me was very elegant, but I don't see any alternatives.

Thanks in advance.
Mark

The type 'FlexiWebTestHarness.FlexiWS.Parameters' must be marked as
Serializable or have a TypeConverter other than ReferenceConverter to be put
in viewstate.

[Serializable]
public class MyClass
{
public MyClass()
{
MyString = "Wow";
}

public string MyString;

public void SaveToDatabase()
{
//Consider yourself saved.
}
}


 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      07-18-2006
Hello Mark,

Welcome to the MSDN newsgroup.

From your description, you're consuming an ASP.NET webservice in an ASP.NET
web application project. The webservice methods will return some custom
class objects(which is marked as serializable at server-side code) and you
will store them in ASP.NET page's viewstate in web application. However,
you found the client custom classes in the generated proxy classes are not
marked as [serializable] which prevent you from storing them into viewstate
directly, and you're wondering a convenient means to resolve the problem,
correct? If anything I missed, please feel free to let me know.

As for the two ASP.NET applications, are you developing them through VS
2005/.NET 2.0 or VS 2003/.NET 1.1? I've performed some local tests and
found that:

1. When developing through VS 2005/.NET 2.0, if I create a
webreference(proxy classes) for a webservice(i use a class library project
for test), the custom classes in the generated proxy will has
[serializable] marked already.

2. When developing through VS 2003/.NET 1.1, if I create a webreference to
a webservice(also use class library project), the custom classes in the
generated proxy has not been marked with [serializable] automatically.

So are you also developing under VS 2003/.NET 1.1? If so, I think you
current workaround about creating custom classes to used for the webservcie
client proxy is a valid method. Another way is to modify the autogenerated
proxy code, we can do this under the following two conditions:

1) If you are using VS IDE to generate the proxy(add webreference), you
will need to click the webreference node to locate the source code file for
those custom classes(client wrapper) and add the [serializable] attribute
for them manually. The drawback here is that when we update the
webreference, all the code is regenerate and our previous modification will
lose and we have to manually mark them again.

2) We can also consider using the wsdl.exe tool to create the webservice
proxy externally(out of our project) and then import the generated proxy
source code into our project. Then, we can manually customize the source
code and do not worry that the source will be automatically reset.

#Web Services Description Language Tool (Wsdl.exe)
http://msdn2.microsoft.com/en-us/library/7h3ystb6.aspx

I agree to your understanding that this problem is due to the webservice
WSDL's limitation( programing platform neutral) which can not express any
platform specific information(such as the .net framework specific
attributes on class). Anyway, the above things are some of my suggestions.
Hope this helps some.

If you have any other concerns or consideration on this, 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.






 
Reply With Quote
 
 
 
 
Mark
Guest
Posts: n/a
 
      07-18-2006
Perfect. Just what I was looking for. Thanks for the detailed reply.

Mark

"Steven Cheng[MSFT]" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> Hello Mark,
>
> Welcome to the MSDN newsgroup.
>
> From your description, you're consuming an ASP.NET webservice in an
> ASP.NET
> web application project. The webservice methods will return some custom
> class objects(which is marked as serializable at server-side code) and you
> will store them in ASP.NET page's viewstate in web application. However,
> you found the client custom classes in the generated proxy classes are not
> marked as [serializable] which prevent you from storing them into
> viewstate
> directly, and you're wondering a convenient means to resolve the problem,
> correct? If anything I missed, please feel free to let me know.
>
> As for the two ASP.NET applications, are you developing them through VS
> 2005/.NET 2.0 or VS 2003/.NET 1.1? I've performed some local tests and
> found that:
>
> 1. When developing through VS 2005/.NET 2.0, if I create a
> webreference(proxy classes) for a webservice(i use a class library project
> for test), the custom classes in the generated proxy will has
> [serializable] marked already.
>
> 2. When developing through VS 2003/.NET 1.1, if I create a webreference
> to
> a webservice(also use class library project), the custom classes in the
> generated proxy has not been marked with [serializable] automatically.
>
> So are you also developing under VS 2003/.NET 1.1? If so, I think you
> current workaround about creating custom classes to used for the
> webservcie
> client proxy is a valid method. Another way is to modify the autogenerated
> proxy code, we can do this under the following two conditions:
>
> 1) If you are using VS IDE to generate the proxy(add webreference), you
> will need to click the webreference node to locate the source code file
> for
> those custom classes(client wrapper) and add the [serializable] attribute
> for them manually. The drawback here is that when we update the
> webreference, all the code is regenerate and our previous modification
> will
> lose and we have to manually mark them again.
>
> 2) We can also consider using the wsdl.exe tool to create the webservice
> proxy externally(out of our project) and then import the generated proxy
> source code into our project. Then, we can manually customize the source
> code and do not worry that the source will be automatically reset.
>
> #Web Services Description Language Tool (Wsdl.exe)
> http://msdn2.microsoft.com/en-us/library/7h3ystb6.aspx
>
> I agree to your understanding that this problem is due to the webservice
> WSDL's limitation( programing platform neutral) which can not express any
> platform specific information(such as the .net framework specific
> attributes on class). Anyway, the above things are some of my
> suggestions.
> Hope this helps some.
>
> If you have any other concerns or consideration on this, 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.
>
>
>
>
>
>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      07-18-2006
Thanks for your prompt response Mark,

Glad that the information is of assistance. Also thanks for your "Perfect"
.

Have a good day!

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
Storing and Exposing a Complex Object Property In Viewstate daokfella ASP .Net 1 08-08-2008 08:26 PM
User Images: Storing in Files VS Storing in Database Jonathan Wood ASP .Net 1 06-02-2008 05:56 PM
WebService that returns an object murugan.pa@gmail.com ASP .Net Web Services 0 01-17-2007 06:40 AM
storing pointer vs storing object toton C++ 11 10-13-2006 11:08 AM



Advertisments