SOAP and WSDL

by mehrzud at 2012-09-01 13:12:11

Hi guys,

I am not a Microsoft sort of guy actually and I need your help and experience here.
We have a web based software with WSDL/SOAP support and I am using a PHP script to read information from it.
For some reasons I need to do the exact work on windows and JUST with a powershell script.

<?php
// Create a standard SOAP client
$client = new SoapClient(‘https://myhost.com/service/?wsdl’);

// Set headers for authentication
// Specify the passwor in plain text, as it will be transmitted over ssl and encrypted

$headers = array();
$headers = new SoapHeader(‘http://mfisoft.ru/auth’,‘Login’,‘admin’);
$headers = new SoapHeader(‘http://mfisoft.ru/auth’,‘Password’,‘mypassword’);

$client->__setSoapHeaders($headers);
// Performed necessary actions

// ------- Main section starts -------
$table_hi = $client->getTableByTitle(‘Customers/Vendors’);
?>


I attached the API documentation.
I found New-WebServiceProxy http://technet.microsoft.com/en-us/libr … 49841.aspx and successfully created the proxy but I do not know how I can do the following:

[quote]The client, using the web service, is required to supply authentication credentials in every query
addressed to the service.
For the SOAP protocol include the login and password in the header of each packet.[/quote]

does anyone have any expert suggestion?
by willsteele at 2012-09-01 14:04:11
To be sure I understand what you need help with. Is it PHP coding or PowerShell? If you are trying to consume a web service from WSDL in PHP that is outside the scope of what we can help with here. If you are trying to use PowerShell, how are you integrating that into your web page? Are you using ASP.NET?
by mehrzud at 2012-09-01 17:16:42
Oh, This is not a server side script.
I used PHP in command prompt of linux/windows as a scripting language.
The php code is not generating a HTML to be displayed on web browser.
I just want to implement the code logic in powershell.
by lumm71 at 2012-09-03 00:07:44
I hope, I understand your problem: You want to use a webservice with powershell. There is a special comandlet called new-webserviceproxy. Have you tried "get-help new-webserviceproxy". Also in google you will find examples.
by willsteele at 2012-09-03 06:46:38
Without knowing the particulars of the proxy here is a general approach I use:

$webserviceproxy = New-WebServiceProxy -Uri ‘https://myhost.com/service/?wsdl’
$webserviceproxy.Login = ‘admin’
$webserviceproxy.Password = ‘mypassword’


There are often specific login methods sometimes. It is possible you can find one and simply pass that username and password to that method as well. One of the key ways to get an idea of what your web service methods/objects are is to instantiate the proxy (the first line) then explore the returned object with:

$webserviceproxy | Get-Member

The Get-Member cmdlet will show you properties, methods, signatures, etc that you can use to perform the usual webclient based work you would normally do.

The Get-Help cmdlet is a great resource to get not only basic parameter information on the initial cmdlet (New-WebserviceProxy) but on other cmdlets as well (such as Get-Member). Here is the help I see for Get-WebserviceProxy on a Windows machine with v3 CTP:

PS C:&gt; get-help New-WebServiceProxy -Full

NAME
New-WebServiceProxy

SYNOPSIS
Creates a Web service proxy object that lets you use and manage the Web service in Windows PowerShell.

SYNTAX
New-WebServiceProxy [-Uri] <Uri> [[-Class] <String>] [[-Namespace] <String>] [<CommonParameters>]

New-WebServiceProxy [-Uri] <Uri> [[-Class] <String>] [[-Namespace] <String>] [-Credential <PSCredential>]
[<CommonParameters>]

New-WebServiceProxy [-Uri] <Uri> [[-Class] <String>] [[-Namespace] <String>] [-UseDefaultCredential
[<SwitchParameter>]] [<CommonParameters>]


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.

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.

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.

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).

Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false

-UseDefaultCredential [<SwitchParameter>]
Sets the UseDefaultCredential parameter in the resulting proxy object to True. This is an alternative to using
the Credential parameter.

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, WarningAction, WarningVariable,
OutBuffer and OutVariable. For more information, see
about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).

INPUTS
None



This cmdlet does not take input from the pipeline.


OUTPUTS
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.


-------------------------- EXAMPLE 1 --------------------------

PS C:&gt; $zip = New-WebServiceProxy -uri http://www.webservicex.net/uszip.asmx?WSDL


This command uses the New-WebServiceProxy command to create a .NET Framework proxy of the US Zip Web service in
Windows PowerShell.





-------------------------- EXAMPLE 2 --------------------------

PS C:&gt; $URI = "http://www.webservicex.net/uszip.asmx?WSDL"
PS C:&gt;$zip = New-WebServiceProxy -uri $URI -namespace WebServiceProxy -class ZipClass


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.





-------------------------- EXAMPLE 3 --------------------------

PS C:&gt; $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


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.





-------------------------- EXAMPLE 4 --------------------------

PS C:&gt; $zip.getinfobyzip(20500).table
CITY : Washington
STATE : DC
ZIP : 20500
AREA_CODE : 202
TIME_ZONE : E


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.






RELATED LINKS
Online Version: http://go.microsoft.com/fwlink/?LinkID=135238
New-Service