This is a migrated thread and some comments may be shown as answers.

Posting Registration Data to Remote Server

2 Answers 111 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Alok Tibrewal
Top achievements
Rank 2
Alok Tibrewal asked on 27 Mar 2012, 01:58 PM
Hi Team,

       var objLogin = new Object();
       objLogin.LoginNm = "abc@siplnet.com"
       objLogin.Password = "abcdef"
 
       function fn_Login() {
            scmEventTypeList = {
                model: {}
            };
 
            dsUsrList = kendo.data.DataSource.create({
                schema: scmEventTypeList,
                transport: {
                    read: {
                        url: ServiceUrl,
                        contentType: "application/json; charset=utf-8",
                        dataType: "jsonp"
                    },
                    parameterMap: function(options) {                                      
                        return JSON.stringify(objLogin);    
                    }
                },
                error: function () { alert("Error"); }
            });
 
            $("#ulUsrInfo").kendoMobileListView({
                dataSource: dsUsrList,
                template: $("#TmpUser").html()
            });
        }

I am trying to post registration information to the remote web service. I am not sure what is going wrong here. My Webservice works fine if I use normal ajax method to post.

Any assistance in this is highly appriciated.

2 Answers, 1 is accepted

Sort by
0
Troy Clemons
Top achievements
Rank 1
answered on 27 Mar 2012, 02:44 PM
Do you have this in your Web Service. Please note the Script Methods and the
first Rem line
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
 by default it is like this 
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
'<System.Web.Script.Services.ScriptService()> _


Imports System.Web.Script.Services
Imports System.Web.Script.Serialization
 
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class DSR
Inherits System.Web.Services.WebService
 
<WebMethod(EnableSession:=True)> _
    <ScriptMethod(ResponseFormat:=ResponseFormat.Json)>
public function DoSomething(byval str as string) as string
return str
end function
 
end class
0
Alok Tibrewal
Top achievements
Rank 2
answered on 28 Mar 2012, 02:51 PM
Hi 

We are using WCF Service. In below i attached one of my POST method function which is unable to reach from our Test Kendo App. 

IService.vb
------------------------------------------
    <OperationContract()> _
    <WebInvoke(Method:="POST", RequestFormat:=WebMessageFormat.Json, ResponseFormat:=WebMessageFormat.Json, UriTemplate:="/ValidateUsr2/{Login}")> _
    Function ValidateUsr2(ByVal Login As dtoLogin) As IList(Of dtoUsr)

Service.vb
------------------------------------------
    Function ValidateUsr2(ByVal Login As dtoLogin) As IList(Of dtoUsr) Implements IService.ValidateUsr2
        Dim dUsr As IList(Of dtoUsr) = Nothing
        Try
            CreateTxnClass()
            clsTxnMgnServer.ValidateUsr2_Proc(Login, dUsr)
        Catch ex As Exception
            m_csLog &= "WebService: Error - " & ex.Message & vbNewLine
        Finally
            FinalizeTxnClass()
        End Try
        Return dUsr
    End Function
------------------------------------------
We call this service function from our kendo test app.
------------------------------------------
<body onload="onLoad">
    <div data-role="layout" data-id="default">
        <header data-role="header">
        <div data-role="navbar">
            <span data-role="view-title"></span>
        </div>
        </header>
        <footer data-role="footer" data-id="default">
        <div data-role="tabstrip">
            <a href="#Login" data-icon="contacts">Login</a>
            <a href="#NewUsr" data-icon="contacts">New User</a>
        </div>
        </footer>
    </div>
    <div data-role="view" data-title="Login" id="Login" data-init="fn_Login2">
        <ul id="ulUsrInfo">
        </ul>
    </div>
    <script type="text/x-kendo-template" id="TmpUser">
    <h4 class="item-title">${FirstName}</h4>
    </script>
    <script>
        var ServiceUrl = "http://192.168.1.7/MTServices/Service.svc/";
        var Login = new Object();
        Login.LoginNm = "abc@siplnet.com"
        Login.Password = "abc"


        function fn_Login2() {
            var LoginUrl = ServiceUrl + "ValidateUsr2/";
            scmEventTypeList = {
                model: {}
            };


            dsUsrList = kendo.data.DataSource.create({
                transport: {
                    create: {
                        type: "POST",
                        url: LoginUrl,
                        data: Login,
                        dataType: "jsonp"
                    },
                    parameterMap: function (data) {
                        return JSON.stringify(data);
                    },
                    schema: scmEventTypeList
                },
                error: function () { alert("Error"); }
            });


            $("#ulUsrInfo").kendoMobileListView({
                dataSource: dsUsrList,
                template: $("#TmpUser").html()
            });
        }


    </script>
    <script>
        window.kendoMobileApplication = new kendo.mobile.Application($(document.body), { layout: "default", transition: "slide" });
    </script>
</body>
------------------------------------------
Error: Unable to get value of the property 'data': object is null or undefined
------------------------------------------

service function which are without any parameter and GET only --- its working fine. But while i passing any data to the remote server via jsonp -- its giving error.

Thanks 

Alok
Tags
Data Source
Asked by
Alok Tibrewal
Top achievements
Rank 2
Answers by
Troy Clemons
Top achievements
Rank 1
Alok Tibrewal
Top achievements
Rank 2
Share this question
or