Options

Nav to Nav Webservice

prototyperprototyper Member Posts: 70
edited 2010-10-28 in NAV Three Tier
Is it possible to have Navision call another Navisions webservice?

I have the following code but I am getting a SQL Logon permission error in the resulting xml.
Will I have to use a C# program with credentials to overcome this ?
CREATE(locautSoapHttpConnector);
CREATE(locautSoapSerializer);
CREATE(locautXmlDoc);

locautSoapHttpConnector.Property('EndPointURL', 'http://servername:7047/DynamicsNAV/ws/coduenit/');
locautSoapHttpConnector.Connect; //WSDL('7047');
locautSoapHttpConnector.Property('AuthUser', 'Adminuserid');
locautSoapHttpConnector.Property('AuthPassword', 'Adminpsw');
locautSoapHttpConnector.Property('Timeout', 5 * 1000);
locautSoapHttpConnector.Property('SoapAction','http://servername:7047/DynamicsNAV/ws/coduenit/thefunction');
locautSoapHttpConnector.BeginMessage;

locautSoapSerializer.Init(locautSoapHttpConnector.InputStream);
locautSoapSerializer.startEnvelope('SOAP','STANDARD');
locautSoapSerializer.startBody;
locautSoapSerializer.startElement('Type');
locautSoapSerializer.writeString(FORMAT(Type));
locautSoapSerializer.endElement;
locautSoapSerializer.startElement('ID');
locautSoapSerializer.writeString(FORMAT(ID));
locautSoapSerializer.endElement;
locautSoapSerializer.endBody;
locautSoapSerializer.endEnvelope;
locautSoapHttpConnector.EndMessage;

locautXmlDoc.load(locautSoapHttpConnector.OutputStream);
locautXmlDoc.save('c:\temp\tempOut.xml');
Sleep on it... The best solutions come at 2am

Comments

  • Options
    deV.chdeV.ch Member Posts: 543
    Are you able to connect to the database directly with this user?
  • Options
    prototyperprototyper Member Posts: 70
    yes using windows authentication. The user is not a database user (not sure if that makes any difference)
    Sleep on it... The best solutions come at 2am
  • Options
    deV.chdeV.ch Member Posts: 543
    I'am not sure but I think when you set a user with locautSoapHttpConnector.Property('AuthUser',... this can't be used with a windows user!

    if the user is the one your logged on then don't use the "auth user" propertys, if it works like in c# then it automaticly uses your windows user for authentication.

    otherwise if you need to specify the user by code, then i suggest to use a normal DB-user, such a user can be used for "AuthUser" Property.


    Warning: I never done this in NAV but if it works the same as in c# (I think so) then this is the way to go.
  • Options
    prototyperprototyper Member Posts: 70
    Thanks I did try it with a dbuser and received an instance create error message on the "EndMessage"

    Any other suggestions ?
    Sleep on it... The best solutions come at 2am
  • Options
    deV.chdeV.ch Member Posts: 543
    With de db user you can connect directly to nav?

    edit: why are you connecting before you set the login (user/pw) parameters?

    Try using .connect after you entered the login.
  • Options
    prototyperprototyper Member Posts: 70
    Thanks Dev.

    I can connect to Navision using the Db user I was using.

    Moving the Connect to after the user/psw gives the same issue as using a db user. IE an Instance create error on the EndMessage.
    It appears as though it needs user/psw for NT authentication in the Connection to create the soap message.
    Is there a separate property or way of passing in a user/psw through the EndPoint or Soapaction or indicate that it should run using window authentication and not db?
    Sleep on it... The best solutions come at 2am
  • Options
    anieanie Member Posts: 14
    You can try with this value in the Soap Action and the code works for Web Method without parameters.
    CLEAR(locautSoapHttpConnector);
    CLEAR(locautSoapSerializer);
    CLEAR(locautXmlDoc);
    
    CREATE(locautSoapHttpConnector);
    locautSoapHttpConnector.Property('EndPointURL','http://localhost:7047/DynamicsNAV/WS/Company/Codeunit/TestWebService');
    locautSoapHttpConnector.Connect;
    locautSoapHttpConnector.Property('Timeout', 5 * 1000);
    locautSoapHttpConnector.Property('SoapAction','http://schemas.xmlsoap.org/disco/scl/HelloNAV');
    
    locautSoapHttpConnector.BeginMessage;
    CREATE(locautSoapSerializer);
    locautSoapSerializer.Init(locautSoapHttpConnector.InputStream);
    locautSoapSerializer.startEnvelope('SOAP','STANDARD');
    locautSoapSerializer.startBody;
    locautSoapSerializer.startElement('HelloNAV');
    locautSoapSerializer.endElement;
    locautSoapSerializer.endBody;
    locautSoapSerializer.endEnvelope;
    locautSoapHttpConnector.EndMessage;
    
    locautXmlDoc.load(locautSoapHttpConnector.OutputStream);
    locautXmlDoc.save('C:\Temp\hellonav.xml');
    

    but with parameters, I am again getting this message:
    <faultcode xmlns:a="urn:microsoft-dynamics-schemas/error">a:Microsoft.Dynamics.Nav.Service.WebServices.ServiceBrokerException</faultcode> 
      <faultstring xml:lang="en-US">Parameter input in method HelloWorld in service TestWebService is null!</faultstring> 
    - <detail>
      <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">Parameter input in method HelloWorld in service TestWebService is null!</string> 
      </detail>
    

    the code used is:
    CLEAR(locautSoapHttpConnector);
    CLEAR(locautSoapSerializer);
    CLEAR(locautXmlDoc);
    
    paramText := 'Dynamics';
    CREATE(locautSoapHttpConnector);
    locautSoapHttpConnector.Property('EndPointURL','http://localhost:7047/DynamicsNAV/WS/Company/Codeunit/TestWebService');
    locautSoapHttpConnector.Connect;
    locautSoapHttpConnector.Property('Timeout', 5 * 1000);
    locautSoapHttpConnector.Property('SoapAction','http://schemas.xmlsoap.org/disco/scl/HelloWorld');
    
    locautSoapHttpConnector.BeginMessage;
    CREATE(locautSoapSerializer);
    locautSoapSerializer.Init(locautSoapHttpConnector.InputStream);
    locautSoapSerializer.startEnvelope('SOAP','STANDARD');
    locautSoapSerializer.startBody;
    xmlText := '<HelloWorld xmlns="http://schemas.xmlsoap.org/wsdl/soap/"><input>'+paramText+'</input></HelloWorld>';
    locautSoapSerializer.writeXML(xmlText);
    locautSoapSerializer.endBody;
    locautSoapSerializer.endEnvelope;
    locautSoapHttpConnector.EndMessage;
                       
    CREATE(locautXmlDoc);
    locautXmlDoc.load(locautSoapHttpConnector.OutputStream);
    locautXmlDoc.save('C:\Temp\helloworld.xml');
    
    Please suggest
Sign In or Register to comment.