Sdk conexión SAP b1

Hola buen día por medio de este mensaje quiero saber quién ha logrado conectar el SDK o diapi con el visual studio 2010 para poder desarrollar addon o aplicaciones ya que tengo en mente una aplicación para subir en automático los XML a la carpeta de anexos de SAP b1 y copiar el uuid a póliza y factura a proveedor si alguien tiene una idea se aceptan comentsfios

si puedar cerrar este foro de ayuda ya que nadie le ha dado seguimiento

Lleva poco tiempo, hay que ser paciente, que nadie responda no significa que nadie sepa y deba cerrarse :slight_smile:

Por cierto, usaste el buscador? Hay varios temas sobre esto.

Y recuerda que los temas se cierran solos automáticamente, no es necesario solicitar el cierre.

Saludos

gracias @SidV saludos y gracias tomare esto en cuenta sobre el cierre automatico

Hola estimado.
Yo me he conectado a visual basic 6. Te dejo el codigo espero te sirva.(algunos comandos tendrás que adaptarlos)

El nombre del form, y el nombre del boton dependen de tu aplicacion.
Además del codigo que te muestro abajo, tenes que previamente instalar (en donde tenes visual studio) el DIAPI de la version de SAP B1 que tienes en tu servidor luego habilitarlo desde el visual studio.

La variable “conectado” es una variable boolean, tipo global, que uso solo para saber si ya estaba previamente conectado, la podés obviar del codigo.

El codigo de coneccion es este. Espero te sirva para visual studio 2010.
Nos comentás.

Saludos.


Private Sub Command2_Click()
'boton iniciar
        Dim lRetCode As Integer
            
        If conectado = False Then            
            sc.Server = "ServerName"    
            sc.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2008 'version de SQL
            
            sc.CompanyDB = "DATABASENAME" 'El nombre de tu base de datos
            sc.UseTrusted = False
            sc.DbUserName = "sa"
            sc.DbPassword = "passwordsa" ' el password del sa de tu database
            sc.UserName = "manager"
            sc.Password = "managerclave" 'clave del manager de SAP B1 u otro usuario con licencia profesional y de preferencia que sea superusuario.
            sc.language = SAPbobsCOM.BoSuppLangs.ln_English
            frmPicking.Caption = sc.CompanyDB
            lRetCode = sc.Connect()
            
            If lRetCode = 0 Then
                conectado = True
                frmPicking.Caption = sc.CompanyDB
                frmPicking.lblstatus = "Estatus=Conectado"
                frmPicking.Refresh
                MsgBox "Coneccion a SAP realizada exitosamente.", 

vbInformation
            Else
                conectado = False
                frmPicking.Caption = sc.CompanyDB
                frmPicking.lblstatus = "Estatus=Desconectado"
                frmPicking.Refresh
                MsgBox "Coneccion a SAP NO realizada.", vbCritical
            End If
        Else
            MsgBox "Ya esta conectado.", vbCritical
        End If
End Sub

Ya tengo instalado dipi quería ver si tengo que modificar alguna configuración y copiarlo en la carpeta del visual no se si tengan algún ejemplo o tuyo soy nuevo en esto y quiero realizar mi primer form

Tendrías que hacer pruebas estimado. Como te comento yo lo hice en visual 6, no lo he hecho en visual studio 2010.
Yo en vb6, lo hago desde menu principal -->project --> References, y marcas la correspondiente a tu version de SAP B1

.

Como te repito esto me ha funcionado para vb6, en vs2010 tendrás que hacer tus propias pruebas.

Olvide agregarte las variables globales en el codigo.

Public sc As New SAPbobsCOM.Company
public lRetCode As Integer

Espero te sirva. Nos comentás.
Saludos.

1 me gusta

Hola, aca tienes el copy de un Blog donde especifican TODOS los modos de conexion de DI / UI con una DB o Instancia de SAP:

Presentation

Connecting a program to SAP Business One is the first thing every developer has to do and the (not so easy) answer dépends on to which part of the Platform the program has to connect.

Basically, the options are:

Connect to the Data Interface (DI-API),
Connect to the User Interface (UI-API),
Connect to the UI then to the DI,
Connect to the UI-DI then “derive” the connection to a different database,
Connect to the server data interface (DIS),
Connect to DIS thru the B1 Web Service extension.

We are now going to see all these possibilities.

As a warning, all the excerpts of program are in C# but they can easily be adapted to any other language and the target Platform is at least 8.8.
Connect to the Data Interface

By using this interface the program can gain an access to all the functionalities of the corresponding API. An interesting point here, is that the program can run on any computer provided the fact that the DI-API is installed.

Basically what has to be done to open a connection:

Get an instance of the company object (the only instance which have to be created),
Fill the mandatory parameters, which are:
    Database server,
    Database server type,
    Database name,
    License server,
    Company user name,
    Company user password.

And now the corresponding code:

 private static SAPbobsCOM.Company _company;
        private static int ConnectDI()
        {
            int returnValue = -1;
            _company = new SAPbobsCOM.Company();
            _company.Server = "192.168.90.118";
            _company.DbServerType = BoDataServerTypes.dst_MSSQL2008;
            _company.CompanyDB = "DB_TestConnection";
            _company.LicenseServer = "192.168.90.118:30000";
            _company.UserName = "manager";
            _company.Password = "password";
            try
            {
                returnValue = _company.Connect();
            }
            catch (Exception exception)
            {
                Console.WriteLine("Exception occurred: {0}", exception.Message);
            }
            return returnValue;
        }

The only thing here is that the license server string has to fully identify the service, so it has to include the port number.

When the work of the program is done, then it is mandatory to disconnect and to free the used objects. The next excerpt shows how:

 int diConnect = ConnectDI();
            if (0 == diConnect)
            {
                _company.Disconnect();
            }             Marshal.FinalReleaseComObject(_company);

The last line will free all instances of the COM object, allowing the garbage collector to get back the used memory.
Connect to the User Interface

A program can be connected to the user interface of the ERP, meaning to the local fat client. The way to do it is a bit different:

The program has to get an instance of the current Gui manager (DCOM server),
Connect to the application’s instance, thru a context string which identifies the development license Under which the program is developped.

The corresponding excerpt of program is the following:

   private static SAPbouiCOM.Application _application;
        private static int ConnectUI(string connectionString = "")
        {
            int returnValue = 0;
#if DEBUG
            if (string.IsNullOrEmpty(connectionString))
            {
                connectionString = "0030002C0030002C00530041005000420044005F00440061007400650076002C0050004C006F006D0056004900490056";
            }
#endif
            var sboGuiApi = new SboGuiApi();
            sboGuiApi.Connect(connectionString);
            try
            {
                _application = sboGuiApi.GetApplication();
            }
            catch (Exception exception)
            {
                var message = string.Format(CultureInfo.InvariantCulture, "{0} Initialization - Error accessing SBO: {1}", "DB_TestConnection", exception.Message);
                Console.WriteLine(message);
                returnValue = -1;
            }
            Marshal.FinalReleaseComObject(sboGuiApi);
            return returnValue;
        }

The only trick here, is the use of the development context string, which allows to debug the program.
Connect to UI and DI

This type of connection will give the program a full access to all of the ERP’s API. It has to be noted that the way to connect has evolved with the version 8.8 of the ERP, allowing now to use the internal DI connection of the UI instead of having to create a specific DI connection: the direct results are a faster usage of the API and a smaller memory footprint.

Here is how to do it:

 private static int ConnectUIDI(string connectionString = "")
        {
            int returnValue = ConnectUI(connectionString);
            if (0 == returnValue)
            {
                try
                {
                    _company = (SAPbobsCOM.Company)_application.Company.GetDICompany();
                }
                catch (Exception exception)
                {
                    var message = string.Format(CultureInfo.InvariantCulture, "{0} Initialization - Error accessing SBO: {1}", "db_TestConnection", exception.Message);
                    Console.WriteLine(message);
                    returnValue = -1;
                }
            }
            return returnValue;
        }

There is nothing specific to note in this code.
Deriving a connection

Sometimes, it is necessary for the program being written to connect on the current fat client using the previous method and to temporarely open a connection on a different database, by using the same user. Since caching (even crypted) the password of any or all of the users is not an option, we have to:

Create a new company object,
Ask the APIs to fill its properties with the values of the opened connection,
Change the database on which to connect,
Finally connect.

Here is the corresponding code:

int uidiConnect = ConnectUIDI();
if (0 == uidiConnect)
{
SAPbobsCOM.Company comp2 = new SAPbobsCOM.Company();
try
{
var cookie = comp2.GetContextCookie();
var context = _application.Company.GetConnectionContext(cookie);
comp2.SetSboLoginContext(context);
comp2.CompanyDB = “DB_TestConnection2”;
var retCode = comp2.Connect();
if (0 == retCode)
{
Console.WriteLine(“Gui connected to {0}”, _company.CompanyName);
Console.WriteLine(“New connection to {0}”, comp2.CompanyName);
Console.ReadLine();
}
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
}
finally
{
Marshal.FinalReleaseComObject(comp2);
}
}

There is nothing specific to note Inside this code.
Connect to DI-Server

To use this API, we have to generate xml documents and to send them to the COM interface of the SBODI_Server service.

Because of the verbosity of xml, the corresponding code excerpt is a bit longer:

    private static int LastErrorCode;
    private static string LastErrorDescription;
    private static readonly Node DisObject = new Node();
    private static string ConectDIS()
    {
        string returnValue = string.Empty;
        var enveloppeLogon = "<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"><env:Body><dis:Login xmlns:dis=\"http://www.sap.com/SBO/DIS\"><DatabaseServer>{0}</DatabaseServer><DatabaseName>{1}</DatabaseName><DatabaseType>{2}</DatabaseType><CompanyUsername&gt:{3}</CompanyUsername><CompanyPassword>{4}</CompanyPassword><Language>{5}</Language><LicenseServer>{6}</LicenseServer></dis:Login></env:Body></env:Envelope>";
        var xmlString = string.Format(CultureInfo.InvariantCulture,
            enveloppeLogon,
            "192.168.90.118",
            "DB_TestConnection",
            "dst_MSSQL2008",
            "manager",
            "password",
            "ln_English",
            "192.168.90.118:30000");
        var sb = new StringBuilder();
        sb.Append("<?xml version=\"1.0\" ?>").Append(xmlString);
        var soapMessage = sb.ToString();
        returnValue = DisObject.Interact(soapMessage);
        if (0 == LastErrorCode)
        {
            var xmlDocument = new XmlDocument();
            xmlDocument.LoadXml(returnValue);
            var sessionNode = xmlDocument.SelectSingleNode("//*[local-name()='SessionID']");
            if (null != sessionNode)
            {
                returnValue = sessionNode.InnerText;
                Console.WriteLine("Connected to DIS. SessionId: {0}", returnValue);
            }
        }
        return returnValue;
    }

Connect to DIS thru B1WS

The web service wrapper provided by SAP allow the programmer to use the services prodided by DIS, in a much easier manner. This interface has eveolved over time and is now in the version 1.2 which is specific to the 9.0 version of the ERP.

To ease the integration of web-serevices, the author is personally using SoapUI in its open-source version.

The connection functionality is done thru the LoginService and after having referenced its specific wsdl and created a request to the Login verb, we get (and modify) the xml definition of the message:

<soapenv:Envelope xmlns:soapenv=“http://schemas.xmlsoap.org/soap/envelope/” xmlns:log=“LoginService”>
soapenv:Header/
soapenv:Body
log:Login
log:DatabaseServer192.168.90.118</log:DatabaseServer>
log:DatabaseNameDB_TestConnection</log:DatabaseName>
log:DatabaseTypedst_MSSQL2008</log:DatabaseType>
log:CompanyUsernamemanager</log:CompanyUsername>
log:CompanyPasswordKuldip</log:CompanyPassword>
log:Languageln_English</log:Language>
log:LicenseServer192.168.90.118:30000</log:LicenseServer>
</log:Login>
</soapenv:Body>
</soapenv:Envelope>

Conclusion

This is it for this document and while some specifics have not been covered (i.e. Single Sign On mode from version 9.0), this post reviewed all the ways (using the various APIs) to connect onto the ERP in an efficient manner.

Full working project (VisualStudio 2012) is attached to this document, so don’t hesitate to have a look at it.

Don’t forget to vote! and good programming.

:information_source: Fuente: h_tps://blogs.sap.com/2014/07/28/connecting-an-add-on-to-sap-business-one/

2 Me gusta

Estimado, en la carpeta C:\Program Files (x86)\SAP\SAP Business One SDK\Samples están todos los ejemplos para DI API e UI API en C# y VB

Saludos

3 Me gusta

Este tema se cerró automáticamente 7 días después del último post. No se permiten nuevas respuestas.