外部系统调用AX服务

1 外部系统调用AX Customer Service,默认是已当前域用户访问AX。

2 如果要模拟其他用户,可以使用CallContext 对象。

3 模拟其他用户,必须使用Business Connector的用户来执行程序,否则会报错"Unable to logon On Microsoft Dynamics"

4 可以在AX中创建"声明用户",并用Business Connector账号模拟登陆

 

实例代码:

void callCustomerService()
{
string response;
JAY_GreetingsClient client = new JAY_GreetingsClient();
try
{
CallContext context = new CallContext();
context.Company = "TPS";
context.LogonAsUser = "outcompany.com\\OutUser001";
//context.LogonAsUser = "tpsax.com\\houzejing";
context.Language = "en-us";
response = client.helloName(context, "xiangliqi");
Console.WriteLine(response);
Console.Read();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.Read();
client.Abort();
}
client.Close();
}

void callUserSessionService()
{
AX.UserSession.UserSessionInfo userSessionInfo;
AX.UserSession.UserSessionServiceClient client = new AX.UserSession.UserSessionServiceClient();
try
{
AX.UserSession.CallContext context = new AX.UserSession.CallContext();
context.Company = "TPS";
context.LogonAsUser = "tpsax.com\\houzejing";
context.LogonAsUser = "outcompany.com\\OutUser001";
context.Language = "en-us";

userSessionInfo = client.GetUserSessionInfo(context);
Console.WriteLine(userSessionInfo.UserId);
Console.WriteLine(userSessionInfo.Company);
Console.Read();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.Read();
client.Abort();
}
client.Close();
}

posted on 2015-12-30 17:21  香里七  阅读(248)  评论(0编辑  收藏  举报