issue with singleton method in calling WCF using JQuery
I created a bare simple method, that just increments a number by 1 and returns the value.
[ServiceContract]
public interface ICalc
{
[OperationContract]
[WebGet(UriTemplate = "getnumber")]
int GetNextNumber();
service class:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class Calculator : ICalc
{
int i = 1;
public int GetNextNumber()
{return i++; }
}
The service is hosted using WebHttpBinding and works well when opened from browser. For example, when I browse http://localhost:8083/Calc/getnumber , I get
<int xmlns="http://schemas.microsoft.com/2003/10/Serialization/">1</int>
Every time I refresh, value keeps incrementing by 1 in xml response (as expected due to singleton behavior)
PROBLEM
When I call the same service using JQuery as:
$.ajax(
{
type: "GET",
url: "http://localhost:8083/Calc/getnumber",
data: "",
contentType: "application/html",
processData: true,
success: function (msg) { alertResult(alert(msg.childNodes[0].xml)) }
}
);
I keep getting the same (latest) number and debugger too is not invoked at service.
What I am not understanding is: If method is not getting called using JQuery, how am I getting valid output and if method is called then why increment is not taking place (which works prop开发者_如何学Cerly if I invoke service just by hitting service url directly from browse)r???
thanks!
Try adding cache: false
to the properties of the ajax request to force the browser to really request the URL everytime as otherwise every sane browser will cache the response for your GET request as your URL doesn't change.
精彩评论