Calling NAV Web Service with Codeunit 1290 (NAV 2016)

mikmik Member Posts: 79
Hello,

I'm trying to call a NAV Web Service from NAV with Codeunit 1290. (NAV 2016)

I defined a Codeunit in NAV with a simple Function

SetAndGet(_InParam : Text,VAR _Outparam :Text)

the Problem is, everytime I call the Web Service from NAV with a defined SOAP Request
<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wst="urn:microsoft-dynamics-schemas/codeunit/wstestmip">
<x:Header/>
  <x:Body>
    <wst:SetAndGet>
      <wst:_InParam>1234</wst:_InParam>
      <wst:_OutParam/>
    </wst:SetAndGet>
  </x:Body>
</x:Envelope>

The Response is always only the wsdl Definition.
<definitions targetNamespace="urn:microsoft-dynamics-schemas/codeunit/wstestmip" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:microsoft-dynamics-schemas/codeunit/wstestmip">
  <types>
    <schema elementFormDefault="qualified" targetNamespace="urn:microsoft-dynamics-schemas/codeunit/wstestmip" xmlns="http://www.w3.org/2001/XMLSchema">
      <element name="SetAndGet">
        <complexType>
          <sequence>
            <element minOccurs="1" maxOccurs="1" name="_InParam" type="string" />
            <element minOccurs="1" maxOccurs="1" name="_OutParam" type="string" />
          </sequence>
        </complexType>
      </element>
      <element name="SetAndGet_Result">
        <complexType>
          <sequence>
            <element minOccurs="1" maxOccurs="1" name="_OutParam" type="string" />
          </sequence>
        </complexType>
      </element>
    </schema>
  </types>
  <message name="SetAndGet">
    <part name="parameters" element="tns:SetAndGet" />
  </message>
  <message name="SetAndGet_Result">
    <part name="parameters" element="tns:SetAndGet_Result" />
  </message>
  <portType name="wstestmip_Port">
    <operation name="SetAndGet">
      <input name="SetAndGet" message="tns:SetAndGet" />
      <output name="SetAndGet_Result" message="tns:SetAndGet_Result" />
    </operation>
  </portType>
  <binding name="wstestmip_Binding" type="tns:wstestmip_Port">
    <binding transport="http://schemas.xmlsoap.org/soap/http" xmlns="http://schemas.xmlsoap.org/wsdl/soap/" />
    <operation name="SetAndGet">
      <operation soapAction="urn:microsoft-dynamics-schemas/codeunit/wstestmip:SetAndGet" style="document" xmlns="http://schemas.xmlsoap.org/wsdl/soap/" />
      <input name="SetAndGet">
        <body use="literal" xmlns="http://schemas.xmlsoap.org/wsdl/soap/" />
      </input>
      <output name="SetAndGet_Result">
        <body use="literal" xmlns="http://schemas.xmlsoap.org/wsdl/soap/" />
      </output>
    </operation>
  </binding>
  <service name="wstestmip">
    <port name="wstestmip_Port" binding="tns:wstestmip_Binding">
      <address location="http://client15:7047/DynamicsNAV90/WS/CRONUS%20AG/Codeunit/wstestmip" xmlns="http://schemas.xmlsoap.org/wsdl/soap/" />
    </port>
  </service>
</definitions>

Any Idea?


With kind regards
mik

Answers

  • vaprogvaprog Member Posts: 1,140
    Your request document is supposed to only contain the soap request's body content (i.e only those elements belonging to namespace wst above).

    Could you show us some code how you use Codeunit 1290, please.
  • tfranzentfranzen Member Posts: 25
    Hi,

    I'm facing the same problem. I've used the WebService example form NAV2016 (Letters) which simply transforms a string to uppercase.

    Here's my code where I'm using codeunit 1290. In CU1290 I had to Change the TextConstant ContentTypeTxt from "multipart/form-data; charset=utf-8" to "application/xml; charset=utf-8". Otherwise the call failed immedialtely.


    <Begin of Code>

    baseURL := 'http://localhost:7047/DynamicsNAV/WS/';
    systemServiceURL := baseURL + 'CRONUS%20AG/Codeunit/Letters';

    BodyTempBlob.Blob.CREATEINSTREAM(BodyContentInputStream);
    BodyContentXmlDoc := BodyContentXmlDoc.XmlDocument;

    XMLDOMMgt.AddRootElementWithPrefix(BodyContentXmlDoc,'Capitalize','',NamespaceTxt,EnvelopeXmlNode);
    XMLDOMMgt.AddElement(EnvelopeXmlNode,'inputstring','abcde',NamespaceTxt,CreatedXmlNode);

    BodyTempBlob.Blob.CREATEOUTSTREAM(BodyContentOutputStream);
    BodyContentXmlDoc.Save(BodyContentOutputStream);
    BodyTempBlob.Blob.CREATEINSTREAM(IStream);

    c1290.SetGlobals(IStream,systemServiceURL,'','');
    c1290.SetTraceMode(TRUE);
    c1290.DisableHttpsCheck;
    c1290.SetTimeout(600000);

    IF c1290.SendRequestToWebService THEN BEGIN
    c1290.GetResponseContent(ResponseInStream);

    BodyTempBlob.Blob.CREATEOUTSTREAM(ResponseOutStream);
    COPYSTREAM(ResponseOutStream,ResponseInStream);
    END ELSE
    c1290.ProcessFaultResponse('');

    UnicodeEncoding := UnicodeEncoding.UnicodeEncoding(FALSE, FALSE);
    BodyTempBlob.Blob.CREATEINSTREAM(InS);
    StreamReader := StreamReader.StreamReader(InS, UnicodeEncoding);
    MESSAGE(StreamReader.ReadToEnd);

    <End of Code>

  • ArmondsArmonds Member Posts: 66
    edited 2016-07-27
    Got the same problem, when tried to call Navision Web service through CU1290.

    Solution is, to add SOAPAction to BuildWebRequest f-n.

    For example:
    HttpWebRequest.Headers.Add( 'SOAPAction', 'urn:microsoft-dynamics-schemas/codeunit/GetAmounts');

    At the end I added new global variable GlobalSOAPAction to CU1290.
  • archer89archer89 Member Posts: 337
    best regards
    Franz Kalchmair, MVP
    Alias: Jonathan Archer

    please like / agree / verify my answer, if it was helpful for you. thx.
    Blog: http://moxie4nav.wordpress.com/
  • ArmondsArmonds Member Posts: 66
    Archer89, thank you for Your post. You really helped me, but with NAV Web service as external source it didn't worked without adding SOAPAction.
  • archer89archer89 Member Posts: 337
    ok, i will check and give you then feedback.
    will be part 3 of that blog post series. ;-)
    best regards
    Franz Kalchmair, MVP
    Alias: Jonathan Archer

    please like / agree / verify my answer, if it was helpful for you. thx.
    Blog: http://moxie4nav.wordpress.com/
Sign In or Register to comment.