小弟我初学Web Services 没有找到门道,请各位同行先进给我指导指导!
小弟我初学VS2005,想写一个Web Services的程序。
Web Services 代码 如下:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod(Description = "计算两个整数相加的和")]
public int Add(int x, int y)
{
return x + y;
}
}
调用ASP.NET 调用 代码如下:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int x, y;
try
{
x = int.Parse(TextBox1.Text);
y = int.Parse(TextBox2.Text);
}
catch(Exception ex)
{
return;
}
MyWebService.Service service = new MyWebService.Service();
Label1.Text = service.Add(x, y).ToString();
}
}
运行后 出错
The request failed with HTTP status 401: Unauthorized
是不是我没有发布这个Web Services的缘故?
我该如何发布一个Web Services?
或者大家给我推荐一些好一点的资料, 我还没有入门啊。
照着书上的Demo写的第一个程序就这样失败了。
很受打击.....大家帮帮我。
问题点数:50、回复次数:6Top
1 楼zhanqiangz(闲云野鹤-Overriding)回复于 2006-03-10 11:15:46 得分 45
检查你的webservice建立的时候是用的file system还是http如果是前者必须在build-in webserver启动的时候才可以访问的,因为用的不是iis。
http://community.csdn.net/Expert/topic/4596/4596345.xml?temp=.5656397
Top
2 楼dNETstart()回复于 2006-03-10 12:46:34 得分 0
谢谢 zhanqiangz(闲云野鹤-Overriding)
吃过饭后试了一下,在用http类型建立后果然可以了。
不过我还想请教一下,通过file system建立的web services 我在IIS中手工添加了虚拟目录的。
在查找Web Services的时候也找到了个这个Web Services,就是不能调用,为什么??
Top
3 楼zhanqiangz(闲云野鹤-Overriding)回复于 2006-03-10 12:59:49 得分 0
过file system建立的web services 我在IIS中手工添加了虚拟目录的。
===================================================
你如何创建的?报的什么错误?Top
4 楼cyy1981(McRain)回复于 2006-03-10 14:21:58 得分 0
应该添加web引用吧Top
5 楼dNETstart()回复于 2006-03-10 15:51:50 得分 0
TO:zhanqiangz(闲云野鹤-Overriding)
问题已经解决了,我只是想知道如果我通过 file system 建立的 Web Services
该如何发布才能让我的ASP.NET客户程序调用呢?
Top
6 楼flashicp(flashicp)回复于 2006-03-13 10:02:43 得分 5
推荐一本好书net web服务开发里面从最基本的一直到专家级的书也不厚是电子工业的不错的
你看下这段代码
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int x, y;
try
{
x = int.Parse(TextBox1.Text);
y = int.Parse(TextBox2.Text);
}
catch(Exception ex)
{
return;
}
MyWebService.Service service = new MyWebService.Service();
Label1.Text = service.Add(x, y).ToString();
}
}
把异常放在webservices上还有你直接访问下你的asmx?wsdl看可以访问么Top




