Almir_7

Hello,

I get this error message when i kick off my web service to run. It gathers survey feedback from a database via http soap. Recently i put in a proxy that is required for access to internet. The web service started to fail that day as well. Can anyone tell me how i could hard code the proxy that should be used by the web service I found this link: http://support.microsoft.com/kb/307220

and tried editing the machine.config file but that didn't fix my issue. Any Ideas

Error:

8/2/2007 1:02:25 PM
The underlying connection was closed: Unable to connect to the remote server.
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult)
at System.Net.HttpWebRequest.GetRequestStream()
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at WebSurveyExec.com.some.api.GatewayV1SoapHandlerService.getRawDataForAllSurveys(String username, String password, DateTime startDate, DateTime endDate)
at WebSurveyExec.Class1.Main()

Thanks,

Almir




Re: ASMX Web Services and XML Serialization The underlying connection was closed: Unable to connect to the remote server.

John Saunders

Your proxy class inherits from SoapHttpClientProtocol. This class has a "Proxy" property that you can set before calling the service.






Re: ASMX Web Services and XML Serialization The underlying connection was closed: Unable to connect to the remote server.

Almir_7

Hi John,

Thanks for your message. Can you point me to sample code or a web page that explains the procedure a bit more I would appreciate your help.

Thanks,

Almir






Re: ASMX Web Services and XML Serialization The underlying connection was closed: Unable to connect to the remote server.

John Saunders

See HttpWebClientProtocol.Proxy Property in MSDN.




Re: ASMX Web Services and XML Serialization The underlying connection was closed: Unable to connect to the remote server.

Almir_7

Thanks for the link John. I'm having trouble taking this and adding it into my already existing class. I have included bellow the code i have so far. How can i implement the HttpWebClientProtocol.Proxy Property I would appreciate any pointers.

Thanks,

Almir

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Web;

using System.Web.Services;

using WebSurveyExec.com.some.api;

using System.Globalization;

using System.IO;

using System.Text;

using System.Net;

namespace WebSurveyExec

{

/// <summary>

/// Summary description for Class1.

/// </summary>

class Class1

{

/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main()

{

try

{

// Instantiate Web Service Object

WebSurveyExec.com.some.api.GatewayV1SoapHandlerService client = new GatewayV1SoapHandlerService();

client.Timeout = 1000000000;

// Sets a DateTime

DateTime myDT = new DateTime( DateTime.Today.Year, DateTime.Today.Month,DateTime.Today.Day, new GregorianCalendar() );

DateTime myDT2 = new DateTime( DateTime.Today.Year, DateTime.Today.Month,DateTime.Today.Day, new GregorianCalendar() );

// Creates an instance of the JulianCalendar.

JulianCalendar myCal = new JulianCalendar();

// Get the last 30 days worth of web surveys

myDT = myCal.AddDays( myDT, -0 );

myDT2 = myCal.AddDays( myDT2, +1 );

// Set the date object values

System.DateTime date1 = new DateTime(myDT.Year, myDT.Month,myDT.Day,23,59,59);

System.DateTime date2 = new DateTime(myDT2.Year, myDT2.Month,myDT2.Day,23,59,59);

// Set object for response

WebSurveyExec.com.some.api.RawData[] soapdata = client.getRawDataForAllSurveys("login","password",date1.ToUniversalTime(),date2.ToUniversalTime());

// Declare variables

int i;

int j;

string labelInfo = null;

string arrayInfo = null;

string dataInfo = null;

//There are 10 questions per survey

String[] dataObject = new String[10];

//Loop through the data to get the external reference data

for (i=0; i < soapdata.Length; i++)

{

labelInfo = labelInfo + soapdataIdea.externalReference + "|" + Convert.ToDateTime(soapdataIdea.timestamp);

// Set the data object in the array

dataObject = soapdataIdea.dataArray;

//Clear arrayInfo before we begin populating it again.

arrayInfo = null;

dataInfo = null;

// Loop through the responses

for (j=1; j < dataObject.Length; j++)

{

if (dataObject[j] != null)

{

if (dataObject[j].Length > 1000)

{

dataInfo = dataObject[j].Substring(0, 1000);

}

else

{

dataInfo = dataObject[j];

}

arrayInfo = arrayInfo + "|" + dataInfo.Replace("|","").Replace("\r","").Replace("\n","");

}

else

{

arrayInfo = arrayInfo + "|" + dataObject[j];

}

}

labelInfo = labelInfo + arrayInfo + "\n";

}

// Create two different encodings.

Encoding utf8 = Encoding.Default;

Encoding unicode = Encoding.Unicode;

// Get the bytes for each encoding

byte[] utf8Bytes = utf8.GetBytes(labelInfo);

byte[] unicodeBytes = Encoding.Convert(utf8, unicode, utf8Bytes);

// Create the unicode string

char[] unicodeChars = new char[unicode.GetCharCount(unicodeBytes, 0, unicodeBytes.Length)];

unicode.GetChars(unicodeBytes, 0, unicodeBytes.Length, unicodeChars, 0);

string unicodeString = new string(unicodeChars);

// Set filestream path

FileStream file = new FileStream(@"C:\Installs\Web Service\websurveyresults\surveys.csv", FileMode.OpenOrCreate, FileAccess.ReadWrite);

// Call StreamWriter class

StreamWriter sw = new System.IO.StreamWriter(file, Encoding.Unicode);

sw.Write(unicodeString);

sw.Close();

System.Environment.ExitCode = 0;

}

catch(Exception ex)

{

StreamWriter wrt = new StreamWriter(@"C:\Installs\Web Service\ErrorLog.log");

wrt.WriteLine(DateTime.Now);

wrt.WriteLine(ex.Message);

wrt.WriteLine(ex.StackTrace);

wrt.Close();

System.Environment.ExitCode = 1;

}

}

}

}






Re: ASMX Web Services and XML Serialization The underlying connection was closed: Unable to connect to the remote server.

John Saunders

Just set client.Proxy right after you set client.TimeOut.






Re: ASMX Web Services and XML Serialization The underlying connection was closed: Unable to connect to the remote server.

Almir_7

So that line would be:

client.Proxy set = new WebProxy("server.com:80", true);

Do i need anything before or after for this to work Thank you very much for quick reply.






Re: ASMX Web Services and XML Serialization The underlying connection was closed: Unable to connect to the remote server.

Almir_7

Well i added the following three lines and it compiles without any errors but it didn't help. The connection still can't be made.

WebProxy clientproxy;

WebProxy proxyObject = new WebProxy(http://prox.com, true);

clientproxy = proxyObject;

I also tried with:

WebProxy clientproxy;

WebProxy proxyObject = new WebProxy(server.com:80, true);

clientproxy = proxyObject;

i couldn't use the client variable as it is defined above as new GatewayV1SoapHandlerService()

Any ideas






Re: ASMX Web Services and XML Serialization The underlying connection was closed: Unable to connect to the remote server.

Almir_7

I noticed here that i was defining both as local variables so i changed the code to:

WebSurveyExec.com.some.api.GatewayV1SoapHandlerService clientproxy = new GatewayV1SoapHandlerService();

//WebProxy clientproxy;

WebProxy proxyObject = new WebProxy("server.com:80", true);

//clientproxy = proxyObject;

clientproxy.Proxy = proxyObject;

I seem to be getting the same error:

10/9/2007 3:55:57 PM
The underlying connection was closed: Unable to connect to the remote server.
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult)
at System.Net.HttpWebRequest.GetRequestStream()
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at WebSurveyExec.com.some.api.GatewayV1SoapHandlerService.getRawDataForAllSurveys(String username, String password, DateTime startDate, DateTime endDate)
at WebSurveyExec.Class1.Main()






Re: ASMX Web Services and XML Serialization The underlying connection was closed: Unable to connect to the remote server.

John Saunders

You now have the correct syntax for setting the Proxy property. Since it doesn't work, I suggest you find out whether you are constructing the WebProxy correctly. Try creating a sample program to simply use the WebRequest/WebResponse classes, and setting the Proxy property of the WebRequest instance to the same proxy you're using here. See if a simple POST can reach the server.






Re: ASMX Web Services and XML Serialization The underlying connection was closed: Unable to connect to the remote server.

Almir_7

Thanks John. I don't do any POST requests and i don't have the permissions to do that. I always just run the GET. I can't find any samples on how to test this or how to implement a sample program that would test if the scripts are using the default proxy (if they did then they would work fine) and if/why is the current configuration with the existing proxy failing. Would you be able to point me to any pages that talk about that or how i could do a simple test

Thanks for your time,

Almir






Re: ASMX Web Services and XML Serialization The underlying connection was closed: Unable to connect to the remote server.

John Saunders

Your proxy class was doing a POST, I'm sure.

See How to: Send Data Using the WebRequest Class and How to: Request Data Using the WebRequest Class.

Please try it with POST first, even if you don't think you're using POST.






Re: ASMX Web Services and XML Serialization The underlying connection was closed: Unable to connect to the remote server.

Almir_7

I was finally able to fix the code issue here. I just needed to change one more line. End result is this:

// Instantiate Web Service Object

WebSurveyExec.com.questionpro.api.GatewayV1SoapHandlerService client = new GatewayV1SoapHandlerService();

client.Timeout = 1000000000;

WebProxy proxyObject = new WebProxy("http://ctcpx3101.accenture.com:3128", false);

client.Proxy = proxyObject;

An this works like a gem.

I do have another issue now that this works and pulls back the data. The download breaks intermitently. Error is with the hexadecimal character that breaks the XML code. I still need to understand how i can work around it as i can't seem to find any info that we can use the replace function or trim the field, or something.

Here is the error:

10/25/2007 11:18:53 AM
System.InvalidOperationException: There is an error in XML document (1831, 5). ---> System.Xml.XmlException: '', hexadecimal value 0x1A, is an invalid character. Line 1831, position 85.
at System.Xml.XmlScanner.ScanContent()
at System.Xml.XmlTextReader.ParseBeginTagExpandCharEntities()
at System.Xml.XmlTextReader.Read()
at System.Xml.XmlReader.ReadStartElement()
at System.Xml.Serialization.XmlSerializationReader.ReadStringValue()
at System.Xml.Serialization.XmlSerializationReader.ReadTypedPrimitive(XmlQualifiedName type, Boolean elementCanBeType)
at System.Xml.Serialization.XmlSerializationReader.ReadReferencingElement(String name, String ns, Boolean elementCanBeType, String& fixupReference)
at System.Xml.Serialization.XmlSerializationReader.ReadReferencingElement(String name, String ns, String& fixupReference)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read4_RawData()
at System.Xml.Serialization.XmlSerializationReader.ReadReferencingElement(String name, String ns, Boolean elementCanBeType, String& fixupReference)
at System.Xml.Serialization.XmlSerializationReader.ReadReferencedElements()
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read23_getRawDataForAllSurveysResponse()
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, XmlDeserializationEvents events)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader)
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at WebSurveyExec.com.questionpro.api.GatewayV1SoapHandlerService.getRawDataForAllSurveys(String username, String password, DateTime startDate, DateTime endDate)
at WebSurveyExec.Class1.Main()
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, XmlDeserializationEvents events)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader)
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at WebSurveyExec.com.questionpro.api.GatewayV1SoapHandlerService.getRawDataForAllSurveys(String username, String password, DateTime startDate, DateTime endDate)
at WebSurveyExec.Class1.Main()

Any ideas on this Maybe a tip if you know how to either strip this character out on the fly or to ignore it. I don't have access to the raw data where i could put some kind of a search and strip function so this needs to be removed when it's being processed.

Thanks,

Almir






Re: ASMX Web Services and XML Serialization The underlying connection was closed: Unable to connect to the remote server.

John Saunders

Somebody is sending you an EOF (CTRL-Z). That needs to stop happening, as it's invalid in XML, and hasn't been necessary for over a decade.






Re: ASMX Web Services and XML Serialization The underlying connection was closed: Unable to connect to the remote server.

Almir_7

From looking at my code. You will notice that i implemented a single proxy server and port to route my http traffic and thus have my application be able to download the survey feedback from the vendor website without problems. A week or two later i find that this server is either experincing problems or is not always available to route my traffic. Solution would be to implement just the http proxy url that will then look at the list of 4-5 proxy servers and pick one every time just like IE does when displaying web pages. So i would assume the connection should not break neirly as frequent as now. Question is how would i code that

If i just add the code as this:

// Instantiate Web Service Object

WebSurveyExec.com.some.api.GatewayV1SoapHandlerService client = new GatewayV1SoapHandlerService();

client.Timeout = 1000000000;

WebProxy proxyObject = new WebProxy("http://set-proxy.some.com/bin/setup.proxy", false);

client.Proxy = proxyObject;

I keep getting a failure and an error such as this:

11/1/2007 3:08:27 PM
The request failed with HTTP status 404: Not Found.
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at WebSurveyExec.com.questionpro.api.GatewayV1SoapHandlerService.getRawDataForAllSurveys(String username, String password, DateTime startDate, DateTime endDate)
at WebSurveyExec.Class1.Main()

How can i fix this What am i missing How to workaround Point is to make the job more stable.

Thanks,

Almir