.NET Framework - Bug when using the -NameSpace parameter in New-WebServiceProxy?

Asked By Stitch10925
18-Mar-10 08:09 AM
THE PROBLEM

When I create a webservice connection with powershell 2.0, and add a
namespace the script only executes one time. Code example:

---
$newWebService = New-WebServiceProxy -uri

$newService = New-Object Service.serviceInput

$newService .Title = "this is a new service"
$newService .Desc = "this is the description of the service"

$newWebService.createService($newService)
----

This code would run the 1st time, and the second time it would error out
with the following message:

Cannot convert argument "0", with value: "Service.serviceInput", for

Changing the name of the namespace or running the script in a new session
would work, but that is not an option is most cases.

WORKAROUND

However, when I change the code to this:

---
$newWebService = New-WebServiceProxy -uri

$newService = New-Object
Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1webservices_services_php_wsdl.serviceInput

$newService .Title = "this is a new service"
$newService .Desc = "this is the description of the service"

$newWebService.createService($newService)
---

This code works everytime, except when you then add the namespace parameter
again, then the following error message would appear:

..."Cannot convert the
value of type "Service.serviceInput" to type "Service.serviceInput"."

As you can see, the important part is the last line:

-- value of type "Service.serviceInput" to type "Service.serviceInput"

Same data type, but still it does not work!

If you now remove the namespace again, so your script is in original state,
it still would not work, you are presented with the following error:

..."Cannot convert the
value of type
to type

I know, annoying to read....

But look closely, also here the last line is important:

-- value of type
to type

The first type is "...WebServiceProxy1webservices..." and the second is

What I can conclude of this, is that the namespaces or the
running, causing the old values to stay in memory and giving you these error
messages. The old, stale, entries probably cause PowerShell to create a new
instance under a different name, hence "WebServiceProxy1" and

SUMMARY

Your safest bet is to use
this will not cause your code to error out as long as you do not add a
namespace parameter, if you do, you need to start a new session.
Service.serviceInput
(1)
NewWebService.createService
(1)
WebServiceProxy1
(1)
WebServiceProxy6
(1)
WebServiceProxy
(1)
Wsdl.serviceInput.serviceInput
(1)
AutogeneratedTypes
(1)
NewWebService
(1)
  Wind replied to Stitch10925
01-Jul-10 05:43 PM
This bug can be remedied by declaring the class.

$newWebService = New-WebServiceProxy -uri

Thanks to v-blairl.
Create New Account
help
slightest ide why it does not work. Give me a comment about this. public class WebServiceProxy { public bool Save1(Order order) { try { / * Call WebService. . . * / return true; } catch { return false; } } public void