Reputation: 4164
I'm trying to consume an ASP.NET web service, using jQuery's Ajax methods. I want the return type of the web service method to be JSON-formatted data, and I'm marking the method with these attributes:
[WebMethod(EnableSession = true)]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public MyObject[] GetMyObjects(int pageIndex) {/*...*/}
I want to also return from the method some sort of value that would indicate whether the session has expired, either in the SOAP headers an output parameter. How would I do this with jQuery syntax? Should I wrap my MyObject[]
array in a serializable ResponseType object that contains a SessionValid property and the payload? Or is it possible to use SOAP headers and output parameters with jQuery?
Thanks.
Upvotes: 0
Views: 3601
Reputation: 3601
I'm not completely familiar with using session in SOAP web services. However, I did stumble on this post which states that the JavaScript will need to account for cookies since this is how the session is maintained.
Although, SOAP may use a different method for tracking session via it's headers, so I don't know if this is accurate.
Upvotes: 1
Reputation: 22392
Should I wrap my MyObject[] array in a serializable ResponseType object that contains a SessionValid property and the payload?
This is the way I usually go with.
Not time consuming to implement and very easy to maintain.
[Serializable]
public class MyReturn
{
public MyObject[] MyObjectList { get; set; }
public bool SessionExpired { get; set; }
}
Then handle it where you do the AJAX call.
EDIT: I usually only use
//...
contentType: "application/json; charset=utf-8",
dataType: "json",
//...
in my AJAX calls to be sure the returned type is in JSON format.
Upvotes: 1