错误发现了SecurityNegotiationException
对SSPI的调用失败,请参阅内部异常。
通过来自visual studio 2010的电话ledgerservice将ax 2012整合到c#应用程序中 并成功调用该服务 这是代码:
try
{
NetTcpBinding binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.Message;
// binding.OpenTimeout = new TimeSpan(0,10,0);
// binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
//// binding.SendTimeout = new TimeSpan(0, 10, 0);
// binding.CloseTimeout = new TimeSpan(0, 10, 0);
//EndpointAddress address = new EndpointAddress("net.tcp://apserver:8201/DynamicsAx/Services/LedgerServices");
GeneralJournalServiceClient client = new GeneralJournalServiceClient();
//binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
client.ClientCredentials.Windows.AllowedImpersonationLevel =
System.Security.Principal.TokenImpersonationLevel.Impersonation;
/* CallContext context = new CallContext();*/
client.ClientCredentials.Windows.ClientCredential.Domain = "elsedawy";
client.ClientCredentials.Windows.ClientCredential.UserName = "administrator";
client.ClientCredentials.Windows.ClientCredential.Password = "P@ssw0rd";
//context.Company = "sdwy";
AxdLedgerGeneralJournal journal = new AxdLedgerGeneralJournal();
AxdEntity_LedgerJournalTable journalHeader = new AxdEntity_LedgerJournalTable();
journalHeader.JournalName = "Vendor Inv";
journalHeader.Name = "Vendor Inv";
AxdEntity_LedgerJournalTrans journalLine = new AxdEntity_LedgerJournalTrans();
journalLine.AccountType = AxdEnum_LedgerJournalACType.Ledger;
journalLine.AccountTypeSpecified = true;
journalLine.Company = "sdwy";
AxdType_MultiTypeAccount account = new AxdType_MultiTypeAccount();
account.Account = "12.01.01.103";
account.DisplayValue = "RTL Cash Tayran";
AxdType_DimensionAttributeValue dimValue1 = new AxdType_DimensionAttributeValue();
dimValue1.Name = "MainAccount";
dimValue1.Value = "5637144583";
/* AxdType_DimensionAttributeValue dimValue2 = new AxdType_DimensionAttributeValue();
dimValue2.Name = "MainAccount";
dimValue2.Value = "5637144583";
AxdType_DimensionAttributeValue dimValue3 = new AxdType_DimensionAttributeValue();
dimValue3.Name = "CostCenter";
dimValue3.Value = "5637145326";*/
account.Values = new AxdType_DimensionAttributeValue[1] { dimValue1/*, dimValue2, dimValue3*/ };
journalLine.LedgerDimension = account;
journalLine.AmountCurDebit = 120;
journalLine.AmountCurDebitSpecified = true;
journalHeader.LedgerJournalTrans = new AxdEntity_LedgerJournalTrans[1] { journalLine };
journal.LedgerJournalTable = new AxdEntity_LedgerJournalTable[1] { journalHeader };
client.create(null, journal);
}
catch (Exception ex)
{
string error = ex.Message;
}