ajax enabled wcf service does not work after short timehttp://forums.asp.net/t/1786044.aspx/1?ajax+enabled+wcf+service+does+not+work+after+short+timeTue, 03 Apr 2012 02:09:03 -040017860444902802http://forums.asp.net/p/1786044/4902802.aspx/1?ajax+enabled+wcf+service+does+not+work+after+short+timeajax enabled wcf service does not work after short time <p>Hi everyone,</p> <p>I have a problem of wcf service, I built a ajax enabled service, it's quite simple, I am using web.config below created automatically</p> <p>&lt;behaviors&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;endpointBehaviors&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;behavior name=&quot;repkitDocServiceAspNetAjaxBehavior&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;enableWebScript /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/behavior&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/endpointBehaviors&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/behaviors&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;services&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;service name=&quot;repkitDocService&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;endpoint address=&quot;&quot; behaviorConfiguration=&quot;repkitDocServiceAspNetAjaxBehavior&quot;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; binding=&quot;webHttpBinding&quot; contract=&quot;repkitDocService&quot; /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/service&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/services&gt;</p> <p>WCF method code like:</p> <p>[ServiceContract(Namespace = &quot;&quot;)]<br> [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]<br> public class repkitDocService<br> {<br> &nbsp;&nbsp;&nbsp; [OperationContract]<br> &nbsp;&nbsp;&nbsp; [WebInvoke(Method = &quot;POST&quot;, BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json)]<br> &nbsp;&nbsp;&nbsp; public string SubmitRepkitDocCellContent(string tempFile, string itemID, string cell, List&lt;RepkitDocCellContent&gt; contents)<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string result = &quot;&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XDocument xdoc = XDocument.Load(HttpContext.Current.Server.MapPath(tempXmlPath &#43; tempFile));<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var qitem = xdoc.Descendants(&quot;item&quot;).Where(m =&gt; m.Attribute(&quot;id&quot;).Value == itemID);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (qitem.Count() &gt; 0)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ... ...<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return result;<br> &nbsp;&nbsp;&nbsp; }<br> <br> }<br> <br> [DataContract]<br> public class RepkitDocCellContent<br> {<br> &nbsp;&nbsp;&nbsp; [DataMember]<br> &nbsp;&nbsp;&nbsp; public string type { get; set; } <br> &nbsp;&nbsp;&nbsp; [DataMember]<br> &nbsp;&nbsp;&nbsp; public string name { get; set; } <br> &nbsp;&nbsp;&nbsp; [DataMember]<br> &nbsp;&nbsp;&nbsp; public string value { get; set; } <br> }</p> <p>In my frontend page, I use jquery &#36;ajax() transfer json data into this service, when I create this service and frontend page code in just moment, its working well, but after moment, it does not work, can anybody tell me why and how to solve this problem? thanks for any help.</p> 2012-03-28T03:24:51-04:004905112http://forums.asp.net/p/1786044/4905112.aspx/1?Re+ajax+enabled+wcf+service+does+not+work+after+short+timeRe: ajax enabled wcf service does not work after short time <p>Hi steven.ye,</p> <p>According to the service code and configuration fragment you provided, it look ok. When the service call failed, you can use the following means to check the detailed error info:</p> <p>* Use fiddler to watch the HTTP request/response messages to see if it indicates any error details * If possible, debug your WCF service at server-side to see if any exceptions ocurr in the service</p> <p>For WCF service, you can enable the &quot;IncludeExceptionDetails&quot; option in the &lt;serviceBehavior&gt; of your WCF service so that detailed error info will be returned when exceptions occured in WCF service.</p> <p>#ServiceDebugBehavior.IncludeExceptionDetailInFaults Property <br> <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicedebugbehavior.includeexceptiondetailinfaults.aspx">http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicedebugbehavior.includeexceptiondetailinfaults.aspx</a></p> <p>Also, for AJAX-enabled WCF service, it is mainly used by ASP.NET specific AJAX client(by using the &lt;scriptManager&gt; control and script proxy types:</p> <p>#How to: Create an AJAX-Enabled WCF Service and an ASP.NET Client that Accesses the Service <br> <a href="http://msdn.microsoft.com/en-us/library/bb924552.aspx">http://msdn.microsoft.com/en-us/library/bb924552.aspx</a></p> <p>#Access an AJAX Enabled WCF Service using ASP.NET and Client Script <br> <a href="http://www.dotnetcurry.com/ShowArticle.aspx?ID=235">http://www.dotnetcurry.com/ShowArticle.aspx?ID=235</a></p> <p>if you want to use JQuery for WCF service consuming, I'd strongly recommend you create the WCF Service as a pure REST HTTP service. Here are some references about creating WCF REST service and consume it through JQuery client:</p> <p>#WCF Web HTTP Programming Model Overview <br> <a href="http://msdn.microsoft.com/en-us/library/bb412172.aspx">http://msdn.microsoft.com/en-us/library/bb412172.aspx</a></p> <p>#WCF REST Service Template 40(CS) <br> <a href="http://visualstudiogallery.msdn.microsoft.com/fbc7e5c1-a0d2-41bd-9d7b-e54c845394cd">http://visualstudiogallery.msdn.microsoft.com/fbc7e5c1-a0d2-41bd-9d7b-e54c845394cd</a></p> <p>#jQuery AJAX calls to a WCF REST Service <br> <a href="http://www.west-wind.com/weblog/posts/2008/Apr/21/jQuery-AJAX-calls-to-a-WCF-REST-Service">http://www.west-wind.com/weblog/posts/2008/Apr/21/jQuery-AJAX-calls-to-a-WCF-REST-Service</a></p> <p>#Consuming a WCF / ASMX / REST Service using jQuery <br> <a href="http://www.codeproject.com/Articles/59551/Consuming-a-WCF-ASMX-REST-Service-using-jQuery">http://www.codeproject.com/Articles/59551/Consuming-a-WCF-ASMX-REST-Service-using-jQuery</a></p> <p>&nbsp;</p> <p>&nbsp;</p> 2012-03-29T03:06:09-04:004912825http://forums.asp.net/p/1786044/4912825.aspx/1?Re+ajax+enabled+wcf+service+does+not+work+after+short+timeRe: ajax enabled wcf service does not work after short time <p>Thank you very much for your help, buddy</p> 2012-04-03T02:09:03-04:00