SoapHttpClientProtocol 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指定代理在使用 SOAP 时派生自的类客户端。
public ref class SoapHttpClientProtocol : System::Web::Services::Protocols::HttpWebClientProtocol
public class SoapHttpClientProtocol : System.Web.Services.Protocols.HttpWebClientProtocol
[System.Runtime.InteropServices.ComVisible(true)]
public class SoapHttpClientProtocol : System.Web.Services.Protocols.HttpWebClientProtocol
type SoapHttpClientProtocol = class
inherit HttpWebClientProtocol
[<System.Runtime.InteropServices.ComVisible(true)>]
type SoapHttpClientProtocol = class
inherit HttpWebClientProtocol
Public Class SoapHttpClientProtocol
Inherits HttpWebClientProtocol
- 继承
- 属性
示例
下面的代码示例是由 XML Math Web 服务 Wsdl.exe 生成的代理类。 代理类派生自 SoapHttpClientProtocol抽象 WebClientProtocol 类。
#using <System.Web.Services.dll>
#using <System.Xml.dll>
#using <System.dll>
using namespace System::Diagnostics;
using namespace System::Xml::Serialization;
using namespace System;
using namespace System::Web::Services::Protocols;
using namespace System::Web::Services;
namespace MyMath
{
[System::Web::Services::WebServiceBindingAttribute(Name="MyMathSoap",Namespace="http://www.contoso.com/")]
public ref class MyMath: public System::Web::Services::Protocols::SoapHttpClientProtocol
{
public:
[System::Diagnostics::DebuggerStepThroughAttribute]
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)]
int Add( int num1, int num2 )
{
array<Object^>^temp0 = {num1,num2};
array<Object^>^results = this->Invoke( "Add", temp0 );
return *dynamic_cast<int^>(results[ 0 ]);
}
[System::Diagnostics::DebuggerStepThroughAttribute]
System::IAsyncResult^ BeginAdd( int num1, int num2, System::AsyncCallback^ callback, Object^ asyncState )
{
array<Object^>^temp1 = {num1,num2};
return this->BeginInvoke( "Add", temp1, callback, asyncState );
}
[System::Diagnostics::DebuggerStepThroughAttribute]
int EndAdd( System::IAsyncResult^ asyncResult )
{
array<Object^>^results = this->EndInvoke( asyncResult );
return *dynamic_cast<int^>(results[ 0 ]);
}
};
}
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]));
}
}
}
Option Strict On
Option Explicit On
Imports System.Diagnostics
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml.Serialization
Namespace MyMath
<System.Web.Services.WebServiceBindingAttribute(Name:="MyMathSoap", [Namespace]:="http://www.contoso.com/")> _
Public Class MyMath
Inherits System.Web.Services.Protocols.SoapHttpClientProtocol
<System.Diagnostics.DebuggerStepThroughAttribute()> _
Public Sub New()
MyBase.New
Me.Url = "http://www.contoso.com/math.asmx"
End Sub
<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 Function Add(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
Dim results() As Object = Me.Invoke("Add", New Object() {num1, num2})
Return CType(results(0),Integer)
End Function
<System.Diagnostics.DebuggerStepThroughAttribute()> _
Public Function BeginAdd(ByVal num1 As Integer, ByVal num2 As Integer, ByVal callback As System.AsyncCallback, ByVal asyncState As Object) As System.IAsyncResult
Return Me.BeginInvoke("Add", New Object() {num1, num2}, callback, asyncState)
End Function
<System.Diagnostics.DebuggerStepThroughAttribute()> _
Public Function EndAdd(ByVal asyncResult As System.IAsyncResult) As Integer
Dim results() As Object = Me.EndInvoke(asyncResult)
Return CType(results(0),Integer)
End Function
End Class
End Namespace
下面的代码示例是 Math 生成上述代理类的 XML Web 服务。
Important
此示例有一个接受用户输入的文本框,这是潜在的安全威胁。 默认情况下,ASP.NET 网页验证用户输入是否不包含脚本或 HTML 元素。 有关详细信息,请参阅 脚本攻击概述。
<%@ WebService Language="C#" Class="MyMath"%>
using System.Web.Services;
using System;
[WebService(Namespace="http://www.contoso.com/")]
public class MyMath {
[ WebMethod ]
public int Add(int num1, int num2) {
return num1+num2;
}
}
<%@ WebService Language="VB" Class="MyMath"%>
Imports System.Web.Services
Imports System
<WebService(Namespace:="http://www.contoso.com/")> _
Public Class MyMath
<WebMethod()> _
Public Function Add(num1 As Integer, num2 As Integer) As Integer
Return num1 + num2
End Function 'Add
End Class 'Math
注解
如果要生成 XML Web 服务客户端,则必须为 XML Web 服务创建间接派生或直接 WebClientProtocol 派生的代理类。 当 XML Web 服务客户端使用 SOAP 调用时,代理类必须派生自SoapHttpClientProtocol该类,该类派生自 。HttpWebClientProtocol HttpWebClientProtocol反过来,派生自 WebClientProtocol。
若要与 XML Web 服务通信,请为要调用的 XML Web 服务创建间接派生或直接 WebClientProtocol 派生的代理类。 使用 Web 服务描述语言工具(Wsdl.exe)为给定 XML Web 服务的服务说明创建代理类,而不是手动创建代理类。 为 SOAP 协议生成代理类时,将通过 Invoke 该方法对 XML Web 服务方法进行同步调用,而异步调用则使用 BeginInvoke 该方法和 EndInvoke 方法进行。
继承者说明
重写此类时,可以在派生类中引入特定于特定类型的 XML Web 服务的方法。 这些方法捕获参数并调用基类来执行与 XML Web 服务通信的工作。 如果引入的方法是异步的,请调用该方法 BeginInvoke(String, Object[], AsyncCallback, Object) 和 EndInvoke(IAsyncResult) 方法。 如果引入的方法是同步的,请调用该方法 Invoke(String, Object[]) 。 重写的构造函数通常将 Url 属性设置为 XML Web 服务方法的 URL。
构造函数
| 名称 | 说明 |
|---|---|
| SoapHttpClientProtocol() |
初始化 SoapHttpClientProtocol 类的新实例。 |
属性
| 名称 | 说明 |
|---|---|
| AllowAutoRedirect |
获取或设置客户端是否自动遵循服务器重定向。 (继承自 HttpWebClientProtocol) |
| CanRaiseEvents |
获取一个值,该值指示组件是否可以引发事件。 (继承自 Component) |
| ClientCertificates |
获取客户端证书的集合。 (继承自 HttpWebClientProtocol) |
| ConnectionGroupName |
获取或设置请求的连接组的名称。 (继承自 WebClientProtocol) |
| Container |
IContainer获取包含 .Component (继承自 Component) |
| CookieContainer |
获取或设置 Cookie 的集合。 (继承自 HttpWebClientProtocol) |
| Credentials |
获取或设置 XML Web 服务客户端身份验证的安全凭据。 (继承自 WebClientProtocol) |
| DesignMode |
获取一个值,该值指示当前是否 Component 处于设计模式。 (继承自 Component) |
| EnableDecompression |
获取或设置一个值,该值指示是否为此 HttpWebClientProtocol启用解压缩。 (继承自 HttpWebClientProtocol) |
| Events |
获取附加到此 Component对象的事件处理程序的列表。 (继承自 Component) |
| PreAuthenticate |
获取或设置是否启用预身份验证。 (继承自 WebClientProtocol) |
| Proxy |
获取或设置通过防火墙发出 XML Web 服务请求的代理信息。 (继承自 HttpWebClientProtocol) |
| RequestEncoding |
Encoding用于向 XML Web 服务发出客户端请求。 (继承自 WebClientProtocol) |
| Site | (继承自 Component) |
| SoapVersion |
获取或设置用于向 XML Web 服务发出 SOAP 请求的 SOAP 协议的版本。 |
| Timeout |
指示 XML Web 服务客户端等待对同步 XML Web 服务请求的回复到达的时间(以毫秒为单位)。 (继承自 WebClientProtocol) |
| UnsafeAuthenticatedConnectionSharing |
获取或设置一个值,该值指示客户端使用 NTLM 身份验证连接到承载 XML Web 服务的 Web 服务器时是否启用连接共享。 (继承自 HttpWebClientProtocol) |
| Url |
获取或设置客户端请求的 XML Web 服务的基 URL。 (继承自 WebClientProtocol) |
| UseDefaultCredentials |
获取或设置一个值,该值指示是否将 Credentials 属性设置为该属性的值 DefaultCredentials 。 (继承自 WebClientProtocol) |
| UserAgent |
获取或设置随每个请求一起发送的用户代理标头的值。 (继承自 HttpWebClientProtocol) |
方法
活动
| 名称 | 说明 |
|---|---|
| Disposed |
当组件通过对方法的调用 Dispose() 释放时发生。 (继承自 Component) |
适用于
线程安全性
此类型是线程安全的。