在asp.net网页上调用Web方法 [英] Call web method on asp.net web page
本文介绍了在asp.net网页上调用Web方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
有没有人知道如何在asp.net网页上调用Web方法?我正在尝试在网页上调用Web方法.当前,我已经尝试在C#Web窗体上调用Web方法,但是我需要在asp.net网页上执行此操作.以下是我关于Web方法和C#Web应用程序的代码.
Hi everyone,
Does anyone have any idea on how to call web method on asp.net web page? I am trying on calling web method on a web page. Currently, I have tried calling the web method on C# Web Form, but i need to do this on asp.net web page. The following is my code on web method and C# web application.
private void button3_Click(object sender, EventArgs e)
{
RequestWS.Service rWS = new RequestWS.Service();
int result = rWS.DoIT();
if (result > 0)
{
MessageBox.Show("YES! WE ARE SUCEEDDED!");
}
else
{
MessageBox.Show("Invalid IpAddress");
}
}
[WebMethod]
public int DoIT()
{
// Get the hostname
string myHost = System.Net.Dns.GetHostName();
string connect = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=c:\\inetpub\\wwwroot\\RequestWS\\App_Data\\TV.mdb";
string query = "SELECT COUNT(IPAddress) FROM Request WHERE IPAddress = ?";
int result = 0;
using (OleDbConnection conn = new OleDbConnection(connect))
{
using (OleDbCommand cmd = new OleDbCommand(query, conn))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("IPAddress", myHost);
conn.Open();
result = (int)cmd.ExecuteScalar();
}
}
return result;
}
推荐答案
感谢您的发帖!我建议在位于以下位置的asp.net论坛中为您的问题创建一个新线程: ( http://forums.asp.net/).
Hello,
Thank you for your post! I would suggest creating a new thread for your question in the asp.net forum located here: (http://forums.asp.net/).
希望会有所帮助.
祝您度过愉快的一天!
感谢&问候,
这篇关于在asp.net网页上调用Web方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文