标准的HelloWorld为啥不行?好心人帮忙指点一下!
照着msdn copy的,总是报这个错
"该服务器提交了 HTTP 协议冲突"
好心人帮忙指点一下!
Client:
private void Button1_Click(object sender, System.EventArgs e)
{
try
{
Service1 service=new Service1();
this.Label1.Text=service.HelloWorld();
}
catch(WebException we)
{
}
}
Server:
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
异常详细信息: System.Net.WebException: 基础连接已经关闭: 该服务器提交了 HTTP 协议冲突。//错误代码:ServerProtocolViolation
源错误:
行 41: [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/HelloWorld", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
行 42: public string HelloWorld() {
行 43: object[] results = this.Invoke("HelloWorld", new object [0]); //{此行错误}
行 44: return ((string)(results[0]));
行 45: }
看现象象是客户端没有找到Webservice地址。
在客户端调用WebService需要设置WebService的地址,如果你的客户端的Web引用的Url行为(在其属性中)设为静态,则客户端会根据你编辑状态下引用地址去查找Webservice,如果你的客户端的Web引用的Url行为(在其属性中)设为动态,则客户端会自动生成一个文件名与程序Exe一致的Config文件,运行时你可以改Config文件中的Webservice地址。
private void Button1_Click(object sender, System.EventArgs e)
{
try
{
Service1.localhost service=new Service1.localhost();///改改,看看是不是这里的问题
this.Label1.Text=service.HelloWorld();
}
catch(WebException we)
{
}
}
Server:
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}