Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Is it necessary to add a web service reference or a simple service reference in a web application to use a web service.i have created a web service for autocomplete but not able to call it from popup.If we r using a ajax modal popup can we call a web method written on the same page from which the pop up is called ? I m not able to call it.The service is in the same project...Please help
Posted
Updated 30-Dec-13 20:05pm
v3
Comments
JoCodes 31-Dec-13 2:27am    
Whats your code?
♥…ЯҠ…♥ 31-Dec-13 2:31am    
What do you mean by simple service reference?
pwavell 31-Dec-13 2:52am    
ADD service reference option of project
Sergey Alexandrovich Kryukov 31-Dec-13 2:41am    
Strictly speaking, not. But why would you want it, just to make you work a nightmare? :-)
—SA
pwavell 31-Dec-13 2:55am    
i want to call the autocomplete web method from textbox of ajax modal popup but not able to do it.

Hi,

If that web service is along with your project or solution, You don't want add as a web service reference / sevice reference to your project.

Example you can use webservice,

1. using Ajaxtoolkit

VB
<asp:AutoCompleteExtender ID="txtSearchPanel_AutoCompleteExtender" runat="server"
  ServiceMethod="GetCompletionList_Popup" ServicePath="~/AutoComplete.asmx"


2. using javascript
XML
<script language="JavaScript">
init(){
 service.useService("http://localhost/CursoAspNetWebService/Service1.asmx?WSDL",_
                                                                     "Service1");
}
function tst(){
   iCallID = service.Service1.callService("Suma",ip1.value,ip2.value);
}
function onmyresult(){
   service.innerHTML= "Resultado : " + event.result.value;
}
</script>
<body onLoad="init();">
  <button onclick="javascript:tst()" ID="Button1">Call Add Web Method</button>
  <div id="service" style="BEHAVIOR:url(webservice.htc)" onresult="onmyresult();">
  </div>
</body>
 
Share this answer
 
It basically depends on web service, if it is a Restful or ajax enabled service then you don't have to add its reference, you can directly call it using HTTP Get/Post protocol. If it is not a restful or ajax enabled web service then you have to call it by adding its service reference.

The following code will show how to call a restful web method.

//Get method

WebRequest req = WebRequest.Create(@"http://localhost:61447/Products.svc/");
 
req.Method = "GET";
 
HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
if (resp.StatusCode == HttpStatusCode.OK)
{
    using (Stream respStream = resp.GetResponseStream())
    {
        StreamReader reader = new StreamReader(respStream, Encoding.UTF8);
        Console.WriteLine(reader.ReadToEnd());
    }
}
else
{
    Console.WriteLine(string.Format("Status Code: {0}, Status Description: {1}", resp.StatusCode, resp.StatusDescription));
}
Console.Read();
 
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