Seite 1 von 1

WebService Codeunit Parameter übergeben

Verfasst: 21. Juli 2015 09:48
von TraderJoe
Moin moin,

kurze Frage:
Wie kann ich bei einer Codeunit die ich über den WebService aufrufe zwei Parameter mitgeben?...

Code:
Path := FileMgt.Magicpath();

XMLRequestDoc := XMLResponseDoc.XmlDocument;

XMLElement1 := XMLRequestDoc.CreateElement('soap','Envelope','http://schemas.xmlsoap.org/soap/envelope/');
XMLElement1.SetAttribute('xmlns:ws','urn:microsoft-dynamics-schemas/codeunit/Testcodeunit');

XMLElement2 := XMLRequestDoc.CreateElement('soap','Body','http://schemas.xmlsoap.org/soap/envelope/');
XMLElement3 := XMLRequestDoc.CreateElement('ws','Insert','urn:microsoft-dynamics-schemas/codeunit/Testcodeunit');

XMLNode4 := XMLRequestDoc.CreateElement('ws','noteText','urn:microsoft-dynamics-schemas/codeunit/Testcodeunit');
XMLNode4.InnerText := '1';
XMLElement3.AppendChild(XMLNode4);

XMLNode4 := XMLRequestDoc.CreateElement('ws','toUser','urn:microsoft-dynamics-schemas/codeunit/Testcodeunit');
XMLNode4.InnerText := '1';
XMLElement3.AppendChild(XMLNode4);

XMLElement3.AppendChild(XMLNode4);
XMLElement2.AppendChild(XMLElement3);
XMLElement1.AppendChild(XMLElement2);
XMLRequestDoc.AppendChild(XMLElement1);

//XMLRequestDoc.Save('D:\Temp\RequestDotNet.xml');

HttpWebRequest := HttpWebRequest.Create(WebserviceLink);
HttpWebRequest.Timeout := 30000;
HttpWebRequest.UseDefaultCredentials(TRUE);
HttpWebRequest.Method := 'POST';
HttpWebRequest.ContentType := 'text/xml; charset=utf-8';
HttpWebRequest.Accept := 'text/xml';
HttpWebRequest.Headers.Add('SOAPAction','Insert');
MemoryStream := HttpWebRequest.GetRequestStream;
XMLRequestDoc.Save(MemoryStream);
MemoryStream.Flush;
MemoryStream.Close;

HttpWebResponse := HttpWebRequest.GetResponse;
MemoryStream := HttpWebResponse.GetResponseStream;
XMLResponseDoc := XMLResponseDoc.XmlDocument;
XMLResponseDoc.Load(MemoryStream);
MemoryStream.Flush;
MemoryStream.Close;

//XMLRequestDoc.Save('D:\Temp\Response.xml');
EXIT;

Re: WebService Codeunit Parameter übergeben

Verfasst: 22. Juli 2015 22:54
von Fido
Hallo,
indem du deinen Code in eine Funktion der Codeunit steckst und dort die Parameter definierst.

Unbenannt.PNG


Die Funktion gibt auch einen Integerwert zurrück, geht aber auch mit "VAR" Paramter, bspw. um Fehler aus NAV mit Text zurückzugeben.

MFG