Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Bug when using the -NameSpace parameter in New-WebServiceProxy?

3,438 views
Skip to first unread message

Stitch10925

unread,
Mar 18, 2010, 8:09:01 AM3/18/10
to

#########
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
"http://<server>/webservices/services.php?wsdl" -NameSpace "Service"

$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
"createService" to type "Service.serviceInput": "Cannot convert the
"Service.serviceInput" value of type "Service.serviceInput" to type
"Service.serviceInput"."

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

##########
WORKAROUND
##########

However, when I change the code to this:

---
$newWebService = New-WebServiceProxy -uri
"http://<server>/webservices/services.php?wsdl"

$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
"Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1webservices_services_php_wsdl.serviceInput.serviceInput"
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
"Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1webservices_services_php_wsdl.serviceInput.serviceInput"
value of type
"Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1webservices_services_php_wsdl.serviceInput.serviceInput"
to type
"Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy6webservices_services_php_wsdl.serviceInput.serviceInput"."

I know, annoying to read....

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

-- value of type
"Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1webservices_services_php_wsdl.serviceInput.serviceInput"
to type
"Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy6webservices_services_php_wsdl.serviceInput.serviceInput"

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

What I can conclude of this, is that the namespaces or the
"AutogeneratedTypes" are not disposed correctly after the code has finished
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
"WebServiceProxy6"

#######
SUMMARY
#######

Your safest bet is to use
"Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes" because
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.

Drawback is that you cannot load URLs dynamically because the name of the
automated proxy name (In this case:
WebServiceProxy1webservices_services_php_wsdl.serviceInput) would change.

---

Anyone have this problem? Did you find a solution? Let me know!

Also, if someone has contact to Microsoft, make them fix this! ^_^

Sincerely,

Stitch10925

Wind

unread,
Jul 1, 2010, 5:43:15 PM7/1/10
to
This bug can be remedied by declaring the class.

$newWebService = New-WebServiceProxy -uri
"http://<server>/webservices/services.php?wsdl" -NameSpace "Service" -Class
"<classname>"

Thanks to v-blairl.

0 new messages