WebService returns object - storing that object in ViewState

M

Mark

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.
}
}
 
S

Steven Cheng[MSFT]

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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Mark

Perfect. Just what I was looking for. Thanks for the detailed reply.

Mark

Steven Cheng said:
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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no
rights.
 
S

Steven Cheng[MSFT]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top