New-WebServiceProxy as way for update information

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 9 years and 1 week old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
aalbende
Posts: 30
Last visit: Mon Jul 13, 2015 7:35 am

New-WebServiceProxy as way for update information

Post by aalbende »

Currently we are developing a script that allows to open/update incidents our incidents plattform (we use Service-Now), allowing to monitoring incidents directly with the user, crossing our ticket platform. In the past, I did we could open tickets from the script.

I explain a little which steps we are using:


1. We save the mail and webpage in two variables. The credentials used are mail (for example my mail account)
PowerShell Code
Double-click the code block to select all.
$SN_Web = "WEBPAGE...incident.do?WSDL"
$cred = Get-Credential

2. We set a web-proxy connection using the Incident Namespace saved in a object
PowerShell Code
Double-click the code block to select all.
$SNowWS_Incidents = New-WebServiceProxy -Uri $uri -Namespace Incidents -Credential $credential
3. We define a object called $records using the type Incidents.getRecords. Then we can set attributes for filtering the query (here we want active incidents but we can extend with a lot of properties like we fill in Service-Now when we open a incident).
PowerShell Code
Double-click the code block to select all.
$records = New-Object Incidents.getRecords

$records.active = $true

$records.activeSpecified = $true

4. The webproxy object include a function called getRecords which parameter is a record object with attributes defined previously. This function will return all incidents which include the same attributes (in this case all incidents active).
PowerShell Code
Double-click the code block to select all.
$INC = $SNowWS_Incidents.getRecords($records)


We will receive all information comming from active incidents (first execution works)

Well until now, looks good and should work but here is when I need your knowledge and experience. If I execute the same code a second time, I receive the following error:

PowerShell Code
Double-click the code block to select all.
ERROR: Cannot convert argument "getRecords1", with value: "Incidents.getRecords", for "getRecords" to type "Incidents.getRecords": "Cannot convert the

ERROR: "Incidents.getRecords" value of type "Incidents.getRecords" to type "Incidents.getRecords"."


I used PowerShell studio, PowerShell GUI, PowerShell ISE, PowerShell consoled and the error successes in all. We have no idea why we receive this error. Could be coming from PowerShell but maybe you have knowledge about the error or logic problem.

Thanks so much for your support.
Vini Vidi Installi
User avatar
SAPIEN Support Forums
Posts: 945
Last visit: Thu Oct 22, 2015 1:10 pm

New-WebServiceProxy as way for update information

Post by SAPIEN Support Forums »

This is an automated post. A real person will respond soon.

Thank you for posting, aalbende.

Here are some hints to help you get an accurate and complete answer to your question.

Ask in the best forum: If you asked in the wrong forum, just copy your question to the right forum.

Anticipate follow-up questions!

Did you remember to include the following?
  • 1. Product, version and build
    2. 32 or 64 bit product
    3. Operating system, e.g. Windows 7 64 bit.
    4. Attach a screenshot, if applicable
    5. Attach logs, crash reports, etc., in a ZIP file
If not, please take a moment to edit your original post or reply to this one.

*** Make sure you do not post any licensing information ***
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: New-WebServiceProxy as way for update information

Post by jvierra »

Sorry but without access to the web service there is not really any way to discover what might be your problem.

I recommend contacting the web service owners and asking them for information on how the service is intended to work.

It appears to me that you are using "getRecords" incorrectly but, without the WSDL I cannot tell.
User avatar
aalbende
Posts: 30
Last visit: Mon Jul 13, 2015 7:35 am

Re: New-WebServiceProxy as way for update information

Post by aalbende »

Hi jvierra,

working more in my problem I have discovered, the problem could be located here in the code:
PowerShell Code
Double-click the code block to select all.
New-WebServiceProxy -Uri $uri -Namespace Incidents
By definition founded in Internet, you cannot execute the same namespace more than one time in the same execution enviroment. That means, if you execute the script from the beginning (without close powershell studio, powergui or other software) you need to modify the code. See this example:

1 Execution: New-WebServiceProxy -Uri $uri -Namespace Incidents1
2 Execution: New-WebServiceProxy -Uri $uri -Namespace Incidents2
3 Execution: New-WebServiceProxy -Uri $uri -Namespace Incidents3
.........................................
.........................................

I extended my code using a globar variable
PowerShell Code
Double-click the code block to select all.
$global:SNowWS_Incidents = New-WebServiceProxy -Uri $uri -Namespace Incidents -Credential $cred
and in the final of the code
PowerShell Code
Double-click the code block to select all.
$SNowWS_Incidents.Dispose()
. It was suggested asking people but it did not solve the problem.

I am not sure how can I can remove the namespace in each execution.
Vini Vidi Installi
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: New-WebServiceProxy as way for update information

Post by jvierra »

Well that is not really what is happening.

We do not need to execute the "namespace" more than once with a web service. The service gives us an object builder in the form of XML "SOAP" instructions. We build the object and the "Proxy" functions and properties then execute them.

What you are missing is the method call that creates the object that you want to pass. You are using New-Object but, normally, a method is provided that construct the object. That is why we need to look at the WSDL.

Since I cannot see the website or the service description pages it is not possible to tell you what you are doing wrong.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: New-WebServiceProxy as way for update information

Post by jvierra »

Try this:

$SNowWS_Incidents | gm


What methods are available?
User avatar
aalbende
Posts: 30
Last visit: Mon Jul 13, 2015 7:35 am

Re: New-WebServiceProxy as way for update information

Post by aalbende »

I add it in an attachment
Attachments
methods.txt
(11.03 KiB) Downloaded 200 times
Vini Vidi Installi
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: New-WebServiceProxy as way for update information

Post by jvierra »

It is not obvious.

Why do you think you need a namespace? Why not use the default namespace. The NS is just to prevent collisions.

Since the passed object is a getRecords object it appears you want to let getRecords build it for you:

$getRecords1=$SNowWS_Incidents.GetRecords()
$SNowWS_Incidents.GetRecords($getRecords1)


Isn't there a web description of the wsdl.

Point your browser at the URL and add ?WSDL to the end.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: New-WebServiceProxy as way for update information

Post by jvierra »

Here is how to get WSDL to see if it has more infoo:

http://www.webservicex.net/globalweather.asmx?WSDL
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: New-WebServiceProxy as way for update information

Post by jvierra »

Here is what an API site loooke like:
[url]
http://wsf.cdyne.com/WeatherWS/Weather.asmx?op=GetCityWeatherByZIP[/url]
This topic is 9 years and 1 week old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked