创建一个 Web 服务代理对象,用于在 Windows PowerShell 中使用和管理 Web 服务。
语法
New-WebServiceProxy [-URI] <Uri> [[-类] <string>] [[-命名空间] <string>] [<CommonParameters>] New-WebServiceProxy [-URI] <Uri> [[-类] <string>] [[-命名空间] <string>] [-Credential <PSCredential>] [<CommonParameters>] New-WebServiceProxy [-URI] <Uri> [[-类] <string>] [[-命名空间] <string>] [-UseDefaultCredential] [<CommonParameters>]
说明
New-WebServiceProxy cmdlet 使您可以在 Windows PowerShell 中使用 Web 服务。该 cmdlet 连接到 Web 服务,并在 Windows PowerShell 中创建 Web 服务代理对象。您可以使用代理对象管理 Web 服务。
Web 服务是一种基于 XML 的程序,用于在网络(特别是 Internet)上交换数据。Microsoft .NET Framework 提供了将 Web 服务表示为 .NET Framework 对象的 Web 服务代理对象。
参数
-类 <string>
指定该 cmdlet 为 Web 服务创建的代理类的名称。此参数的值与 Namespace 参数的值一起使用时,可提供该类的完全限定名称。默认值从 URI 生成。
是否为必需? |
false |
位置? |
2 |
默认值 |
Generated from the URI |
是否接受管道输入? |
false |
是否接受通配符? |
false |
-Credential <PSCredential>
指定有权执行此操作的用户帐户。默认值为当前用户。这是使用 UseDefaultCredential 参数的替代方法。
键入用户名,例如“User01”或“Domain01\User01”。或者,输入 PSCredential 对象,例如由 Get-Credential cmdlet 生成的对象。如果键入用户名,则将提示您输入密码。
是否为必需? |
false |
位置? |
named |
默认值 |
|
是否接受管道输入? |
false |
是否接受通配符? |
false |
-命名空间 <string>
指定新类的命名空间。
此参数的值与 Class 参数的值一起使用时,可生成该类的完全限定名称。默认值为 Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes 和从 URI 生成的类型。
您可以设置 Namespace 参数的值,以便可访问多个同名 Web 服务。
是否为必需? |
false |
位置? |
3 |
默认值 |
Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes |
是否接受管道输入? |
false |
是否接受通配符? |
false |
-URI <Uri>
指定 Web 服务的 URI。请输入 URI 或包含服务说明的文件的路径和文件名。
该 URI 必须引用 .asmx 页或引用返回服务说明的页。要返回使用 ASP.NET 所创建的 Web 服务的服务说明,请在该 Web 服务的 URL 后面追加“?WSDL”(例如,http://www.contoso.com/MyWebService.asmx?WSDL)。
是否为必需? |
true |
位置? |
1 |
默认值 |
|
是否接受管道输入? |
false |
是否接受通配符? |
false |
-UseDefaultCredential
将生成的代理对象中的 UseDefaultCredential 参数设置为 True。这是使用 Credential 参数的替代方法。
是否为必需? |
false |
位置? |
named |
默认值 |
False |
是否接受管道输入? |
false |
是否接受通配符? |
false |
<CommonParameters>
此 cmdlet 支持通用参数:-Verbose、-Debug、-ErrorAction、-ErrorVariable、-OutBuffer 和 -OutVariable。有关详细信息,请参阅 about_Commonparameters.
输入和输出
输入类型是指可通过管道传递给 cmdlet 的对象的类型。返回类型是指 Cmdlet 所返回对象的类型。
输入 |
None 此 cmdlet 不通过管道接受输入。 |
输出 |
A Web service proxy object 该对象的命名空间和类由该命令的参数确定。默认值是根据输入的统一资源标识符 (URI) 生成的。 |
说明
New-WebServiceProxy 使用 System.Net.WebClient 类加载指定的 Web 服务。
示例 1
C:\PS>$zip = New-WebServiceProxy -uri http://www.webservicex.net/uszip.asmx?WSDL 说明 ----------- 此命令使用 New-WebServiceProxy 命令在 Windows PowerShell 中创建 US Zip Web 服务的 .NET Framework 代理。
示例 2
C:\PS>$URI = "http://www.webservicex.net/uszip.asmx?WSDL" C:\PS> $zip = New-WebServiceProxy -uri $URI -namespace WebServiceProxy -class ZipClass 说明 ----------- 此命令使用 New-WebServiceProxy cmdlet 创建 US Zip Web 服务的 .NET Framework 代理。 第一条命令将该 Web 服务的 URI 存储在 $URI 变量中。 第二条命令创建该 Web 服务代理。该命令使用 URI 参数指定该 URI,使用 Namespace 和 Class 参数指定该对象的命名空间和类。
示例 3
C:\PS>$zip | get-member -type method TypeName: WebServiceProxy.USZip Name MemberType Definition ---- ---------- ---------- Abort Method System.Void Abort( BeginGetInfoByAreaCode Method System.IAsyncResul BeginGetInfoByCity Method System.IAsyncResul BeginGetInfoByState Method System.IAsyncResul BeginGetInfoByZIP Method System.IAsyncResul CreateObjRef Method System.Runtime.Rem Discover Method System.Void Discov Dispose Method System.Void Dispos EndGetInfoByAreaCode Method System.Xml.XmlNode EndGetInfoByCity Method System.Xml.XmlNode EndGetInfoByState Method System.Xml.XmlNode EndGetInfoByZIP Method System.Xml.XmlNode Equals Method System.Boolean Equ GetHashCode Method System.Int32 GetHa GetInfoByAreaCode Method System.Xml.XmlNode GetInfoByCity Method System.Xml.XmlNode GetInfoByState Method System.Xml.XmlNode GetInfoByZIP Method System.Xml.XmlNode GetLifetimeService Method System.Object GetL GetType Method System.Type GetTyp InitializeLifetimeService Method System.Object Init ToString Method System.String ToSt 说明 ----------- 此命令使用 Get-Member cmdlet 显示 $zip 变量中 Web 服务代理对象的方法。在下面的示例中将会用到这些方法。 请注意,代理对象 WebServiceProxy 的 TypeName 反映了上一示例中所指定的命名空间和类名。
示例 4
C:\PS>$zip.getinfobyzip(20500).table CITY : Washington STATE : DC ZIP : 20500 AREA_CODE : 202 TIME_ZONE : E 说明 ----------- 此命令使用存储在 Zip 变量中的 Web 服务代理。该命令使用该代理的 GetInfoByZip 方法及其 Table 属性。
另请参阅