Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to web services but basically i have created a webservice that reads from a db and then returns a value back to the client. Here is an example of my webservice.

C#
namespace TestWebService1
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {

        [WebMethod]
        [ScriptMethod(UseHttpGet=true)]
        public string getID()
        {
            SqlConnection cs = new SqlConnection(@"Server=130-ASQL1-B-001.OSCD.LOCAL;Initial Catalog=AIM;User ID=user;Password=pass");

            SqlCommand cmd = new SqlCommand("select id from NIM where stationName='" + System.IO.Path.GetDirectoryName(HttpContext.Current.Request.ServerVariables["REMOTE_USER"]) + "' and availability = 'reachable'", cs);

            cmd.CommandType = CommandType.Text;

            cmd.Connection = cs;

            cs.Open();

            SqlDataReader dr = cmd.ExecuteReader();


            dr.Read();
            
                return dr["id"].ToString();

                dr.Close();
                cs.Close();
  
            
        }
    }
}


Ok now I would like to call this web service from an html page

HTML
<div style="display: hidden;">
<form action='http://localhost:52618/Service1.asmx/HelloWorld?ID='
method="get" target="_self">
<table>
  <tr>
    <td>GET ID</td>
    <td>
    <input class="frmInput" type="text" size="30" name="id">
    </td>
  </tr>
  <tr>
    <td></td>
    <td align="right">
     <input type="submit" id="submitButton" value="Submit" class="button">
     </td>
  </tr>
</table>
</form>
<script language="javascript">
        document.getElementById("submitButton").click();
    </script>
</div>


the soap message that appears is below.

XML
<?xml version="1.0" encoding="UTF-8"?>
<string xmlns="http://tempuri.org/">0</string>


So far i am able to call the web service fine but what happens is it calls the web service and display the soap message on the webpage within the browser. I would like to somehow show the value of my soap message in the url like http://localhost:52618/Service1.asmx/HelloWorld?ID=42 or something like that. I know this can be done from the examples i've seen but i'm obviously not doing something right on either the web service or client side. Also i'm not exactly sure that this is the best way to call a web service from an html page so if anyone has any knowledge on that that would be great as well. I am having to use javascript but it would be nice just use html. Any Help is Appreciated!
Posted
Updated 24-Jun-13 4:34am
v3
Comments
Mahesh Bailwal 23-Jun-13 4:56am    
can you share your soap message.
Dustin Prevatt 24-Jun-13 10:33am    
adding the soap message...
eng.amir.ebrahimi 23-Jun-13 6:07am    
Read AJAX ...if you wanna call a webservice in your web application ...The best way is AJAX !
Dustin Prevatt 24-Jun-13 10:35am    
I need to find out a way to call this from a plain html page and somehow store the soap message data (which in this case is 0) to a variable or something so that it can be reused. Can i use ajax without it being an asp.net page?
Ahmed Bensaid 24-Jun-13 10:44am    
Yes you can ... you can use AJAX with javascript or with the jQuery library ... without being in an asp.net page ;)

1 solution

Follow - Calling ASMX from jQuery[^] for a simple example.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900