我最近要做个webservice开发,但是以前一点没接触过怎么开始开发
2条回答 默认 最新
- 温柔一击_H 2013-08-07 03:10关注
其实web service 不是你想想中的那么难,你在自己的VS 中新建一个WEB应用程序,然后再新建一个web 服务 在这个文件中写一些简单的加法,减法运算等
“using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;namespace WebApplication2
{
///
/// WebService1 的摘要说明
///
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{[WebMethod] public string HelloWorld() { return "Hello World"; } [WebMethod(Description = "求和的方法")] public double additon(double i, double j) { return i + j; } [WebMethod(Description="求差的方法")] public double subtrat(double i, double j) { return i - j; } }
}”
然后再建一个web应用程序,新建一个页面,在BIN文件夹那里引用刚刚的web service 再建一个页面,在后台调用就行了
‘using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
WebApplication2.WebService1 web1 = new WebApplication2.WebService1 ();TextBox1.Text = web1.additon(3, 4).ToString(); }
}’
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报