开发者

Error handling with Javascript-enabled WCF?

Is there documentation on how to use the callback functions in a WCF Service that is exposed to Javascript? I'm interested in getting information from the FailureCallback as to why my method isn't firing.

In other words I have the follwoing JavaScript code:

     function getWCF_RowNumber(parentID) {
              logEvent("<strong>Busy</strong>: Please wait while lower grid is refreshed...");                  
              var service = new ajaxTest();
              service开发者_StackOverflow中文版.Vendor_GetParentRowNumber(parentID, moveBottomGridToRow, wcfFailCallback, null);
          }

How do I implement wcfFailCallback?


I'm assuming you're using ASP.NET AJAX and not jQuery or some other 3rd party JavaScript library.

The ASP.NET AJAX failure callback takes a single parameter. From MSDN, a sample failure callback would look like this:

function wcfFailCallback(error)
{
    var stackTrace = error.get_stackTrace();
    var message = error.get_message();
    var statusCode = error.get_statusCode();
    var exceptionType = error.get_exceptionType();
    var timedout = error.get_timedOut();

    // Display the error.    
    var RsltElem = 
        document.getElementById("Results");
    RsltElem.innerHTML = 
        "Stack Trace: " +  stackTrace + "<br/>" +
        "Service Error: " + message + "<br/>" +
        "Status Code: " + statusCode + "<br/>" +
        "Exception Type: " + exceptionType + "<br/>" +
        "Timedout: " + timedout;
}

So the wcfFailCallback function takes an error parameter, which has a number of properties that provide you information about what failed.

The full article on MSDN is here. It goes into some decent amount of details about how to hook up WCF services to ASP.NET AJAX clients.

I hope this helps!! If there are other questions or if I didn't fully understand your question, let me know and I'll update my answer accordingly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜