开发者

How to save object returned by a web service?

I'm new to PowerShell and I'm trying to figure out how to save (to a file or database) object returned by the following web service:

$apiKey = "00000000-1111-2222-3333-444444444444"
$userName   = "12345678"
$password   = "SamplePassword"

$URI     = "https://www.example.com/api/TestWS.TestService.svc?wsdl" 
$开发者_C百科prox = New-WebServiceProxy -uri $URI -namespace WebServiceProxy
$prox.chambersList
$prox.chambersList($userName, $password, $apiKey, 0, $false, 0, $false)

---------------------------------------------------------------------

MemberType          : Method
OverloadDefinitions : {WebServiceProxy.chambersListOutputData, ijfah16c, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null chambersList(string userName, string password, string apiKey, System.Nullable[int] pageNumber, bool pageNumberSpecified, System.Nullable[int] pageSize, bool pageSizeSpecified)}
TypeNameOfValue     : System.Management.Automation.PSMethod
Value               : WebServiceProxy.chambersListOutputData, ijfah16c, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null chambersList(string userName, string password, string apiKey, System.Nullable[int] pageNumber, bool pageNumberSpecified, System.Nullable[int] pageSize, bool pageSizeSpecified)
Name                : chambersList
IsInstance          : True

chambersList                       : {797, 798, 799, 800...}
pagesCount                         : 92
pagesCountSpecified                : True
allElementsCount                   : 918
allElementsCountSpecified          : True
pageNumber                         : 1
pageNumberSpecified                : True
pageSize                           : 10
pageSizeSpecified                  : True
description                        : OK
code                               : OK
codeSpecified                      : True
information                        : 

I would like to invoke a method called "chambersList" but I'm having trouble understanding how it works. Is it possible to export the returned object (List?, Table?) to a XML / CSV / TXT / database? How can I do that?


From the output, I'd gather that you should be able to store the value from the method into a variable, which you can do what you like with in Powershell:

$chambersListData = $prox.chambersList($userName, $password, $apiKey, 0, $false, 0, $false)

#Just an example of using the data
if ($chambersListData.allElementsCountSpecified)
{
    $chambersListData.allElementsCount
}

$chambersListData.chambersList | Foreach-Object {

    #do something with the elements
}

$chambersListData.chambersList | Export-Csv "myChambersList.csv"

Hard to tell if that last is useful, depends on the contents of chambersList

If this fails, do a $chambersListData | Get-Member to see what you can do with it.


Try these commands

Get-command -verb export

And then for each command returned :

Help export-....

Generally you will pipe you variable to the command:

$prox.chambersList($userName, $password, $apiKey, 0, $false, 0, $false) | export-...

There are quite few ways to export, csv and clixml (basically the PowerShell object) sound like the sort of things you want. Of course it depends what you want to do afterwards?

also check more detailed help out here:

To see the examples, type: "get-help Export-CSV -examples".
For more information, type: "get-help Export-CSV -detailed".
For technical information, type: "get-help Export-CSV -full".

and for export-clixml

To see the examples, type: "get-help Export-Clixml -examples".
For more information, type: "get-help Export-Clixml -detailed".
For technical information, type: "get-help Export-Clixml -full".
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜