Solved

Calling  $webclient.UploadString in .NET Framework 2.0

Posted on 2010-09-22
6
1,017 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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

729 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