Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WebException from GetRequestStream

251 views
Skip to first unread message

lordbru...@yahoo.com

unread,
Sep 24, 2012, 4:14:21 PM9/24/12
to
I am developing a web service that at points needs to call another web service. The web service it must interact with does not use the same SOAP standard as Visual Studio, so I could not just add a web reference. When demoing the capabilities in a WPF project, I successfully sent requests and received expected responses. I can still use that project and get the results I want. However, once I moved it to a web service, it began giving me a WebException error that is below the code example below. I have already tried to change the security protocol through the ServicePointManager as suggested by many people. As you can see, I set KeepAlive to false. The code from the WPF project and web service project are IDENTICAL to one another. The former works and the latter does not. Does anyone have a clue what could be going on?

Code:
int startIndex;
int length;
System.IO.Stream requestStream;
string ret;
string uri = "<url that I need to keep to myself>";
byte[] postBytes = Encoding.ASCII.GetBytes(xmlRequest);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
HttpWebResponse response;

request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
request.Method = "POST";
request.ContentType = "text/XML";
request.ContentLength = postBytes.Length;
requestStream = request.GetRequestStream();
requestStream.Write(postBytes, 0, postBytes.Length);
requestStream.Close();
response = (HttpWebResponse)request.GetResponse();
ret = new System.IO.StreamReader(response.GetResponseStream()).ReadToEnd();
startIndex = ret.IndexOf("<response");
length = ret.IndexOf("</soapenv:Body>") - startIndex;
return ret.Substring(startIndex, length);

Error:
The underlying connection was closed: An unexpected error occurred on a send., StackTrace= at System.Net.HttpWebRequest.GetRequestStream(TransportContext&amp; context)

at System.Net.HttpWebRequest.GetRequestStream()

at BloombergLP.ISYS.Mir3svc.MIR3SoapHandler.SendHttpsRequest(String xmlRequest) in c:\Work\mir3svc\Service\App_Code\Common\MIR3SoapHandler.cs:line 149

at BloombergLP.ISYS.Mir3svc.MIR3SoapHandler.GetNotifications(Notification[]&amp; notifications) in c:\Work\mir3svc\Service\App_Code\Common\MIR3SoapHandler.cs:line 855

at BloombergLP.ISYS.Mir3svc.Mir3svc.GetNotification(GetNotificationRequestType request, SqlConnection conn, SqlCommand&amp; cmd, WebTimer webTimer) in c:\Work\mir3svc\Service\App_Code\Impl\GetNotification.cs:line 60

at BloombergLP.ISYS.Mir3svc.Mir3svc.BloombergLP.ISYS.Mir3svc.IMir3svcBinding.GetNotification(GetNotificationRequestType request) in c:\Work\mir3svc\Service\App_Code\Generated\Mir3svc.cs:line 312, InnerExc=System.IO.IOException: Authentication failed because the remote party has closed the transport stream.

at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)

at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)

at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)

at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)

at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)

at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)

at System.Net.TlsStream.CallProcessAuthentication(Object state)

at System.Threading.ExecutionContext.runTryCode(Object userData)

at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)

at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)

at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)

at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size)

at System.Net.ConnectStream.WriteHeaders(Boolean async)

BillyDHowell

unread,
Sep 25, 2012, 12:55:10 PM9/25/12
to
Figured it out. When the application makes the calls, the Microsoft classes are picking up the proxy script. When the same code is executed in the web service, it isn't.
0 new messages