Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. HttpWebRequest and strange networking errors

HttpWebRequest and strange networking errors

Scheduled Pinned Locked Moved C#
xmlcsharpjavawpfwcf
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cjb110
    wrote on last edited by
    #1

    I've got the following code that did seem to be working successfully: (It's sending a SOAP envelope to a Java web service and receiving a response) EndPoint is just a string property containing the URL and path to the WebService, Response is a HttpWebResponse property, that other classes use to process the response SOAP.

            //create the request
            HttpWebRequest req = (HttpWebRequest) WebRequest.CreateDefault(new Uri(EndPoint));
            //and request header info
            req.ContentType = "text/xml; charset=utf-8";
            req.Method = "POST";
            req.Accept = "text/xml";
            req.KeepAlive = false;
            req.Timeout = Timeout;
            req.Proxy = WebRequest.GetSystemWebProxy();
    
            req.Headers.Add("SOAPAction", EndPoint);
    
            //write the SOAP Message to the request
            using (StreamWriter stm = new StreamWriter(req.GetRequestStream(), Encoding.UTF8))
            {
                stm.Write(soapRequest.ToString(SaveOptions.DisableFormatting)); //remove the formatting from the passed XML.
                stm.Flush();
            }
    
            Response = null;
            try
            {
                //get the response
                Response = ((HttpWebResponse) req.GetResponse());
                //read the raw response into ResponseString
                using (StreamReader reader = new StreamReader(Response.GetResponseStream(), Encoding.UTF8))
                    ResponseString = reader.ReadToEnd();
            }
            catch (WebException we)
            {
                throw new ApplicationException("A web exception occurred in calling Transact OUG!\\r\\n" + we.Message, we);
            }
            catch (Exception e)
            {
                throw new ApplicationException("A general exception occurred when calling Transact OUG!\\r\\n" + e.Message, e);
            }
            finally
            {
                if (Response != null)
                    Response.Close();
    
                req = null;
            }
    

    Now I'm not sure what's really changed but I'm getting really odd errors like 'An operation was attempted on something that is not a socket', now I think this might be threading related. As I'm seeing the very first time it returns a timeout, its only the second attempts that I get the odder errors. As I said this code was working fine when it was called via a single Window WPF app, I

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups