【发布时间】:2009-11-03 21:19:06
【问题描述】:
我有这个网络服务:
using System.Web.Services;
namespace Contracts
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class Second : System.Web.Services.WebService
{
[WebMethod]
public string GetContract()
{
return "Contract 1";
}
}
}
以下 WPF 应用程序可以很好地显示 HTML:
using System.Windows;
using System.Net;
using System;
namespace TestConsume2343
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
WebClient proxy = new WebClient();
proxy.DownloadStringCompleted += new DownloadStringCompletedEventHandler(proxy_DownloadStringCompleted);
proxy.DownloadStringAsync(new Uri("http://localhost:57379/Second.asmx?op=GetContract"));
Message.Text = "loading...";
}
void proxy_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
Message.Text = e.Result.ToString();
}
}
}
但是当我用 实际的网络服务替换上面的行时:
proxy.DownloadStringAsync(new Uri("http://localhost:57379/Second.asmx/GetContract"));
它给了我错误消息:
远程服务器返回错误 (500) Internal Server Error。
虽然当我在浏览器中查看相同的 URL 时,我看到了 XML 文本 fine:
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">Contract 1</string>
为什么会出现 500 错误?
【问题讨论】:
标签: c# web-services