remote server returned an error: (500) Internal Server Error
smshyd
Member Posts: 72
Hi Experts,
I am very much new to Dotnet world. I have a few lines of code using automations. I would like to change the code by using dot net functionality But I am getting following error, and code is followed after error
A call to System.Net.HttpWebRequest.GetResponse failed with this message: The remote server returned an error: (500) Internal Server Error.
But web service is working fine with automation variable. Any way to solve above issue, or if I am wrong in my approach , suggest correct approach
I am very much new to Dotnet world. I have a few lines of code using automations. I would like to change the code by using dot net functionality But I am getting following error, and code is followed after error
A call to System.Net.HttpWebRequest.GetResponse failed with this message: The remote server returned an error: (500) Internal Server Error.
But web service is working fine with automation variable. Any way to solve above issue, or if I am wrong in my approach , suggest correct approach
Name DataType Subtype Length
Credential DotNet System.Net.NetworkCredential.'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
MemoryStream DotNet System.IO.MemoryStream.'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
XMLRequestDoc DotNet System.Xml.XmlDocument.'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
XMLResponseDoc DotNet System.Xml.XmlDocument.'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
XMLProsInstr DotNet System.Xml.XmlProcessingInstruction.'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
XMLElement1 DotNet System.Xml.XmlElement.'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
XMLElement2 DotNet System.Xml.XmlElement.'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
XMLElement3 DotNet System.Xml.XmlElement.'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
XMLNode4 DotNet System.Xml.XmlNode.'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
XMLNsMgr DotNet System.Xml.XmlNamespaceManager.'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
msURL Text
oRequest DotNet System.Net.HttpWebRequest.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
oResponse DotNet System.Net.HttpWebResponse.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
Ouri DotNet System.Uri.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
XMLRequestDoc := XMLResponseDoc.XmlDocument;
XMLProsInstr := XMLRequestDoc.CreateProcessingInstruction('xml','version="1.0" encoding="utf-8"');
XMLRequestDoc.AppendChild(XMLProsInstr);
XMLElement1 := XMLRequestDoc.CreateElement('soap','Envelope','http://www.w3.org/2001/XMLSchema');
XMLElement1.SetAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
XMLElement1.SetAttribute('xmlns:xsd','http://schemas.xmlsoap.org/soap/envelope/');
XMLElement2 := XMLRequestDoc.CreateElement('soap','Body', 'http://schemas.xmlsoap.org/soap/envelope/');
XMLElement3 := XMLRequestDoc.CreateElement('insertuserbyerpid');
XMLElement3.SetAttribute('xmlns',STRSUBSTNO('http://tempuri.org/'));
XMLNode4 := XMLRequestDoc.CreateElement('erpuserid');
XMLNode4.InnerText := ID;
XMLElement3.AppendChild(XMLNode4);
XMLElement3.AppendChild(XMLNode4);
XMLElement2.AppendChild(XMLElement3);
XMLElement1.AppendChild(XMLElement2);
XMLRequestDoc.AppendChild(XMLElement1);
XMLRequestDoc.Save('C:\TEMP\RequestDotNet.xml');
msURL := GetEShopServiceURL;
Ouri := Ouri.Uri(msURL);
oRequest := oRequest.Create(msURL);
oRequest.Method := 'POST';
oRequest.ContentType := 'text/xml; charset=utf-8'; //'XML'
oRequest.KeepAlive := TRUE;
oRequest.Timeout := 10000;
MemoryStream := oRequest.GetRequestStream;
XMLRequestDoc.Save(MemoryStream);
SLEEP(100);
MemoryStream.Flush;
MemoryStream.Close;
oResponse:=oResponse.HttpWebResponse; //DESMS120314
oRequest := oRequest.GetResponse;
MemoryStream := oResponse.GetResponseStream;
XMLResponseDoc := XMLResponseDoc.XmlDocument;
XMLResponseDoc.Load(MemoryStream);
SLEEP(100);
MemoryStream.Flush;
MemoryStream.Close;
XMLNsMgr := XMLNsMgr.XmlNamespaceManager(XMLResponseDoc.NameTable);
XMLNsMgr.AddNamespace('urn',STRSUBSTNO('urn:microsoft-dynamics-schemas/codeunit/%1','Insertuserbyerpid'));
XMLNode4 := XMLResponseDoc.SelectSingleNode('//urn:return_value',XMLNsMgr);
IF UPPERCASE(XMLNode4.InnerText) = 'FALSE' THEN BEGIN
XMLNode4 := XMLResponseDoc.SelectSingleNode('//urn:responseMessage',XMLNsMgr);
ERROR(XMLNode4.InnerText);
END;
0
Comments
-
Hi smshyd,
there's probably nothing wrong with your Webrequest call but rather with the SOAP Request document you are sending. It might be an authentication problem though.
Along with the status 500, the web server usually sends you some explanation. You will want to inspect that info. Either use a network monitor to capture the communication or add a wrapper to your Webrequest that allows you to catch and handle Dotnet exceptions.
You might be interested in the following AddOn from the German NAV Developers Blog, if you opt for the latter: Catch Me If You Can – try-catch für .NET in C/AL0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 328 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
