New WebServiceProxy - PowerShell


Overview

The New-WebServiceProxy command generates a proxy class and configuration files for a specified web service. This allows you to access the web service’s methods and properties from your PowerShell scripts.

Syntax

New-WebServiceProxy [-Name] <string> [-Uri] <Uri> [-Namespace] <string> [-OutputAssembly] <string>
[-OutFile] <string> [-CodeLanguage] <string> [-NamespacePrefix] <string>
[-UseDefaultCredentials] [-WebProxy] <Uri> [-Credential] <PSCredential>
[-Timeout] <int> [-Verbose] [-Debug] [-ErrorAction] <ActionPreference>
[-ErrorVariable] <string> [-OutVariable] <string> [<CommonParameters>]

Options/Flags

  • -Name: Specifies the name of the proxy class to be generated.
  • -Uri: Specifies the URI of the web service to be proxied.
  • -Namespace: Specifies the namespace of the generated proxy class.
  • -OutputAssembly: Specifies the path and file name of the assembly to generate.
  • -OutFile: Specifies the path and file name of the configuration file to generate.
  • -CodeLanguage: Specifies the language of the generated proxy class. Can be either “CS” for C# or “VB” for Visual Basic.
  • -NamespacePrefix: Specifies the namespace prefix to be used for the generated proxy class.
  • -UseDefaultCredentials: Specifies whether to use the default credentials for authentication.
  • -WebProxy: Specifies the URI of the web proxy to use for the request.
  • -Credential: Specifies the credentials to use for authentication.
  • -Timeout: Specifies the timeout in seconds for the request.
  • -Verbose: Specifies whether to display verbose output.
  • -Debug: Specifies whether to display debug output.
  • -ErrorAction: Specifies the action to take when an error occurs.
  • -ErrorVariable: Specifies the variable to store the error message in.
  • -OutVariable: Specifies the variable to store the output in.

Examples

Simple Example

The following command generates a proxy class named MyWebServiceProxy for the web service at https://example.com/service.asmx:

New-WebServiceProxy -Name MyWebServiceProxy -Uri https://example.com/service.asmx

Complex Example

The following command generates a proxy class named MyWebServiceProxy for the web service at https://example.com/service.asmx, using the VB language, and specifying the output assembly and configuration files:

New-WebServiceProxy -Name MyWebServiceProxy -Uri https://example.com/service.asmx -CodeLanguage VB -OutputAssembly c:\temp\MyWebServiceProxy.dll -OutFile c:\temp\MyWebServiceProxy.config

Common Issues

One common issue is that the New-WebServiceProxy command may fail with an error if the web service is not accessible. To resolve this issue, check that the web service is running and that you have the necessary permissions to access it.

Integration

The New-WebServiceProxy command can be integrated with other PowerShell commands to automate tasks related to web service access. For example, you can use the Invoke-WebRequest command to send requests to a web service, and then use the ConvertFrom-Json command to parse the JSON response.

  • Invoke-WebRequest
  • ConvertFrom-Json