0

I have a project to write a script that connects to a Web Service and retrieve information of selected records. Unfortunately there is no PowerShell support from the vendor. Their documents only provides .Net examples. The web service that I am trying to retrieve information is for HP Trim v7. Maybe some of you are familiar.

Here is the .Net example from vendor

Example – Title Word search

// Construct a request object
TrimRequest request = new TrimRequest();

// Construct a RecordStringSearchClause, with type
// TitleWord, and argument "reef"
RecordStringSearchClause clause = new RecordStringSearchClause();
clause.Type = RecordStringSearchClauseType.TitleWord;
clause.Arg = "reef";

// Construct a record search, and put our search clause in it
RecordSearch search = new RecordSearch();
search.Items = new RecordClause[] { clause };

// Put our search operation into our TrimRequest
request.Items = new Operation[] { search };

// Send it off. Whatever comes back will be in response
Engine engine = new Engine();
engine.Credentials = new System.Net.NetworkCredential(username, password);
TrimResponse response = engine.Execute(request);

And here is my PowerShell code

$url = "http://localhost/trimws/trim.asmx"
$Engine = New-WebServiceProxy -Uri $url -Class "proxy" -Namespace "Connection" -UseDefaultCredential

$RecordStringSearchClause = New-Object Connection.RecordStringSearchClause

$ClauseType = New-Object Connection.RecordStringSearchClauseType
$ClauseType.value__ = 4 ##Record Number
$RecordStringSearchClause.Type = $ClauseType
$RecordStringSearchClause.Arg = "39299763"

$RecordSearch = New-Object Connection.RecordSearch
$RecordClause = New-Object Connection.RecordClause ## doesn't work

$RecordSearch.Items = New-Object Connection.RecordClause { $RecordStringSearchClause } ## doesn't work
$RecordSearch.Items = $RecordStringSearchClause

$TrimRequest = New-Object Connection.TrimRequest
$TrimRequest.Items = $RecordSearch

$Engine.Execute($TrimRequest) ## returns nothing

Could any body help me to convert above .Net code into PowerShell script? (if technically possible)

3
  • What does New-Object Connection.RecordClause ## doesn't work mean? No object, wrong object, something else? Commented Nov 11, 2014 at 11:12
  • New-Object : Constructor not found. Cannot find an appropriate constructor for type Connection.RecordClause. Commented Nov 11, 2014 at 22:07
  • Wrappers on wrappers.... a web service doesn't need a special .Net class to call it. You can just call the web service directly. However a special vendor wrapper can certainly make it easy. I think you have to make the class know to powershell by using Add-Type or using New-Object <name of assembly> Commented Apr 2, 2023 at 12:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.