web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

User is not authorized for web service endpoint

(0) ShareShare
ReportReport
Posted on by 52

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)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans