0

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.

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I was thinking the same thing actually, before I posted my response, but I don't see an intuitive way to determine if the HttpContext's current session was created on the current request.
1

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.

3 Comments

Thanks. But is JScript/Infopath the same as JavaScript as implemented in a web browser?
Ok, after testing, it appears that session state is not being retained. I'm going to have to figure out how to pass the cookies in the ajax call.
Ok, it's working after all. I just had a couple bugs in my code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.