
Hello,
I am trying to read Customer Information from Ax 2009 environment using AIF web services, From second Company belonging to my Ax 2009 Environment named COMP2 . I created Endpoints for Both of my companies and granted user accesses to both of them. My code is as Following:
var remoteAddress = new System.ServiceModel.EndpointAddress(new Uri("aossrv/.../customerservice.svc"), EndpointIdentity.CreateUpnIdentity(@"domain\IISHOSTUSER"));
WSHttpBinding httpBinding = new WSHttpBinding();
httpBinding.MaxReceivedMessageSize = 2147483647;
using (var customerService = new CustomerServiceClient(httpBinding, remoteAddress))
{
using (new OperationContextScope(customerService.InnerChannel))
{
Program p = new Program();
p.PrepareHeader();
customerService.Endpoint.Binding.SendTimeout = new TimeSpan(0, 0, 0, 60);
EntityKey[] entityKeyList = new EntityKey[1];
EntityKey key1 = new EntityKey();
KeyField[] keyFields = new KeyField[1];
KeyField keyField = new KeyField();
keyField.Field = "AccountNum";
keyField.Value = "BAC0002";
keyFields[0] = keyField;
key1.KeyData = keyFields;
entityKeyList[0] = key1;
AxdEntity_CustTable a = customerService.read(entityKeyList).CustTable[0] as AxdEntity_CustTable;
}
}
My prepare Header Method:
void PrepareHeader()
{
this.SetHeader_DestinationEndpoint();
this.SetHeader_SourceEndpointUser();
}
private void SetHeader_DestinationEndpoint()
{
OperationContext.Current.OutgoingMessageHeaders.Add(MessageHeader.CreateHeader(string.Format((IFormatProvider)CultureInfo.CurrentCulture, "DestinationEndpoint", new object[0]), "schemas.microsoft.com/.../services", (object)"DAXIntegration"));
}
private void SetHeader_SourceEndpointUser()
{
AddressHeader addressHeader = AddressHeader.CreateAddressHeader(string.Format((IFormatProvider)CultureInfo.CurrentCulture, "SourceEndpointUser", new object[0]), "schemas.microsoft.com/.../services", (object)("domain\\endpointuser"));
OperationContext.Current.OutgoingMessageHeaders.From = new EndpointAddressBuilder(new EndpointAddress(new Uri("urn:DAXIntegration"), new AddressHeader[1]
{
addressHeader
})).ToEndpointAddress();
}
But when i run this code, i get an exception like : user is not authorized for this endpoint
But i double checked and added all users i user to Users tab of EndPoint. Without using Prepare Header method, i get the data but, i only get data from Default Company, but i need to get data from Not Only Default Company but From All companies belonging to my AX 2009 Environment.
Can anyone please suggest me an answer?
*This post is locked for comments
I have the same question (0)