473,386 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

WebService returns object - storing that object in ViewState

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.
}
}
Jul 17 '06 #1
3 2229
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.


Jul 18 '06 #2
Perfect. Just what I was looking for. Thanks for the detailed reply.

Mark

"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:xw**************@TK2MSFTNGXA01.phx.gbl...
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.


Jul 18 '06 #3
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
Jul 18 '06 #4

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

Similar topics

1
by: Karuppasamy | last post by:
H I have a WebService calling a Method in a Remote Object. The Remote method Returns an Object. This Webservice also returns the same object. All things are working fine when this Web Service is...
5
by: mtv | last post by:
Hi all, I have the following code: ================================ Webservice side: public class MyWS: WebService { private myLib.DataObject curDataObject;
8
by: kenneth fleckenstein nielsen | last post by:
hi guru's I want to restart my webservice when ever it throws an exception that isn't cought. can i do that by web.config or iss or how ??
9
by: Nick Gilbert | last post by:
Hi, I'm trying to create a system whereby my desktop application submits it's order to an online server using a webservice (pretty standard!). So, I added a new project to my solution to...
5
by: | last post by:
Hi, How long do webservice objects live for? In particular, if i have static variables filled with data from a static constructor in a webservice, how long will that data persist? thxs
4
by: dan655t | last post by:
Hello, I've come here to get some advise from the experts. Currently I am tasked with modifying a web service that currently supports one product to support multiple products. It needs to be...
10
by: Phillip Taylor | last post by:
Hi guys, I'm looking to develop a simple web service in VB.NET but I'm having some trivial issues. In Visual Studio I create a web services project and change the asmx.vb file to this: Imports...
1
by: daokfella | last post by:
I have a custom server control that exposes a property which is a complex type. I expose the property as such: public class Automobile { public AutomobileEngine Engine { get { object o =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
Oralloy
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,...

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.