!!继承自SoapHttpClientProtocol的类报错!!

xister 2008-10-23 08:33:13
在微软的网站上:
http://msdn.microsoft.com/zh-cn/library/system.web.services.protocols.soaphttpclientprotocol.aspx
有关于SoapHttpClientProtocol 类的介绍,在介绍中有一个C#示例:
C# 复制代码
namespace MyMath {
using System.Diagnostics;
using System.Xml.Serialization;
using System;
using System.Web.Services.Protocols;
using System.Web.Services;


[System.Web.Services.WebServiceBindingAttribute(Name="MyMathSoap", Namespace="http://www.contoso.com/")]
public class MyMath : System.Web.Services.Protocols.SoapHttpClientProtocol {

[System.Diagnostics.DebuggerStepThroughAttribute()]
public MyMath() {
this.Url = "http://www.contoso.com/math.asmx";
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.contoso.com/Add", RequestNamespace="http://www.contoso.com/", ResponseNamespace="http://www.contoso.com/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public int Add(int num1, int num2) {
object[] results = this.Invoke("Add", new object[] {num1,
num2});
return ((int)(results[0]));
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
public System.IAsyncResult BeginAdd(int num1, int num2, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("Add", new object[] {num1,
num2}, callback, asyncState);
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
public int EndAdd(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((int)(results[0]));
}
}
}

我在Visual Studio 2008中创建了这个类,编译没有问题,代码中也没有错误提示。但当我双击打开时,却报了一个错:


1 Error
WebServiceBindingAttribute is required on proxy classes.




Instances of this error (1)

1. Show Call Stack

at System.Web.Services.Protocols.SoapClientType..ctor(Type type)
at System.Web.Services.Protocols.SoapHttpClientProtocol..ctor()

Help with this error

Could not find an associated help topic for this error. Check Windows Forms Design-Time error list


Forum posts about this error

Search the MSDN Forums for posts related to this error

请高手指点一二,多谢多谢!


...全文
321 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jietuan 2008-10-23
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 findcaiyzh 的回复:]
这个类应该不是你手动创建的,应该是由Wsdl.exe为你创建的,你也可以通过Add Web service(或者reference)创建这个类。
这个类叫proxy类,其实是web service在客户端的代理,你在客户端操作这个类,.net framework 在底层将操作翻译成SoapMessage,发送给web service进行调用。


Wsdl不仅生成一个proxy 类,还有其他一些东西,像config等,所以,你的调用会出错。
[/Quote]


你调用这个类的作用是什么? 看了一下你的代码,你直接添加web service 就可以实现阿!
pvgyetg 2008-10-23
  • 打赏
  • 举报
回复
UP
宝_爸 2008-10-23
  • 打赏
  • 举报
回复
这个类应该不是你手动创建的,应该是由Wsdl.exe为你创建的,你也可以通过Add Web service(或者reference)创建这个类。
这个类叫proxy类,其实是web service在客户端的代理,你在客户端操作这个类,.net framework 在底层将操作翻译成SoapMessage,发送给web service进行调用。


Wsdl不仅生成一个proxy 类,还有其他一些东西,像config等,所以,你的调用会出错。

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧