用户代码未处理SoapException

问题描述:

尊敬的朋友们:

我使用vs 2008 .net framework 3.5编写了一个asp.net Web服务.此服务通过https运行.

它从客户端获取参数,并将其发送到另一个应用程序,然后将答案从该应用程序发送回客户端.

有时可以正常工作,有时可以发芽即时通讯收到此异常:

System.Web.Services.Protocols.SoapException:服务器无法处理请求. ---> System.Net.WebException:服务器提交了协议冲突.在Section = ResponseHeader Detail = CR之后必须是C:\ Documents and Settings \ BB \中System.Net.HttpWebRequest.GetResponse()
在WebService2.Service1.HttpSOAPRequest(String xmlfile,String proxy)处的LF
我的Documents \ Visual Studio 2008 \ Projects \ WebService2 \ WebService2 \ Service1.asmx.cs:第44行位于WebService2.Service1.CardWithPerson(C:\ Documents and Settings中的字符串persId,字符串projectId,字符串用户名,字符串pw) \ BB \ My Documents \ Visual Studio 2008 \ Projects \ WebService2 \ WebService2 \ Service1.asmx.cs:line 82
---内部异常堆栈跟踪的结尾---

以下是一些代码Web服务:

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



问题通过添加
req.KeepAlive = false;

随后创建请求:)
Hi,

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

ofter creating the request :)