[1.2] DirectMethod.request, webservice and success/failure

  1. #1

    [1.2] DirectMethod.request, webservice and success/failure

    Hi

    I have implemented DirectMethod to call a webservice in order to validate soecfic edits in a gridpanel
    It is working well, I just wonder if there is any way I can make use of the failure in case the validation comes out with "not valid"?

    My implemtation is more or less a copy of the this example
    https://examples1.ext.net/#/Events/D...ds/WebService/

    I'd like to return a failure response if possible, but how?
    Otherwise I will extend my success response and extend my javascript invoked in case of a "success"

    Thanks in advance /Peter
  2. #2
    Hi,

    Please just set up "success = false" in a response's root.

    Example Page
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net Example</title>
    
        <script type="text/javascript">
            var onClick = function (method) {
                Ext.net.DirectMethod.request({
                    url          : "WebService1.asmx/" + method,
                    cleanRequest : true,
                    json         : true,
                    success      : function (result) {
                        alert("success");
                    },
                    failure      : function (result) {
                        alert("failure");
                    }
                });
            };
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:Button runat="server" Text="Success">
                <Listeners>
                    <Click Handler="onClick('Success');" />
                </Listeners>
            </ext:Button>
            <ext:Button runat="server" Text="Failure">
                <Listeners>
                    <Click Handler="onClick('Failure');" />
                </Listeners>
            </ext:Button>
        </form>
    </body>
    </html>
    Example WebService
    using System.Web.Services;
    using Ext.Net;
    using System.Web.Script.Services;
    
    namespace Work
    {
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [ScriptService]
        public class WebService1 : WebService
        {
            [WebMethod]
            public object Success()
            {
                return new { data = new { Test = "Hello World!" }, success = true };
            }
    
            [WebMethod]
            public object Failure()
            {
                return new { data = new { Test = "Hello World!" }, success = false };
            }
        }
    }
  3. #3
    Thanks Daniil

    - Peter
  4. #4
    Quote Originally Posted by Daniil View Post
    Please just set up "success = false" in a response's root.
    Ups I have a problem with my failure function

    Add console.log to the javascript and run the sample in Chrome, when failure is called (setting succes eq false) the result parameter is "undefined"
    I need to return a message to the user from my webmethod

    <script type="text/javascript">    var onClick = function (method) {
            Ext.net.DirectMethod.request({
                url          : "WebService1.asmx/" + method,
                cleanRequest : true,
                json         : true,
                success      : function (result) {
                    console.log(result);
                    alert("success");
                },
                failure      : function (result) {
                    console.log(result);
                    alert("failure");
                }
            });
        };
    Thanks /Peter
  5. #5
    The first argument is an error message.
    Ext.net.DirectMethod.request({
        url          : "WebService1.asmx/" + method,
        cleanRequest : true,
        json         : true,
        success      : function (result) {
            alert("success");
        },
        failure      : function (errorMessage, response, extraParams, o) {
            alert(errorMessage);
        }
    });
    
    [WebMethod]
    public object Failure()
    {
        return new { errorMessage = "some error", success = false };
    }
  6. #6
    Working like a charm

    Hmm I need to dig in to this ExtJS stuff some more
    From time to time it's like a impenetrable black box :-)

    rgds /Peter
  7. #7
    In this case it's Ext.Net stuff:)

    The debug mode should help you much: VS + "debugger" in JavaScript code.

    Example
    failure      : function () {
        debugger;
    }
    Then a pair of F10 and you are in the Ext.Net scripts, where you will see the failure handler's arguments.
  8. #8
    Also I'm curious why you are still not a premium member:)

    It would be great to see such intelligent person on the Premium Help forum:)

Similar Threads

  1. DirectMethod success and failure not working
    By mtrutledge in forum 1.x Help
    Replies: 3
    Last Post: Mar 14, 2012, 1:08 PM
  2. [CLOSED] Ext.net.DirectEvent.request don't fire my success function
    By emmanuel.sans.domenech in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jan 06, 2012, 10:32 AM
  3. Replies: 16
    Last Post: Oct 04, 2011, 5:17 PM
  4. Replies: 2
    Last Post: Dec 01, 2010, 10:14 AM
  5. Request Failure!
    By jachnicky in forum 1.x Help
    Replies: 0
    Last Post: Dec 11, 2008, 3:26 AM

Posting Permissions