Link to home
Start Free TrialLog in
Avatar of nanohurtz
nanohurtz

asked on

Calling $webclient.UploadString in .NET Framework 2.0

I seem to be having a challenge retrieving $results using $webclient.upload parameter. This snippet of code was transferred from a server running IIS 6 with a web service running .NET 1.1 . It's launched through powershell on a IIS 7 server running .NET 2.0. The error I am receiving seems to point to the version of .NET but I'm not entirely sure. Any suggestions?

SNIPPET OF THE CODE (PS1 script)

$webclient.headers.Add("Content-Type", "text/xml; charset=utf-8")
#$webclient.headers.Add("Content-Type", "application/soap+xml; charset=utf-8")
$WebClient.Proxy = [System.Net.WebRequest]::DefaultWebProxy;

$WebClient.Proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials;
#$result = ([XML]$webclient.UploadString($Url, #

$soapMessage)).envelope.body.GetPISummaryDataResponse.GetPISumrrayDataResult

$result = $webclient.UploadString($Url, $soapMessage)

ERROR RECEIVED

Exception calling "UploadString" with "2" argument(s): "The remote server retur
ned an error: (500) Internal Server Error."
At E:\scripts\SummaryCalls452b.ps1:83 char:34
+ $result = $webclient.UploadString <<<< ($Url, $soapMessage)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException
ASKER CERTIFIED SOLUTION
Avatar of mgrabarz
mgrabarz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nanohurtz
nanohurtz

ASKER

If that's the case shouldn't the script work since it's being executed directly on an IIS 7, 2k8 (R2) server with an appPool, and Site running ASP.NET 2.0?
Script should run under Framework 2.0.
You said that code was transfered from 1.1 and I suppose it was working before. The problem is that it was impossible ;)

It is likely that your code has targetframework set to 1.1 or references the old version of the System.Net.dll Please check your project settings, references and web.config, eventually read this article: http://msdn.microsoft.com/en-us/library/cc668079.aspx
How can I incorperate a trap in powershell before running the script?

I'd like to have this added:

trap { $error[0].Exception | get-member } $webclient.uploadstring($url, #$soapMessage)
TypeName: System.Management.Automation.MethodInvocationException

Maybe I wrote this wrong any suggestions?
Sorry, I should have mentioned that the appPool was pointed to .NET 2.0. So presumably the code was targetted to making calls from there. It did work fine on the II6 server with no exceptions. The call seems to look ok based on the calls that can be made in 2.0. I think that If I can insert a trap I can get a verbose dump indicating where the problem is.
Could you please list assemblies loaded into powershell appdomain:
PS [appdomain]::currentdomain.getassemblies() | sort -property fullname | format-table fullname

I have no idea how to trap exception before script execution.