5 Replies - 2197 Views - Last Post: 27 November 2012 - 04:40 PM Rate Topic: -----

#1 darrenrm  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 14-November 12

WebRequest in a CGI

Posted 14 November 2012 - 11:16 AM

I have a program that uses WebRequest. When I execute it under VS IDE or as standalone EXE not under a webserver, I get the desired results. When I try it under IIS using http://localhost/TestPGM.exe or under our web server using http://web/cgi-bin/TestPGM.exe, the following error info is produced via the Catch routine:

System.Configuration.ConfigurationerrorsException > Configuration system failed to initialize > System.Configuration
at System.Configuration.ConfigurationManager.EnsureConfigurationSystem() at System.Configuration.ConfigurationManager.PrepareConfigSystem() at System.Configuration.ConfigurationManager.GetSection(String sectionName) at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName) at System.Diagnostics.DiagnosticsConfiguration.GetConfigSection() at System.Diagnostics.DiagnosticsConfiguration.Initialize() at System.Diagnostics.DiagnosticsConfiguration.get_Sources() at System.Diagnostics.TraceSource.Initialize() at System.Net.Logging.InitializeLogging() at System.Net.Logging.get_On() at System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase) at System.Net.WebRequest.Create(String requestUriString) at TestPGM.TestPGM.Module1.Main(String[] args)

I also included an attempted to get FilePath from System.Configuration.Configuration since I thought the problems might be related. Here is the error from that test:
test exeConfig
System.Configuration.ConfigurationerrorsException > An error occurred loading a configuration file: Illegal characters in path. > System.Configuration
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal) at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors) at System.Configuration.Configuration..ctor(String locationSubPath, Type typeConfigHost, Object[] hostInitConfigurationParams) at System.Configuration.ClientConfigurationHost.OpenExeConfiguration(ConfigurationFileMap fileMap, Boolean isMachine, ConfigurationUserLevel userLevel, String exePath) at System.Configuration.ConfigurationManager.OpenExeConfigurationImpl(ConfigurationFileMap fileMap, Boolean isMachine, ConfigurationUserLevel userLevel, String exePath) at System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel userLevel) at TestPGM.TestPGM.Module1.Main(String[] args)

What am I missing?

            Try
                _apiUrl = "http://www.google.com"
                ' wr = WebRequest.Create(_apiUrl)
                Dim request As HttpWebRequest = WebRequest.Create(_apiUrl)
                request.Timeout = 10000
                Dim response As HttpWebResponse = request.GetResponse
                Dim h1stream As System.IO.Stream = response.GetResponseStream
                Dim h1 As String = String.Empty
                Dim reader As New StreamReader(h1stream)
                h1 += reader.ReadToEnd
                Console.WriteLine(h1)
            Catch ex As Exception
                Console.WriteLine(ex.GetType.ToString + " > " + ex.Message + " > " + ex.Source + " <br> " & ex.StackTrace)
            End Try
            Dim xPath As String
            Console.WriteLine("<br>test exeConfig<br>")
            Try
                Dim exeConfig As System.Configuration.Configuration = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None)
                xPath = exeConfig.FilePath
            Catch ex As Exception
                xPath = ""
                Console.WriteLine(ex.GetType.ToString + " > " + ex.Message + " > " + ex.Source + "<br> " + ex.StackTrace)
            End Try




Is This A Good Question/Topic? 0
  • +

Replies To: WebRequest in a CGI

#2 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,511
  • Joined: 16-March 11

Re: WebRequest in a CGI

Posted 14 November 2012 - 04:03 PM

I honestly can't be sure of what the issue is. What's your CGI looking like? Has your server run a cgi application before? If not have you made sure it's set up properly for cgi? I wrote a cgi application some time ago, and when I ran it I thought there was an issue with my code because it kept giving me all sorts of errors. Turns out it was just the server itself screwing with me.
Was This Post Helpful? 0
  • +
  • -

#3 darrenrm  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 14-November 12

Re: WebRequest in a CGI

Posted 15 November 2012 - 08:15 AM

I have set up IIS (under windows 7) to run CGIs. I would get a "do you want to run TestPGM.exe?" before I had it set up correctly. It appeared to work then but I soon learned that it was actually running as an application and not as a CGI. TestPGM.exe runs now as a CGI and works fine unless a WebRequest is attempted. We run lots of CGIs on our production servers. They are all written in VB6. I switched to VB.NET to utilize some code obtained from another source to communicate with a website using XML. The code works but I have to run it as an application. I need to get it to run as a CGI on the web server. The code that I posted is all I am executing at the moment. The messages (via console.writeline) are appropriately being returned to the browser and are displayed correctly. That tells me the CGI is basically functioning both on the web server and on IIS. I assume something needs to be setup on IIS or the web server to get this to work.
Was This Post Helpful? 0
  • +
  • -

#4 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,511
  • Joined: 16-March 11

Re: WebRequest in a CGI

Posted 16 November 2012 - 11:30 AM

Hmmm It doesn't seem to me that it's a server problem. Sounds like something with the code. Have you tried placing some error traps? Maybe writing to a log file? Unfortunately since it's CGI there isn't a great list of ways for you to watch the code as it runs. Out of curiosity what kind of server are you running this on?

This post has been edited by trevster344: 16 November 2012 - 11:32 AM

Was This Post Helpful? 0
  • +
  • -

#5 darrenrm  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 14-November 12

Re: WebRequest in a CGI

Posted 26 November 2012 - 08:05 AM

If it is the code that is wrong then WebRequest.Create should fail when running as an application and under the IDE during debugging, right? WebRequest.Create works perfectly in those two instances.

These are the IMPORTS I am using:

Imports System
Imports System.Collections
Imports System.IO
Imports System.Text
Imports System.Xml
Imports System.Xml.Serialization
Imports System.Net


Was This Post Helpful? 0
  • +
  • -

#6 darrenrm  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 14-November 12

Re: WebRequest in a CGI

Posted 27 November 2012 - 04:40 PM

I got some help from Microsoft:

1)
add this before webrequest.create:
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", " c:\inetpub\wwwroot\testpgm.exe.config")

This resolves an issue with an invalid path. The config file doesn't even have to exist. It just needs that valid path.

2)
add this after webrequest.create if you are using a proxy
myRequest.Proxy = new WebProxy(“Http://10.0.0.15:8081”,true)
replace 10.0.0.15:8081 with your proxy.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1