Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Calling  $webclient.UploadString in .NET Framework 2.0

Posted on 2010-09-22
6
Medium Priority
?
1,051 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 2000 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
10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

 

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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Here I am going to explain creating proxies at runtime for WCF Service. So basically we use to generate proxies using Add Service Reference and then giving the Url of the WCF service then generate proxy files at client side. Ok, what if something ge…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

721 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