Solved

Calling  $webclient.UploadString in .NET Framework 2.0

Posted on 2010-09-22
6
983 Views
Last Modified: 2012-08-08
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
0
Comment
Question by:nanohurtz
  • 3
  • 3
6 Comments
 
LVL 2

Accepted Solution

by:
mgrabarz earned 500 total points
ID: 33744175
This error can be realted to .NET framework version, method UploadString doesn't exist in .Net 1.1 and was introduced in .Net 2.0.

Methods of System.Net.WebClient:
.NET 1.1 http://msdn.microsoft.com/en-us/library/system.net.webclient_methods%28v=VS.71%29.aspx
.NET 2.0 http://msdn.microsoft.com/en-us/library/system.net.webclient_methods%28v=VS.80%29.aspx

Exception is thrown when you call this method from service running under old framework version.
0
 

Author Comment

by:nanohurtz
ID: 33744412
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?
0
 
LVL 2

Expert Comment

by:mgrabarz
ID: 33744517
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
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:nanohurtz
ID: 33744598
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?
0
 

Author Comment

by:nanohurtz
ID: 33744631
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.
0
 
LVL 2

Expert Comment

by:mgrabarz
ID: 33744807
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.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now