Kiran_M
asked on
Why am i getting "The remote server returned an error : (500) Internal Server Error" when i consume .net Web Service
I have .net C# Test Harness consuming a new WebService I wrote. I am getting "The remote server returned an error : (500) Internal Server Error" when it executes
WebResponse webResponse = webRequest.GetResponse();
My Test Harness code to invoke Web Service is as follows :
private void CallUsingSOAP(string InXml, out XmlDocument xmlResponse)
{
string strSoapRequest = "";
xmlResponse = null;
string strABCWebServiceUrl = ConfigurationManager.AppSe ttings["AB CTestWebSe rviceURL"] ;
strSoapRequest = "";
strSoapRequest += "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
strSoapRequest += "<soap:Envelope ";
strSoapRequest += "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ";
strSoapRequest += "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ";
strSoapRequest += "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" ";
strSoapRequest += "xmlns=\"http://www.ACORD.org/standards/PC_Surety/ACORD1.10.0/xml/\" ";
strSoapRequest += ">";
strSoapRequest += "<soap:Header>";
strSoapRequest += "<ContractId/> ";
strSoapRequest += "<AppInfo/> ";
strSoapRequest += "</soap:Header>";
strSoapRequest += "<soap:Body>";
strSoapRequest += InXml;
strSoapRequest += "</soap:Body>";
strSoapRequest += "</soap:Envelope>";
try
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(strSoapRequ est);
HttpWebRequest webRequest = (HttpWebRequest)WebRequest .Create(st rABCWebSer viceUrl);
webRequest.Headers.Add("SO APAction", " ABCMethod");
//webRequest.Timeout = Int32.Parse("2000");
webRequest.ContentType = "text/xml; charset=utf-8";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
Stream webStream = webRequest.GetRequestStrea m();
xmlDoc.Save(webStream);
webStream.Close();
WebResponse webResponse = webRequest.GetResponse();
webStream = webResponse.GetResponseStr eam();
XmlTextReader xmlReader = new XmlTextReader(webStream);
// xmlResponse = new XmlDocument();
xmlResponse.Load(xmlReader );
webStream.Close();
}
catch (Exception e )
{
throw new Exception ("" + e.Message);
}
It throws a exception when it executes the
WebResponse webResponse = webRequest.GetResponse();
The strSoapRequest is a well formed XML, I checked it it looks ok.
I am not sure why i am getting this error?
My Web Service code is as follows :
namespace ABCTestWebService
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(Conform sTo = WsiProfiles.BasicProfile1_ 1)]
[ToolboxItem(false)]
public class ABCTestWebService : System.Web.Services.WebSer vice
{
[WebMethod]
public XmlDocumentABCMethod (XmlDocument InputXML)
{
}
}
WebResponse webResponse = webRequest.GetResponse();
My Test Harness code to invoke Web Service is as follows :
private void CallUsingSOAP(string InXml, out XmlDocument xmlResponse)
{
string strSoapRequest = "";
xmlResponse = null;
string strABCWebServiceUrl = ConfigurationManager.AppSe
strSoapRequest = "";
strSoapRequest += "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
strSoapRequest += "<soap:Envelope ";
strSoapRequest += "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ";
strSoapRequest += "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ";
strSoapRequest += "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" ";
strSoapRequest += "xmlns=\"http://www.ACORD.org/standards/PC_Surety/ACORD1.10.0/xml/\" ";
strSoapRequest += ">";
strSoapRequest += "<soap:Header>";
strSoapRequest += "<ContractId/> ";
strSoapRequest += "<AppInfo/> ";
strSoapRequest += "</soap:Header>";
strSoapRequest += "<soap:Body>";
strSoapRequest += InXml;
strSoapRequest += "</soap:Body>";
strSoapRequest += "</soap:Envelope>";
try
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(strSoapRequ
HttpWebRequest webRequest = (HttpWebRequest)WebRequest
webRequest.Headers.Add("SO
//webRequest.Timeout = Int32.Parse("2000");
webRequest.ContentType = "text/xml; charset=utf-8";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
Stream webStream = webRequest.GetRequestStrea
xmlDoc.Save(webStream);
webStream.Close();
WebResponse webResponse = webRequest.GetResponse();
webStream = webResponse.GetResponseStr
XmlTextReader xmlReader = new XmlTextReader(webStream);
// xmlResponse = new XmlDocument();
xmlResponse.Load(xmlReader
webStream.Close();
}
catch (Exception e )
{
throw new Exception ("" + e.Message);
}
It throws a exception when it executes the
WebResponse webResponse = webRequest.GetResponse();
The strSoapRequest is a well formed XML, I checked it it looks ok.
I am not sure why i am getting this error?
My Web Service code is as follows :
namespace ABCTestWebService
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(Conform
[ToolboxItem(false)]
public class ABCTestWebService : System.Web.Services.WebSer
{
[WebMethod]
public XmlDocumentABCMethod (XmlDocument InputXML)
{
}
}
ASKER
I would like to use SOAP and call the web service explictly.
Then i believe you need to change this:
webRequest.Headers.Add("SO APAction", " ABCMethod");
To this:
webRequest.Headers.Add("SO APAction", " XmlDocumentABCMethod");
webRequest.Headers.Add("SO
To this:
webRequest.Headers.Add("SO
If that doesn't work, I would verify that your webservice is working properly. Either visit its location through a browser or use WebserviceSudios
ASKER
I am able to visit the web service location through a browser. Web service seems to working correctly.
Are there other reasons for this error code : 500 (Internal Server Error)?
Are there other reasons for this error code : 500 (Internal Server Error)?
I would recommend trying a submission to your webservice using Web Service Studio (http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=65A1D4EA-0F7A-41BD-8494-E916EBC4159C). This will help narrow down where the problem lies. I know this program works when calling a web service so it will tell you where your problem resides.
If you get a successful response, then the error lies in you calling code (which i doubt). If it also receives a 500 error, or throws and error the problem is in the web service. A good idea would be to start the web service in debug mode and step through the code if this happens. You can set it up on your localhost if you need to. You can also try creating a simple webservice and putting it on your server. See if you can contact that. If you can't you know it is a server configuration issue.
My best guess is that there is an issue in the code. It might be caused by an infinite loop or it could be caused by low RAM on the server. There are a lot of options to check.
If you get a successful response, then the error lies in you calling code (which i doubt). If it also receives a 500 error, or throws and error the problem is in the web service. A good idea would be to start the web service in debug mode and step through the code if this happens. You can set it up on your localhost if you need to. You can also try creating a simple webservice and putting it on your server. See if you can contact that. If you can't you know it is a server configuration issue.
My best guess is that there is an issue in the code. It might be caused by an infinite loop or it could be caused by low RAM on the server. There are a lot of options to check.
ASKER
I'm all set with this error. The Web Service was missing Web.Service.Protocols.Soap DocumentMe thodAttrib ute......
Thanks for your help.
Thanks for your help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I was able to fix the problem myself. strickdd suggestions helped a lot.
ABCTestWebService.ABCTestW
server.XmlDocumentABCMetho