How Send XML Document via HTTP Post Using DotNet?

michelegrs
Member Posts: 3
Hi to all,
I'd like to know how you can send an XML file via HTTP POST using DotNET.
I'm currently using the seguende code:
http://forum.mibuso.com/discussion/comment/296881/#Comment_296881
In the case:
..but I get an error:
"The system can not locate the resource"
Can you help me? Thanks in advance.
MGRS
I'd like to know how you can send an XML file via HTTP POST using DotNET.
I'm currently using the seguende code:
http://forum.mibuso.com/discussion/comment/296881/#Comment_296881
In the case:
URL[1] := '\\****************\************\ICT\JSS\EDI\Invoice200117.xml'; WebaddressToPostTo := 'http://IP:PORT/http?request=send';
..but I get an error:
"The system can not locate the resource"
Can you help me? Thanks in advance.
MGRS
0
Best Answers
-
Have a look at this code . I m using DotNet in it.
Variables: XmlHttpHandler2 System.Net.Http.HttpClient.'System.Net.Http, Version=4.0.0.0 XmlHttpHandler System.Net.Http.HttpClientHandler.'System.Net.Http, Version=4.0.0.0 XmlHttpRequestMessage System.Net.Http.HttpRequestMessage.'System.Net.Http, Version=4.0.0.0 XmlHttpMethod DotNet System.Net.Http.HttpMethod.'System.Net.Http, Version=4.0.0.0 XmlHttpContent System.Net.Http.StringContent.'System.Net.Http, Version=4.0.0.0 XmlHttpRequestHeader System.Net.Http.Headers.HttpRequestHeaders.'System.Net.Http, Version=4.0.0.0 XmlHttpClient System.Net.Http.HttpClient.'System.Net.Http, Version=4.0.0.0 XmlHttpResponseMessage: System.Net.Http.HttpResponseMessage.'System.Net.Http, Version=4.0.0.0 CurrNode System.Xml.XmlNode.'System.Xml, Version=4.0.0.0 Code: XmlHttpHandler := XmlHttpHandler.HttpClientHandler(); XmlHttpMethod := XmlHttpMethod.HttpMethod('POST'); XmlHttpRequestMessage := XmlHttpRequestMessage.HttpRequestMessage(XmlHttpMethod,WebServiceURL); { Testing: XmlHttpClient.DefaultRequestHeaders := ('Content-Type','text/xml'); XmlHttpClient.DefaultRequestHeaders('SOAPAction','"http://tempuri.org/' + WebFunc + '"'); XmlHttpRequestMessage.Headers := XmlHttpClient.DefaultRequestHeaders; } XmlHttpContent := XmlHttpContent.StringContent(XmlDoc.ToString); XmlHttpRequestMessage.Content(XmlHttpContent); XmlHttpHandler2 := XmlHttpHandler2.HttpClient(XmlHttpHandler); XmlHttpHandler2.SendAsync(XmlHttpRequestMessage); CLEAR(XmlDoc); XmlDoc := XmlDoc.XmlDocument; XmlHttpResponseMessage := XmlHttpResponseMessage.HttpResponseMessage; XmlHttpResponseMessage.RequestMessage := XmlHttpRequestMessage.HttpRequestMessage(XmlHttpMethod,WebServiceURL); IF XmlHttpResponseMessage.StatusCode <> 200 THEN BEGIN ErrorNote := 'HTTP ' + FORMAT(XmlHttpResponseMessage.StatusCode) + ': ' + XmlHttpResponseMessage.ReasonPhrase; EXIT(FALSE); END; XmlHttpContent := XmlHttpResponseMessage.Content; XmlDoc.LoadXml(XmlHttpContent.ToString); NOTE: This line gives and error. How can I store the data from the Response back in this XMlDoc? CurrNode := XmlDoc.DocumentElement.SelectSingleNode('soap:Body/' + WebFunc + 'Response/' + WebFunc + 'Result'); IF NOT ISNULL(CurrNode) THEN ReturnMessage := CurrNode.InnerText; IF XmlHttpResponseMessage.IsSuccessStatusCode THEN EXIT(TRUE); ErrorNote := COPYSTR(ReturnMessage,1,MAXSTRLEN(ErrorNote)); EXIT(FALSE);
Best Regards
Zohaib Ahmed
Dynamics NAV ERP Technical Consultant.
please like / agree / verify my answer, if it was helpful for you. thanks.6 -
Answers
-
I have wrote this code in NAV 2009 but you can replace Automation with DotNet type. The logic will remains the same.
Variables are as under:
Code:CLEAR(TempBlob); TempBlob.Blob.CREATEOUTSTREAM(OS); Customer.GET('30000'); //Set the view for the XMLPort CustomerXML.SETTABLEVIEW(Customer); // Use the TempBlob record to get a blob stream TempBlob.Blob.CREATEOUTSTREAM(OS); CustomerXML.SETDESTINATION(OS); // export the contents of the XMLPort to a blob CustomerXML.EXPORT; TempBlob.CALCFIELDS(Blob); TempBlob.Blob.CREATEINSTREAM(IS); IF ISCLEAR(XMLHTTP) THEN //'Microsoft XML, v6.0'.XMLHTTP60 CREATE(XMLHTTP); IF ISCLEAR(XMLDoc) THEN //'Microsoft XML, v6.0'.DOMDocument CREATE(XMLDoc); XMLDoc.load(IS); XMLHTTP.open('POST', WebAddress, FALSE); XMLHTTP.setRequestHeader('Content-Type', 'text/xml'); XMLHTTP.send(XMLDoc); IF XMLHTTP.status = 200 THEN BEGIN IF (XMLHTTP.responseText <> '') THEN BEGIN END; END ELSE BEGIN ERROR('Status %1 %2',XMLHTTP.status,XMLHTTP.statusText); END; CLEAR(XMLDoc); CLEAR(XMLHTTP);
Best Regards
Zohaib Ahmed
Dynamics NAV ERP Technical Consultant.
please like / agree / verify my answer, if it was helpful for you. thanks.2 -
Hi zohaibu,
many thanks for the swift answer, unfortunately I'm forced to use dotnet.
MicheleGRS0 -
Hey
Check out this link, if it seems helpful.
https://rockwithnav.wordpress.com/2016/02/23/consume-net-webservice-dotnet-data-type/Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/1 -
@michelegrs just replace Automation with DotNet rest will be the sameBest Regards
Zohaib Ahmed
Dynamics NAV ERP Technical Consultant.
please like / agree / verify my answer, if it was helpful for you. thanks.2 -
Have a look at this code . I m using DotNet in it.
Variables: XmlHttpHandler2 System.Net.Http.HttpClient.'System.Net.Http, Version=4.0.0.0 XmlHttpHandler System.Net.Http.HttpClientHandler.'System.Net.Http, Version=4.0.0.0 XmlHttpRequestMessage System.Net.Http.HttpRequestMessage.'System.Net.Http, Version=4.0.0.0 XmlHttpMethod DotNet System.Net.Http.HttpMethod.'System.Net.Http, Version=4.0.0.0 XmlHttpContent System.Net.Http.StringContent.'System.Net.Http, Version=4.0.0.0 XmlHttpRequestHeader System.Net.Http.Headers.HttpRequestHeaders.'System.Net.Http, Version=4.0.0.0 XmlHttpClient System.Net.Http.HttpClient.'System.Net.Http, Version=4.0.0.0 XmlHttpResponseMessage: System.Net.Http.HttpResponseMessage.'System.Net.Http, Version=4.0.0.0 CurrNode System.Xml.XmlNode.'System.Xml, Version=4.0.0.0 Code: XmlHttpHandler := XmlHttpHandler.HttpClientHandler(); XmlHttpMethod := XmlHttpMethod.HttpMethod('POST'); XmlHttpRequestMessage := XmlHttpRequestMessage.HttpRequestMessage(XmlHttpMethod,WebServiceURL); { Testing: XmlHttpClient.DefaultRequestHeaders := ('Content-Type','text/xml'); XmlHttpClient.DefaultRequestHeaders('SOAPAction','"http://tempuri.org/' + WebFunc + '"'); XmlHttpRequestMessage.Headers := XmlHttpClient.DefaultRequestHeaders; } XmlHttpContent := XmlHttpContent.StringContent(XmlDoc.ToString); XmlHttpRequestMessage.Content(XmlHttpContent); XmlHttpHandler2 := XmlHttpHandler2.HttpClient(XmlHttpHandler); XmlHttpHandler2.SendAsync(XmlHttpRequestMessage); CLEAR(XmlDoc); XmlDoc := XmlDoc.XmlDocument; XmlHttpResponseMessage := XmlHttpResponseMessage.HttpResponseMessage; XmlHttpResponseMessage.RequestMessage := XmlHttpRequestMessage.HttpRequestMessage(XmlHttpMethod,WebServiceURL); IF XmlHttpResponseMessage.StatusCode <> 200 THEN BEGIN ErrorNote := 'HTTP ' + FORMAT(XmlHttpResponseMessage.StatusCode) + ': ' + XmlHttpResponseMessage.ReasonPhrase; EXIT(FALSE); END; XmlHttpContent := XmlHttpResponseMessage.Content; XmlDoc.LoadXml(XmlHttpContent.ToString); NOTE: This line gives and error. How can I store the data from the Response back in this XMlDoc? CurrNode := XmlDoc.DocumentElement.SelectSingleNode('soap:Body/' + WebFunc + 'Response/' + WebFunc + 'Result'); IF NOT ISNULL(CurrNode) THEN ReturnMessage := CurrNode.InnerText; IF XmlHttpResponseMessage.IsSuccessStatusCode THEN EXIT(TRUE); ErrorNote := COPYSTR(ReturnMessage,1,MAXSTRLEN(ErrorNote)); EXIT(FALSE);
Best Regards
Zohaib Ahmed
Dynamics NAV ERP Technical Consultant.
please like / agree / verify my answer, if it was helpful for you. thanks.6 -
-
Best Regards
Zohaib Ahmed
Dynamics NAV ERP Technical Consultant.
please like / agree / verify my answer, if it was helpful for you. thanks.2 -
@michelegrs could you give the dotnet reference of HTTPRequest Var? Thanks!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K 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
- 320 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