Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
New Contributor
GautamPowar
Posts: 6
Registered: ‎01-25-2011
My Device: Not Specified

How to call .NET web-service from javascript

[ Edited ]

Hi All, 

           I'm new to blackberry programming. I'm developing a simple login page consisting of username & password. In javascript i need to authenticate the user by calling .net web-service.

 

The code is given below :- login.html

 

 

 

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MS3 Project</title>
  <script type="text/javascript"  src="logic.js"></script>
 

<style type="text/css">
<!--
.style1 {
    font-size: 18px;
    font-weight: bold;
}
-->
</style>

<script type="text/javascript">

   
   var WSresponse = new Array();
   var i;
   
   
   function initPage()
   {
       service.useService("http://59.90.208.182:8080/MS3service/DataService.asmx?WSDL","DataService");
   }
   
   
   function login_info()
   {
      alert("login_info function called");
      
      try
      {
      
         var username = document.getElementById("idUser").value;
         var password = document.getElementById("idPassword").value;
      
      
          alert(username);
          alert(password);
          
                  
          alert("calling web-service");
          
          WSresponse = service.DataService.callService(loginDetails,"Authenticate", username,password);
         
          alert("web-service executed...");
         
        }
        catch(err)
        {
           alert("Error description: " + err.description);
        }  
         
    
      
   }
   
   function loginDetails(result)
   {
      alert("in loginDetails");
      if(result.error)
      {
        alert("ERROR");
      }
      else
      {
        alert("Length of result is ==== "+result.length);
      }
   }


    
    

   
</script>
</head>

<body onload="initPage()">
    <DIV id="service" STYLE="behavior:url(webservice.htc)">
    </DIV>
 
   <form id="login" name="login_form" method="post" action="">
  <table width="100%" border="0">
    <tr>
      <td width="41%">&nbsp;</td>
      <td width="10%">&nbsp;</td>
      <td width="45%">&nbsp;</td>
      <td width="4%">&nbsp;</td>
    </tr>
    <tr>
      <td colspan="4"><div align="center" class="style1">Login Page</div></td>
    </tr>

    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><strong>User Name :</strong></td>
      <td><input type="text" name="txtUserName" id="idUser"  maxlength="15"/></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><strong>Password :</strong></td>
      <td><input type="password" name="txtPassword" id="idPassword" maxlength="15"/></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td align="center"><input type="button" name="submitButton" id="submitBtn" value="Submit" onclick="login_info()"/> </td>
      <td>&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" name="resetButton" id="resetBtn" value="Reset" /></td>
      <td>&nbsp;</td>
    </tr>
  </table>
 
</form>
</body>
</html>

 

 

 

 

 

For this I'm getting foll. exception in catch block :- "service.DataService" is null or not an object.

 

 

Sorry, If i've made any silly mistake. Please guide me for this.

 

 

Retired
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: How to call .NET web-service from javascript

Have you checked out the following post?

 

http://supportforums.blackberry.com/t5/Web-Development/How-quot-I-quot-would-call-a-web-service-from...

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
New Contributor
GautamPowar
Posts: 6
Registered: ‎01-25-2011
My Device: Not Specified

Re: How to call .NET web-service from javascript

Thanks Tim..  My problem has been solved.

 

Your link was also helpful for me.. got some new to learn.

Please inform me about Blackberry Playbook Applications. I am developing applications on it.

 

Looking forward to your positive response. :smileyhappy:

 

Retired
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: How to call .NET web-service from javascript

What type of specific information are you looking for around PlayBook WebWorks development?  We should be able to point you in the right direction.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter