Solved

Calling  $webclient.UploadString in .NET Framework 2.0

Posted on 2010-09-22
6
1,002 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

756 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