SoapException was unhandled by user code
-
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]
public String CardWithPerson(string persId, string projectId, string username, string pw)
{
xmlfile = "<?xml version=\"1.0\" encoding=\"utf-8\" ?> "
+ "<soap:Envelope xmlns:soap=\"http://www.w3.org/2001/12/soap-envelope\\">"
+"soap:Body"
+"<PS_CardsWithPersonReq xmlns=\"http://tempuri.org\">"
+"<WebAuthenticate>"
+" <WebUser>"+username+"</WebUser>"
+" <WebPass>"+pw+"</WebPass>"
+" <WebIp>"+Context.Request.UserHostAddress+"</WebIp>"
+" <WebMd>0123456789ABCDEF0123</WebMd>"
+" </WebAuthenticate>"
+"<PersNr>"+persId+"</PersNr>"
+"<Lang>E</Lang>"
+"<ProjCode>"+projectId+"</ProjCode>"
+"</PS_CardsWithPersonReq>"
+"</soap:Body>"
+"</soap:Envelope>";
r = HttpSOAPRequest(xmlfile, null);
result = r.ReadToEnd();
return result;
}StreamReader HttpSOAPRequest(String xmlfile, string proxy)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlfile);HttpWebRequest req = (HttpWebRequest)WebRequest.Cr
-
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]
public String CardWithPerson(string persId, string projectId, string username, string pw)
{
xmlfile = "<?xml version=\"1.0\" encoding=\"utf-8\" ?> "
+ "<soap:Envelope xmlns:soap=\"http://www.w3.org/2001/12/soap-envelope\\">"
+"soap:Body"
+"<PS_CardsWithPersonReq xmlns=\"http://tempuri.org\">"
+"<WebAuthenticate>"
+" <WebUser>"+username+"</WebUser>"
+" <WebPass>"+pw+"</WebPass>"
+" <WebIp>"+Context.Request.UserHostAddress+"</WebIp>"
+" <WebMd>0123456789ABCDEF0123</WebMd>"
+" </WebAuthenticate>"
+"<PersNr>"+persId+"</PersNr>"
+"<Lang>E</Lang>"
+"<ProjCode>"+projectId+"</ProjCode>"
+"</PS_CardsWithPersonReq>"
+"</soap:Body>"
+"</soap:Envelope>";
r = HttpSOAPRequest(xmlfile, null);
result = r.ReadToEnd();
return result;
}StreamReader HttpSOAPRequest(String xmlfile, string proxy)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlfile);HttpWebRequest req = (HttpWebRequest)WebRequest.Cr
Just guessing, but the problem might occur when some of your variables (username, pwd, persID, projectId, ....) have invalid chars, like xml schema chars. Seems your webservice is accessing other webservice, right? If you're using Visual Studio, you can just reference the other webservice (Right click on project -> Add Web Reference). VS will automatically create a new class encapsulating the webservice, so you just call for WebServiceClass.PS_CardsWithPersonReq method with the parameters. You might need WS Secutity to authenticate.
Regards, Leonardo Muzzi
-
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]
public String CardWithPerson(string persId, string projectId, string username, string pw)
{
xmlfile = "<?xml version=\"1.0\" encoding=\"utf-8\" ?> "
+ "<soap:Envelope xmlns:soap=\"http://www.w3.org/2001/12/soap-envelope\\">"
+"soap:Body"
+"<PS_CardsWithPersonReq xmlns=\"http://tempuri.org\">"
+"<WebAuthenticate>"
+" <WebUser>"+username+"</WebUser>"
+" <WebPass>"+pw+"</WebPass>"
+" <WebIp>"+Context.Request.UserHostAddress+"</WebIp>"
+" <WebMd>0123456789ABCDEF0123</WebMd>"
+" </WebAuthenticate>"
+"<PersNr>"+persId+"</PersNr>"
+"<Lang>E</Lang>"
+"<ProjCode>"+projectId+"</ProjCode>"
+"</PS_CardsWithPersonReq>"
+"</soap:Body>"
+"</soap:Envelope>";
r = HttpSOAPRequest(xmlfile, null);
result = r.ReadToEnd();
return result;
}StreamReader HttpSOAPRequest(String xmlfile, string proxy)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlfile);HttpWebRequest req = (HttpWebRequest)WebRequest.Cr
Hi, Can you please highlight the line numbers indicated in the error message or can you paste the code with the line numbers. Gayani
-
Hi, Can you please highlight the line numbers indicated in the error message or can you paste the code with the line numbers. Gayani
Hi Gayani Devapriya, Thanks for your response. This is the line:
WebResponse resp = req.GetResponse();
You can see it In the methode: StreamReader HttpSOAPRequest(String xmlfile, string proxy)
-
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]
public String CardWithPerson(string persId, string projectId, string username, string pw)
{
xmlfile = "<?xml version=\"1.0\" encoding=\"utf-8\" ?> "
+ "<soap:Envelope xmlns:soap=\"http://www.w3.org/2001/12/soap-envelope\\">"
+"soap:Body"
+"<PS_CardsWithPersonReq xmlns=\"http://tempuri.org\">"
+"<WebAuthenticate>"
+" <WebUser>"+username+"</WebUser>"
+" <WebPass>"+pw+"</WebPass>"
+" <WebIp>"+Context.Request.UserHostAddress+"</WebIp>"
+" <WebMd>0123456789ABCDEF0123</WebMd>"
+" </WebAuthenticate>"
+"<PersNr>"+persId+"</PersNr>"
+"<Lang>E</Lang>"
+"<ProjCode>"+projectId+"</ProjCode>"
+"</PS_CardsWithPersonReq>"
+"</soap:Body>"
+"</soap:Envelope>";
r = HttpSOAPRequest(xmlfile, null);
result = r.ReadToEnd();
return result;
}StreamReader HttpSOAPRequest(String xmlfile, string proxy)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlfile);HttpWebRequest req = (HttpWebRequest)WebRequest.Cr
Hi, The problem is solved by adding req.KeepAlive = false; ofter creating the request :)