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("Co ntent-Type ", "text/xml; charset=utf-8")
#$webclient.headers.Add("C ontent-Typ e", "application/soap+xml; charset=utf-8")
$WebClient.Proxy = [System.Net.WebRequest]::D efaultWebP roxy;
$WebClient.Proxy.Credentia ls = [System.Net.CredentialCach e]::Defaul tCredentia ls;
#$result = ([XML]$webclient.UploadStr ing($Url, #
$soapMessage)).envelope.bo dy.GetPISu mmaryDataR esponse.Ge tPISumrray DataResult
$result = $webclient.UploadString($U rl, $soapMessage)
ERROR RECEIVED
Exception calling "UploadString" with "2" argument(s): "The remote server retur
ned an error: (500) Internal Server Error."
At E:\scripts\SummaryCalls452 b.ps1:83 char:34
+ $result = $webclient.UploadString <<<< ($Url, $soapMessage)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
SNIPPET OF THE CODE (PS1 script)
$webclient.headers.Add("Co
#$webclient.headers.Add("C
$WebClient.Proxy = [System.Net.WebRequest]::D
$WebClient.Proxy.Credentia
#$result = ([XML]$webclient.UploadStr
$soapMessage)).envelope.bo
$result = $webclient.UploadString($U
ERROR RECEIVED
Exception calling "UploadString" with "2" argument(s): "The remote server retur
ned an error: (500) Internal Server Error."
At E:\scripts\SummaryCalls452
+ $result = $webclient.UploadString <<<< ($Url, $soapMessage)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
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($u rl, #$soapMessage)
TypeName: System.Management.Automati on.MethodI nvocationE xception
Maybe I wrote this wrong any suggestions?
I'd like to have this added:
trap { $error[0].Exception | get-member } $webclient.uploadstring($u
TypeName: System.Management.Automati
Maybe I wrote this wrong any suggestions?
ASKER
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 .getassemb lies() | sort -property fullname | format-table fullname
I have no idea how to trap exception before script execution.
PS [appdomain]::currentdomain
I have no idea how to trap exception before script execution.
ASKER