在基于Acumatica Screen的API和基于合同的API之间共享登录会话

时间:2016-05-19 21:50:54

标签: acumatica

如何在基于Acumatica Screen的API和基于合同的API之间共享登录会话?

1 个答案:

答案 0 :(得分:3)

5.30.1672版本支持基于合同和基于屏幕的API之间共享会话数据。

在下面的代码段中,我们通过基于合同的API登录,检索会话cookie并在基于屏幕的API中使用它。

        string sharedCookie;

        var soapClient = new DefaultSoapClient();
            using (new OperationContextScope(soapClient.InnerChannel))
        {
            soapClient.Login("admin", "123", null, null, null);
            var responseMessageProperty = (HttpResponseMessageProperty)
                        OperationContext.Current.IncomingMessageProperties[HttpResponseMessageProperty.Name];
            sharedCookie = responseMessageProperty.Headers.Get("Set-Cookie");
        }
        try
        {
            apitest.Screen context = new apitest.Screen();
            context.CookieContainer = new System.Net.CookieContainer();
            context.Url = "http://localhost/AcumaticaCBWS/Soap/APITEST.asmx";
            context.CookieContainer.SetCookies(new Uri(context.Url), sharedCookie);

            SO301000Content salesOrdersSchema = context.SO301000GetSchema();
            var commands = new Command[]
            {
                new Value
                {
                    LinkedCommand = salesOrdersSchema.OrderSummary.OrderType,
                    Value = "SO"
                },
                salesOrdersSchema.OrderSummary.ServiceCommands.EveryOrderNbr,

                salesOrdersSchema.OrderSummary.OrderType,
                salesOrdersSchema.OrderSummary.OrderNbr,
                salesOrdersSchema.OrderSummary.Description
            };
            var orders = context.SO301000Export(commands, null, 10, false, false);
        }
        finally
        {
            soapClient.Logout();
        }
    }