Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more: (untagged)
Dear friends,

i wrote a asp.net webservice using vs 2008 .net framework 3.5. this service runs over https.

it gets the parameters from the client and sends this to another application and then the answer from that application back to the client.

It works sometimes fine, bud sometimes im getting this exception:

System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Net.WebException: The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF
at System.Net.HttpWebRequest.GetResponse()
at WebService2.Service1.HttpSOAPRequest(String xmlfile, String proxy) in C:\Documents and Settings\BB\My Documents\Visual Studio 2008\Projects\WebService2\WebService2\Service1.asmx.cs:line 44
at WebService2.Service1.CardWithPerson(String persId, String projectId, String username, String pw) in C:\Documents and Settings\BB\My Documents\Visual Studio 2008\Projects\WebService2\WebService2\Service1.asmx.cs:line 82
--- End of inner exception stack trace ---

Here is some code of the webservice:
[WebMethod]   <br />        public String CardWithPerson(string persId, string projectId, string username, string pw)   <br />        {   <br />            xmlfile = "<?xml version=\"1.0\" encoding=\"utf-8\" ?> "  <br />            + "<soap:Envelope xmlns:soap=\"http://www.w3.org/2001/12/soap-envelope\">"  <br />            +"<soap:Body>"  <br />            +"<PS_CardsWithPersonReq xmlns=\"http://tempuri.org\">"  <br />           +"<WebAuthenticate>"  <br />            +" <WebUser>"+username+"</WebUser>"  <br />            +" <WebPass>"+pw+"</WebPass>"  <br />            +" <WebIp>"+Context.Request.UserHostAddress+"</WebIp>"  <br />            +" <WebMd>0123456789ABCDEF0123</WebMd>"  <br />            +" </WebAuthenticate>"  <br />            +"<PersNr>"+persId+"</PersNr>"  <br />            +"<Lang>E</Lang>"  <br />            +"<ProjCode>"+projectId+"</ProjCode>"  <br />            +"</PS_CardsWithPersonReq>"  <br />            +"</soap:Body>"  <br />            +"</soap:Envelope>";   <br />            r = HttpSOAPRequest(xmlfile, null);   <br />            result = r.ReadToEnd();   <br />            return result;   <br />        }   <br />  <br />StreamReader HttpSOAPRequest(String xmlfile, string proxy)   <br />        {   <br />            XmlDocument doc = new XmlDocument();   <br />            doc.LoadXml(xmlfile);   <br />               <br />            HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://211.144.244.244:7871");   <br />            if (proxy != null) req.Proxy = new WebProxy(proxy, true);   <br />            req.Headers.Add("SOAPAction", "\"\"");   <br />            req.ContentType = "text/xml;charset=\"utf-8\"";   <br />            req.Accept = "text/xml";   <br />            req.Method = "POST";   <br />            Stream stm = req.GetRequestStream();   <br />            doc.Save(stm);   <br />            stm.Close();   <br />            WebResponse resp = req.GetResponse();   <br />            stm = resp.GetResponseStream();   <br />            StreamReader strmReader = new StreamReader(stm);   <br />            return strmReader;   <br />        }  


Here the code of the client side:

protected void Button1_Click(object sender, EventArgs e)   <br />        {   <br />            nl.test.testsoap.Service1 serv = new WebApplication1.nl.test.testsoap.Service1();   <br />  <br />            Response.Write(serv.CardWithPerson(textPersId.Text, txtProCode.Text, username, pw));   <br />            Response.End();   <br />        }  


Can anyone help me with this issue?



Thanks
Posted

1 solution

Hi,

The problem is solved by adding
req.KeepAlive = false;

ofter creating the request :)
 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900