HttpMethodAttribute 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
如果使用 HTTP-GET 或 HTTP-POST 将此特性应用于 XML Web services 客户端,则可设置特定的类型,它们对发送到 XML Web services 方法的参数进行序列化并从 XML Web services 方法读取响应。 此类不能被继承。
public ref class HttpMethodAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Method)]
public sealed class HttpMethodAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Method, Inherited=true)]
public sealed class HttpMethodAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Method)>]
type HttpMethodAttribute = class
inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Method, Inherited=true)>]
type HttpMethodAttribute = class
inherit Attribute
Public NotInheritable Class HttpMethodAttribute
Inherits Attribute
- 继承
- 属性
示例
以下示例是由Wsdl.exe实用工具生成的代理类,用于使用 HTTP-POST 调用 XML Web 服务实用工具。 Wsdl.exe会自动提供正确的类型ReturnFormatterParameterFormatter,并指定代理类继承自HttpPostClientProtocol该类型。
[System::Xml::Serialization::XmlRootAttribute(Namespace="http://tempuri.org/",IsNullable=true)]
public ref class UserName
{
public:
String^ Name;
String^ Domain;
};
public ref class MyUser: public System::Web::Services::Protocols::HttpPostClientProtocol
{
public:
MyUser()
{
this->Url = "http://www.contoso.com/username.asmx";
}
[System::Web::Services::Protocols::HttpMethodAttribute(System::Web::Services::Protocols::XmlReturnReader::typeid,System::Web::Services::Protocols::HtmlFormParameterWriter::typeid)]
UserName^ GetUserName()
{
return (dynamic_cast<UserName^>(this->Invoke( "GetUserName", (String::Concat( this->Url, "/GetUserName" )), gcnew array<Object^>(0) )));
}
System::IAsyncResult^ BeginGetUserName( System::AsyncCallback^ callback, Object^ asyncState )
{
return this->BeginInvoke( "GetUserName", (String::Concat( this->Url, "/GetUserName" )), gcnew array<Object^>(0), callback, asyncState );
}
UserName^ EndGetUserName( System::IAsyncResult^ asyncResult )
{
return (dynamic_cast<UserName^>(this->EndInvoke( asyncResult )));
}
};
public class MyUser : System.Web.Services.Protocols.HttpPostClientProtocol
{
public MyUser()
{
this.Url = "http://www.contoso.com/username.asmx";
}
[System.Web.Services.Protocols.HttpMethodAttribute(typeof(System.Web.Services.Protocols.XmlReturnReader), typeof(System.Web.Services.Protocols.HtmlFormParameterWriter))]
public UserName GetUserName()
{
return ((UserName)(this.Invoke("GetUserName", (this.Url + "/GetUserName"), new object[0])));
}
public System.IAsyncResult BeginGetUserName(System.AsyncCallback callback, object asyncState)
{
return this.BeginInvoke("GetUserName", (this.Url + "/GetUserName"), new object[0], callback, asyncState);
}
public UserName EndGetUserName(System.IAsyncResult asyncResult)
{
return ((UserName)(this.EndInvoke(asyncResult)));
}
}
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://tempuri.org/", IsNullable=true)]
public class UserName
{
public string Name;
public string Domain;
}
Public Class MyUser
Inherits System.Web.Services.Protocols.HttpPostClientProtocol
Public Sub New()
Me.Url = "http://www.contoso.com/username.asmx"
End Sub
<HttpMethodAttribute(GetType(XmlReturnReader), GetType(HtmlFormParameterWriter))> _
Public Function GetUserName() As UserName
Return CType(Me.Invoke("GetUserName", Me.Url + "/GetUserName", New Object(0) {}), UserName)
End Function 'GetUserName
Public Function BeginGetUserName(callback As System.AsyncCallback, asyncState As Object) As System.IAsyncResult
Return Me.BeginInvoke("GetUserName", Me.Url + "/GetUserName", New Object(0) {}, callback, asyncState)
End Function 'BeginGetUserName
Public Function EndGetUserName(asyncResult As System.IAsyncResult) As UserName
Return CType(Me.EndInvoke(asyncResult), UserName)
End Function 'EndGetUserName
End Class
<XmlRootAttribute(Namespace := "http://tempuri.org/", IsNullable := True)> _
Public Class UserName
Public Name As String
Public Domain As String
End Class
注解
如果 XML Web 服务客户端使用 HTTP-GET 调用 XML Web 服务方法, ReturnFormatter 则必须设置为 XmlReturnReader
并 ParameterFormatter 设置为 UrlParameterWriter
。 XML Web service clients invoking a XML Web service using HTTP-POST must set ReturnFormatter to XmlReturnReader
and ParameterFormatter to HtmlFormParameterWriter
.
构造函数
HttpMethodAttribute() |
初始化 HttpMethodAttribute 类的新实例。 |
HttpMethodAttribute(Type, Type) |
初始化 HttpMethodAttribute 的新实例。 |
属性
ParameterFormatter |
获取或设置一个 Type,它对从 XML Web services 客户端发送到 XML Web services 方法的参数进行序列化。 |
ReturnFormatter |
获取或设置一个 Type,它对来自 XML Web services 方法的响应进行反序列化。 |
TypeId |
在派生类中实现时,获取此 Attribute 的唯一标识符。 (继承自 Attribute) |
方法
Equals(Object) |
返回一个值,该值指示此实例是否与指定的对象相等。 (继承自 Attribute) |
GetHashCode() |
返回此实例的哈希代码。 (继承自 Attribute) |
GetType() |
获取当前实例的 Type。 (继承自 Object) |
IsDefaultAttribute() |
在派生类中重写时,指示此实例的值是否是派生类的默认值。 (继承自 Attribute) |
Match(Object) |
当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。 (继承自 Attribute) |
MemberwiseClone() |
创建当前 Object 的浅表副本。 (继承自 Object) |
ToString() |
返回表示当前对象的字符串。 (继承自 Object) |
显式接口实现
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
将一组名称映射为对应的一组调度标识符。 (继承自 Attribute) |
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
检索对象的类型信息,然后可以使用该信息获取接口的类型信息。 (继承自 Attribute) |
_Attribute.GetTypeInfoCount(UInt32) |
检索对象提供的类型信息接口的数量(0 或 1)。 (继承自 Attribute) |
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
提供对某一对象公开的属性和方法的访问。 (继承自 Attribute) |