Version 2. View version list at the bottom.
// Communication
CREATE(locautXmlHttp);
locautXmlHttp.open('POST','http://localhost:56063/SoapService.asmx',0);
locautXmlHttp.setRequestHeader('Content-type','application/soap+xml; charset=utf-8');
locautXmlHttp.setRequestHeader('SOAPAction','http://tempuri.org/NavisionRequest');
locautXmlHttp.send(locautXmlDoc);
locautXmlDoc := locautXmlHttp.responseXML;
locautXmlDoc.async := TRUE;
Complete CodeUnit;
OBJECT Codeunit 90002 WebService Connection
{
OBJECT-PROPERTIES
{
Date=02-01-12;
Time=20:21:46;
Modified=Yes;
Version List=;
}
PROPERTIES
{
OnRun=BEGIN
CREATE(XmlIn);
CREATE(XmlOut);
// Populating XmlIn document for test purposes
LoadTestXml();
// Invoke method
Send(XmlIn, XmlOut, 'User', 'Pass');
// Save result to disc
XmlOut.save('C:\Temp\XML\response.xml');
END;
}
CODE
{
VAR
XmlIn@1000000004 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{F6D90F11-9C73-11D3-B32E-00C04F990BB4}:'Microsoft XML, v6.0'.DOMDocument";
XmlOut@1000000003 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{F6D90F11-9C73-11D3-B32E-00C04F990BB4}:'Microsoft XML, v6.0'.DOMDocument";
DecodeXSLT@1000000008 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{F6D90F11-9C73-11D3-B32E-00C04F990BB4}:'Microsoft XML, v6.0'.DOMDocument";
locautXmlDoc@1000000010 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{F6D90F11-9C73-11D3-B32E-00C04F990BB4}:'Microsoft XML, v6.0'.DOMDocument";
ResultNode@1000000011 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNode";
PROCEDURE Send@1000000004(XmlRequest@1000000002 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{F6D90F11-9C73-11D3-B32E-00C04F990BB4}:'Microsoft XML, v6.0'.DOMDocument";VAR XmlReply@1000000003 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{F6D90F11-9C73-11D3-B32E-00C04F990BB4}:'Microsoft XML, v6.0'.DOMDocument";User@1000000005 : Text[30];Password@1000000006 : Text[30]);
VAR
locautXmlHttp@1000000000 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{F6D90F16-9C73-11D3-B32E-00C04F990BB4}:'Microsoft XML, v6.0'.XMLHTTP";
bodyXMLnode@1000000004 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNode";
BEGIN
CLEAR(XmlReply);
CREATE(XmlReply);
// Load Soap Envelope
LoadSendEnvelope(User,Password);;
// Load Transformation schema for URL-decode
LoadDecodeXlsSchema;
bodyXMLnode := locautXmlDoc.selectSingleNode('soap:Envelope/soap:Body/NavisionRequest/request');
// Inserting xml into text property it gets URL-encodes automatic
bodyXMLnode.text := XmlRequest.xml;
// Communication
CREATE(locautXmlHttp);
locautXmlHttp.open('POST','http://localhost:56063/SoapService.asmx',0);
locautXmlHttp.setRequestHeader('Content-type','application/soap+xml; charset=utf-8');
locautXmlHttp.setRequestHeader('SOAPAction','http://tempuri.org/NavisionRequest');
locautXmlHttp.send(locautXmlDoc);
locautXmlDoc := locautXmlHttp.responseXML;
locautXmlDoc.async := TRUE;
// Readin reply
XmlReply := locautXmlDoc;
// Fetching response
ResultNode := locautXmlDoc.selectSingleNode('soap:Envelope/soap:Body/NavisionRequestResponse/NavisionRequestResult');
// Parsing response
ResultNode.transformNodeToObject(DecodeXSLT, XmlReply);
END;
PROCEDURE LoadDecodeXlsSchema@1000000002();
BEGIN
CREATE(DecodeXSLT);
DecodeXSLT.loadXML(
'<?xml version="1.0" encoding="UTF-8" ?>' +
'<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">' +
'<xsl:output indent="yes" />' +
'<xsl:template match="*"> ' +
//'<xsl:element name="{local-name()}">' +
'<xsl:value-of select="." disable-output-escaping="yes"></xsl:value-of>' +
//'</xsl:element>' +
'</xsl:template>' +
'</xsl:stylesheet>');
END;
PROCEDURE LoadSendEnvelope@1000000006(parUser@1000000001 : Text[30];parPassword@1000000000 : Text[30]);
BEGIN
CREATE(locautXmlDoc);
locautXmlDoc.async := FALSE;
locautXmlDoc.loadXML(
'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
'<soap:Body>' +
'<NavisionRequest xmlns="http://tempuri.org/">' +
'<username>'+parUser+'</username>' +
'<password>'+parPassword+'</password>' +
'<request><xmltest><value>test</value></xmltest></request>' +
'</NavisionRequest>' +
'</soap:Body>' +
'</soap:Envelope>');
END;
PROCEDURE LoadTestXml@1160870000();
BEGIN
XmlIn.loadXML(
'<xmltest>' +
'<test>' +
'This document can contain anything. But must not contain xml decleration.' +
'</test>' +
'</xmltest>');
END;
BEGIN
{
Shows how to connect to a SOAP Web Service.
Version 2. For change history view:
http://navcode.blogspot.com/2012/01/connecting-to-soap-webservice-from.html
}
END.
}
}
Code examble of the .Net webservice:
using System;
using System.Web;
using System.Web.Services;
namespace WebServiceApplication
{
/// <summary>
/// Web Service for Navision Integration purpose
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class SoapService : System.Web.Services.WebService
{
[WebMethod]
public string HelloNavision()
{
return "Hello Navision";
}
[WebMethod]
public string NavisionRequest(string username, string password, string request)
{
if (string.IsNullOrEmpty(request))
{
return "Tinfoilhat!";
}
System.Xml.XmlDocument resp = new System.Xml.XmlDocument();
resp.LoadXml(request);
return resp.OuterXml;
}
[WebMethod]
public void ParamTest(System.Xml.XmlDocument xmldoc)
{
}
}
}
Version List:
1. Init
2. Bufferoverflow error fixed:
XmlReply.loadXML(ResultNode.transformNode(DecodeXSLT)); was changed to
ResultNode.transformNodeToObject(DecodeXSLT, XmlReply); due to the loadXML uses the Navision
string buffer as temporary container for the decoded XML this means 1024 chars.
Ingen kommentarer:
Send en kommentar