是否有必要在Web应用程序中添加Web服务引用或简单服务引用以使用Web服务? [英] Is it necessary to add a web service reference or a simple service reference in a web application to use a web service?
本文介绍了是否有必要在Web应用程序中添加Web服务引用或简单服务引用以使用Web服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有必要在Web应用程序中添加Web服务引用或简单服务引用以使用Web服务。我已经创建了一个用于自动完成但无法从弹出窗口调用它的Web服务。如果我们使用ajax模态弹出窗口我们可以调用写在弹出窗口的同一页面上的Web方法吗?我无法调用它。服务在同一个项目中...请帮助
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
推荐答案
如果该Web服务与您的项目或解决方案一起使用,您不希望添加为项目的Web服务引用/服务引用。
示例你可以使用webservice,
1.使用Ajaxtoolkit
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
<asp:AutoCompleteExtender ID="txtSearchPanel_AutoCompleteExtender" runat="server"
ServiceMethod="GetCompletionList_Popup" ServicePath="~/AutoComplete.asmx"
2.使用javascript
2. using javascript
<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>
它基本上依赖于Web服务,如果它是Restful或ajax启用的serv ice然后你不必添加它的引用,你可以使用HTTP Get / Post协议直接调用它。如果它不是一个restful或ajax启用的Web服务,那么你必须通过添加其服务引用来调用它。
以下代码将显示如何调用restful web方法。
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();
这篇关于是否有必要在Web应用程序中添加Web服务引用或简单服务引用以使用Web服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文