Error: Web service using web service

Hi everyone,

I’m creating an exzecutable program, that calls to a function in a codeunit published as a WebService. If I run the CU, I don’t have aby problem, but executin the exe program, I get this error:

This is the code I’m calling from the executable file:

ICforStock()

//IC
// IF NOT ISSERVICETIER THEN
//  EXIT;
// IF NOT GUIALLOWED THEN
//  EXIT;


lItem.SETCURRENTKEY("Item Category Code","Product Group Code");
lItem.SETRANGE("Item Category Code",'INSIZE');
IF lItem.FINDSET THEN REPEAT
  lItem.CALCFIELDS(Inventory,"Qty. on Sales Order");
  lCantidad := lItem.Availability;
  ICStock_CALL(lItem."No.", lCantidad);

UNTIL lItem.NEXT = 0;

ICStock_CALL(pCodprod : Code[35];pCantidad : Decimal) CabVenta : Code[20]



//Creamos conexión IC
CLEAR(xmlhttp);
CREATE(xmlhttp,FALSE,TRUE);
ICConfiguration.GET;
ICURL := ICConfiguration."IC URL";
xmlhttp.open('POST',ICURL,0,'betea','onM1crosoft1');

xmlhttp.setRequestHeader('Content-Type','text/xml; charset=utf-8');
xmlhttp.setRequestHeader('SOAPAction','FuncionesIC');
xmlhttp.setTimeouts(20000,20000,20000,200000);
xmlhttp.send('<?xml version="1.0" encoding="utf-8"?>'+
              '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" '+
              'xmlns:nav="urn:microsoft-dynamics-schemas/codeunit/FuncionesIC">'+
              '<soap:Header/>'+
              '<soap:Body>'+
              '<nav:ICStock_FUN>'+
                '<nav:pCodprod>'+pCodprod+'</nav:pCodprod>'+
                '<nav:pCantidad>'+FORMAT(pCantidad)+'</nav:pCantidad>'+
              '</nav:ICStock_FUN>'+
              '</soap:Body>'+
              '</soap:Envelope> ');

ICStock_FUN(pCodprod : Code[35];pCantidad : Text)
EVALUATE(vCantidad,pCantidad);
lItem.RESET;
IF lItem.GET(pCodprod) THEN BEGIN
  lItem."Stock In IC" := vCantidad;
  lItem.MODIFY;
END;

Any hint about this? If I don’t comment GUIALLOWED and SERVITIER, I don’t get the error, but the functions aren’t executed…

Thank you all

Does your function ICSock_CALL open any GUI (PAGE.RUN, CONFIRM, MESSAGE, etc)? This error message is what you usually get when a GUI element is called in a session which does not interact with the user interface. In web services GUI is not allowed, so if you uncomment the statement IF NOT GUIALLOWED THEN EXIT, the subsequent code is not executed.

Hi Alexander.

I’ve solved the issue using DOTNET variabels instead automations:

ICStock_CALL(pCodprod : Code[35];pCantidad : Decimal) CabVenta : Code[20]
 ICConfiguration.GET;
 ICURL := ICConfiguration."IC URL";

IF ISNULL(DotNetXmlDoc) THEN
DotNetXmlDoc := DotNetXmlDoc.DOMDocumentClass;

IF ISNULL(DotNetXmlHttp) THEN
DotNetXmlHttp := DotNetXmlHttp.XMLHTTPRequestClass;

DotNetXmlHttp.open('POST',ICURL,0,'betea','onM1crosoft1');


DotNetXmlHttp.setRequestHeader('Content-Type','text/xml; charset=utf-8');

DotNetXmlHttp.setRequestHeader('SOAPAction','ICStock_FUN');

DotNetXmlHttp.send('<?xml version="1.0" encoding="utf-8"?>'+
              '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" '+
              'xmlns:nav="urn:microsoft-dynamics-schemas/codeunit/FuncionesIC">'+
              '<soap:Header/>'+
              '<soap:Body>'+
              '<nav:ICStock_FUN>'+
                '<nav:pCodprod>'+pCodprod+'</nav:pCodprod>'+
                '<nav:pCantidad>'+FORMAT(pCantidad)+'</nav:pCantidad>'+
              '</nav:ICStock_FUN>'+
              '</soap:Body>'+
              '</soap:Envelope> ');

https://rockwithnav.wordpress.com/2016/02/23/consume-net-webservice-dotnet-data-type/

https://rockwithnav.wordpress.com/2016/02/23/consume-net-webservice-automation/

Check this out.