New-WebServiceProxy
Published: February 29, 2012
Updated: November 16, 2012
Applies To: Windows PowerShell 2.0, Windows PowerShell 3.0
New-WebServiceProxy
Syntax
Parameter Set: NoCredentials New-WebServiceProxy [-Uri] <Uri> [[-Class] <String> ] [[-Namespace] <String> ] [ <CommonParameters>] Parameter Set: Credential New-WebServiceProxy [-Uri] <Uri> [[-Class] <String> ] [[-Namespace] <String> ] [-Credential <PSCredential> ] [ <CommonParameters>] Parameter Set: UseDefaultCredential New-WebServiceProxy [-Uri] <Uri> [[-Class] <String> ] [[-Namespace] <String> ] [-UseDefaultCredential] [ <CommonParameters>]
Detailed Description
The New-WebServiceProxy cmdlet lets you use a Web service in Windows PowerShell. The cmdlet connects to a Web service and creates a Web service proxy object in Windows PowerShell. You can use the proxy object to manage the Web service.
A Web service is an XML-based program that exchanges data over a network, particularly over the Internet. The Microsoft .NET Framework provides Web service proxy objects that represent the Web service as a .NET Framework object.
Parameters
-Class<String>
Specifies a name for the proxy class that the cmdlet creates for the Web service. The value of this parameter is used with the Namespace parameter to provide a fully qualified name for the class. The default value is generated from the URI.
|
Aliases |
none |
|
Required? |
false |
|
Position? |
2 |
|
Default Value |
Generated from the URI |
|
Accept Pipeline Input? |
false |
|
Accept Wildcard Characters? |
false |
-Credential<PSCredential>
Specifies a user account that has permission to perform this action. The default is the current user. This is an alternative to using the UseDefaultCredential parameter.
Type a user name, such as "User01" or "Domain01\User01". Or, enter a PSCredential object, such as one generated by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password.
|
Aliases |
none |
|
Required? |
false |
|
Position? |
named |
|
Default Value |
Current user |
|
Accept Pipeline Input? |
false |
|
Accept Wildcard Characters? |
false |
-Namespace<String>
Specifies a namespace for the new class.
The value of this parameter is used with the value of the Class parameter to generate a fully qualified name for the class. The default value is Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes plus a type that is generated from the URI.
You can set the value of the Namespace parameter so that you can access multiple Web services with the same name.
|
Aliases |
none |
|
Required? |
false |
|
Position? |
3 |
|
Default Value |
Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes |
|
Accept Pipeline Input? |
false |
|
Accept Wildcard Characters? |
false |
-Uri<Uri>
Specifies the URI of the Web service. Enter a URI or the path and file name of a file that contains a service description.
The URI must refer to an .asmx page or to a page that returns a service description. To return a service description of a Web service that was created by using ASP.NET, append "?WSDL" to the URL of the Web service (for example, http://www.contoso.com/MyWebService.asmx?WSDL).
|
Aliases |
none |
|
Required? |
true |
|
Position? |
1 |
|
Default Value |
none |
|
Accept Pipeline Input? |
false |
|
Accept Wildcard Characters? |
false |
-UseDefaultCredential
Sets the UseDefaultCredential property in the resulting proxy object to True. This is an alternative to using the Credential parameter.
|
Aliases |
none |
|
Required? |
false |
|
Position? |
named |
|
Default Value |
False |
|
Accept Pipeline Input? |
false |
|
Accept Wildcard Characters? |
false |
<CommonParameters>
This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/p/?LinkID=113216).
Inputs
The input type is the type of the objects that you can pipe to the cmdlet.
-
None
This cmdlet does not take input from the pipeline.
Outputs
The output type is the type of the objects that the cmdlet emits.
-
A Web service proxy object
The namespace and class of the object are determined by the parameters of the command. The default is generated from the input Uniform Resource Identifier (URI).
Notes
-
New-WebServiceProxy uses the System.Net.WebClient class to load the specified Web service.
Examples
-------------------------- EXAMPLE 1 --------------------------
This command uses the New-WebServiceProxy command to create a .NET Framework proxy of the US Zip Web service in Windows PowerShell.
PS C:\> $zip = New-WebServiceProxy -Uri http://www.webservicex.net/uszip.asmx?WSDL
-------------------------- EXAMPLE 2 --------------------------
This command uses the New-WebServiceProxy cmdlet to create a .NET Framework proxy of the US Zip Web service.
The first command stores the URI of the Web service in the $URI variable.
The second command creates the Web service proxy. The command uses the URI parameter to specify the URI and the Namespace and Class parameters to specify the namespace and class of the object.
PS C:\> $URI = "http://www.webservicex.net/uszip.asmx?WSDL"PS C:\>$zip = New-WebServiceProxy -Uri $URI -Namespace WebServiceProxy -Class USZip
-------------------------- EXAMPLE 3 --------------------------
This command uses the Get-Member cmdlet to display the methods of the Web service proxy object in the $zip variable. We will use these methods in the following example.
Notice that the TypeName of the proxy object, WebServiceProxy, reflects the namespace and class names that were specified in the previous example.
PS C:\> $zip | get-member -type methodTypeName: WebServiceProxy.USZipName MemberType Definition---- ---------- ----------Abort Method System.Void Abort(BeginGetInfoByAreaCode Method System.IAsyncResulBeginGetInfoByCity Method System.IAsyncResulBeginGetInfoByState Method System.IAsyncResulBeginGetInfoByZIP Method System.IAsyncResulCreateObjRef Method System.Runtime.RemDiscover Method System.Void DiscovDispose Method System.Void DisposEndGetInfoByAreaCode Method System.Xml.XmlNodeEndGetInfoByCity Method System.Xml.XmlNodeEndGetInfoByState Method System.Xml.XmlNodeEndGetInfoByZIP Method System.Xml.XmlNodeEquals Method System.Boolean EquGetHashCode Method System.Int32 GetHaGetInfoByAreaCode Method System.Xml.XmlNodeGetInfoByCity Method System.Xml.XmlNodeGetInfoByState Method System.Xml.XmlNodeGetInfoByZIP Method System.Xml.XmlNodeGetLifetimeService Method System.Object GetLGetType Method System.Type GetTypInitializeLifetimeService Method System.Object InitToString Method System.String ToSt
-------------------------- EXAMPLE 4 --------------------------
This command uses the Web service proxy stored in the Zip variable. The command uses the GetInfoByZip method of the proxy and its Table property.
PS C:\> $zip.getinfobyzip(20500).tableCITY : WashingtonSTATE : DCZIP : 20500AREA_CODE : 202TIME_ZONE : E
Related topics