Web Services returning objects; Cannot serialize in Viewstate/Session due to SOAP headers

Our company has moved from InProc to StateServer Session State recently, and I've run into the problem of not being able to store objects that are returned from the Web Service into the Session because the SOAP Headers are not serializable. How can I combat this problem?

Also, if this is a big issue, is there another way I can store these objects in order to persist them through postbacks for sorting on a Gridview? Application level variables seem to be overlapping data between multiple users.

0
jlrolin
3/31/2008 3:16:07 PM
asp.net.xml-web-services 7071 articles. 0 followers. Follow

9 Replies
678 Views

Similar Articles

[PageSpeed] 8

In my opinion , using the object that is returned from a webservice in your pages and directly in the code is not a good practice !

because it makes your application a highly coopled with that webservice , and so make it hard to chagne the service in the future ,

instead , you need a at least an assember class that mapp between the webservice objects and your custom object ,

so you need to write a cutom obejcts that is used in the application, and let that assembler class return them instead of returning the actual webservice object ,

the assembler class must take the webservice object and return a custom object that you write .....

your cutom object must  be marked with Serializable()  attribute so that the runtime can serialize it !

 

Hope it helps


Regards,

Anas Ghanem.


Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!

0
anas
3/31/2008 3:33:37 PM

I understand what you are saying, but the framework we use for our Web Services has over 100 different Entity classes, each with their own web service. Is there not another way that would less cumbersome?

0
jlrolin
3/31/2008 3:39:03 PM

ah,

well, I afraid that the only solution is to use Inproc mode !

Please try to check if the generated entities( proxy classes) is partial classes ,

if yes , try to mark them as serializable by  writing a new partial  class for every proxy class

e.g: if you have a class called Customer ,

try to write

<Serializable()> _

Partial class Customer ()

End class

this may set the proxy class as serilizable , !

another thing that you need to check is that the original classes (in the webservice  code ) was marked with <Serializable()> attribute !

what is the custom entities type ? are you implementing some remoting interface(like MarshalByRefObject) that prevent serilizing the classes ?

Update : another solution is to use the cache !


Regards,

Anas Ghanem.


Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!

0
anas
3/31/2008 3:53:33 PM

We've now run into the original problem that I've been having. I have been using the Cache, but for some reason, when I postback on my Gridviews... my Gridview are grabbing other user's data that is in the Cache. Very odd behavior considering I am using the key as the SessionID from the StateServer. Data seems to be overlapping, etc.

0
jlrolin
3/31/2008 4:16:22 PM

Hi

yes, if the data is unique for every user, you need to use a unique cache key for every user,

e.g: you can concat the userID with some key , this way you can avoid the overlapping issues

dim key as string= UserID +":" + "SomeKey"

cache(key )= your object

 

Regards, 


Regards,

Anas Ghanem.


Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!

0
anas
3/31/2008 4:49:39 PM

What I'm doing right now is using HttpContext.Current.Session.SessionID as the unique key. Am I wrong in assuming that this would be unique for every user on different systems?

0
jlrolin
3/31/2008 4:57:19 PM

jlrolin:
What I'm doing right now is using HttpContext.Current.Session.SessionID as the unique key. Am I wrong in assuming that this would be unique for every user on different systems?

no , never use sessionID ! it will never be the same for the user , the sessionId will be generated automaticly for every user sessio,

and it will be unique just for the same user session ,and it will be changed when the session tiomes out !

so please , you need something else !

if you are working with formsAuthentication, its good to use HttpContext.Current.User.Identiy.Name , this will returned the autheinticated userName .

 


Regards,

Anas Ghanem.


Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!

0
anas
3/31/2008 5:07:11 PM

When I hit sort or page on my Gridview, I'm only using the SessionID as a unique key for the data in the Cache. Will my Httpcontext.current.session.sessionID actually change within a 1-2 second span from loading a page to hitting a sort header?

0
jlrolin
3/31/2008 5:16:59 PM

jlrolin:

When I hit sort or page on my Gridview, I'm only using the SessionID as a unique key for the data in the Cache. Will my Httpcontext.current.session.sessionID actually change within a 1-2 second span from loading a page to hitting a sort header?

it depeds on the session timeout value in web.config ( default is 20 minutes ) , but i think it will nt changed !

try to  debug and check the values before and after the sort !

Again , you should not use the sessionID as a cache key ....

 

Hope it helps


Regards,

Anas Ghanem.


Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!

0
anas
3/31/2008 5:26:33 PM
Reply:

Similar Artilces:

web service SOAP Headers
If this isn't the right forum, let me know what is.Is there a difference between SOAP serialization and  and XML serialization.I have been reading heavily and am now quite confused.I understand that SOAP serialization produces XML, but perhaps without a specific schema or a scheme very different from XML. In the context of web services, the XML Serializer is used to produce XML in SOAP format. What you may be getting confused about is that there is also a "runtime serialization" subsystem. This can serialize data either using a Binary Formatter, or a SOAP Formatter. It...

xml web service --uploading the file to the xml web service
how can we upload the file in the xml web service 1.i mean what will be the return value in the proxy class 2.and how am i going to send the file to the xml web service----regards Bipul Kumar Here are some links to articles that helped us get this done: http://msdn.microsoft.com/webservices http://www.microsoft.com/downloads/details.aspx?familyid=06255a94-2635-4d29-a90c-28b282993a41&displaylang=en https://www.sys-con.com/dotnet/article.cfm?id=458 Hope this helps....

How to call a .net web service from another .net web service?
Hi all,I have developed two asp .net web services using visual studio .net 2003.I wish to call one web service from another web service.I tried adding a web reference of the web service in another web service and was able to do so.but i m not able to access the web methods provided by the web servicecould you please suggest a way to go about itExpecting quick replyThanxCharmy try to make sure that you reference it in the web reference and call it properly this is sample  [WebMethod()] public double CalcDistance(int x1, int y1, int x2, int y2) { Calculator.Service1 calc = new...

Web service in .NET from Java Web Service
Hi there,I'm pretty new to .net (although i have years of experience with the old vb 6, access 2k, as well as java)... and need some with perhaps either some syntax or something.Here is the wsdl.<wsdl:definitions targetNamespace="http://www.dynix.com/schema/book">−<wsdl:types>−<schema targetNamespace="GetBookInfoByISBN">−<complexType name="BookInfoType">−<sequence><element maxOccurs="1" minOccurs="0" name="Title" nillable="true" type="xsd:string"/><element maxOccurs=&quo...

.NET web services Vs Java Web Services
Hello, does anyone know of a book or good source of information that compares .NET and Java Web Services? (I would like soemthing neutral if possible). I am thinking of approaching this subject for my dissertation? Many Thanks Rob Hi Rob, Last year I had to give a powepoint presentation on Web Services. I noticed some good books at barnes and noble that discussed the subject. These books were specific to Java and discussed Web Services in a very clear fashion. They gave some elementary examples that were easy to understand. I have not yet had the pleasure of creatin .NET Web Servi...

Can you return .net web controls in a .net page from a web service?
I've got a problem with a project. I've got to compile an entire .net page and return it as part of a Web Service for display. The problem I have is that I need to add WebControls and functionality to the page so that not only the html content and images are displayed (which I've managed) but that textboxes, labels, buttons and datasets can be displayed also. Essentially I need to make a call from one site for a page, populate the page and return it in a state as though it resided on the same server/webspace as the calling page. Code is currently built as follows into a string: strOpenHT...

How do I set a session ID in a web service SOAP header using a .NET proxy?
I have a web service proxy set up in PB 10.5. I need to set a session ID in the SOAP header so the web service can validate subsequent requests for this session. Is this possible? You can't modify the SOAP headers unfortunately. That capability is supposed to be forthcoming in an EBF/Maintenance Release, but I do not now of an specific timeframe. On 20 Apr 2006 13:40:54 -0700, "Libby Engelbret" <lengelbret@npomn.com> wrote: >I have a web service proxy set up in PB 10.5. I need to set a session ID in >the SOAP header so the web service can val...

SOAP Web Service Problem (problema con un web service)
Please help, I can't read a webservice method (webmethod) from asmx web service, with Delphi firemonkey, In my first try I put a WDSL Importer, and I can retrive data from simplex type (string, booleans, integers) but when the method returns a DataSet, i loose my way. Por favor, ayuda, no puedo leer datos de un web service si el metodo que regresa es un DataSet, el web service esta hecho en dot.net así que es un asmx, utilizando el WDSL importes, traje datos sencillos como enteros, boleanos y otros, pero en el caso de arreglos como un DataSet no lo he conseguido, estoy perdido, y l...

Returning Serialized XMl from Web Service
Fumbling about in the dark here. I'm trying to output serialized XML from my webservice, but I keep getting a 'Object reference not set to an instance of an object' error (marked below). Can anybody tell me if I'm going about this the correct way, etc? Thanks. Imports System.Web Imports System.Web.Services Imports System.DirectoryServices Imports System.Xml.Serialization <WebService(Namespace:="http://www.someuri.co.uk/webservices/")> _ Public Class ActiveDirectory Inherits System.Web.Services.WebService #Region " Web Services Designer ...

Calling a Web Service from a Web Service
Hello,I was looking for some feedback on calling a web service from within a web service. I've heard that it's not good practice (or not possible). I have a scenario where I think it might make some sense.Within our infrastructure, we've created a web service that handles incoming updates on the statuses of all processes. This has proven to be a good thing since it allows applications to communicate across server to make status updates. It's also used by third party developers and applications to communicate with our infrastructure.Along these lines ... we are planning to create a new compon...

Is web services a part of web Service?
  I have a question: Is web services a part of web server?? And when the client calls web service, it means that client calls web server?? Or is it a different entity in itself which communicates separately both with client and server and acts as middleware application.. I am very confused.. Can someone explain me the architecture...??? Thanks..Dont forget to click "Mark as Answer" on the post that helped you.This credits the member,earns you a point & marks your thread as Resolved so that new users will know where to search for their queries. When you build and dep...

what are web services and what are the advantages of web services?
 Hello  i am new to this .net stuff and i was ask on the job interview what a web services is?and if i did not know given that i had a project ( as a project manager,  or a web developer)   what  is it? how do i start a >NET project on it? what are the main advantages is?  HOW DO I START THIS IN THE INTERVIEW>  and what basic books do i buy?   Hi There, There plenty of source on the net about webservice Definiton: http://en.wikipedia.org/wiki/Web_service http://www.codeproject.com/Purgatory/Defining_Web_Services.asp...

Web Site Project: How to configure web service URL in web.config (web service defined in a referenced DLL)
I have a web site that references a business logic DLL project. In the business logic project, there is a web service defined in its app.config file something like this: <applicationSettings>  <MyNamespace.BLL.Properties.Settings>    <setting name="MyNamespace_BLL_MyServer_ServiceName" serializeAs="String">    <value>http://blah.blah.blah.asmx</value>  </setting>  </MyNamespace.BLL.Properties.Settings></applicationSettings> When the web site is published, the web ...

create valid xml to send to web service based on the schema provided by web service
Problem: I have a web page which is being populated from a dataset containing multiple tables.  I now need to call a web service and send the majority of this data to be incorporate into a mainframe system.  I have been supplied with the schema that the web service will be using to validate the data.  I am new to web services and I am not sure how to take my existing dataset and transform it into an xml document that matches the schema I was provided with. There is a main schema with an element which is a custom complex type.  This custom type consists of an element whi...

Web resources about - Web Services returning objects; Cannot serialize in Viewstate/Session due to SOAP headers - asp.net.xml-web-services

Resources last updated: 11/29/2015 2:56:50 AM