Question Status

Unanswered
Shashi Sadasivan asked a question on 3 Oct 2013 11:02 PM

I Created an Endpoint (not a Local Endpoint) in Ax , and Disabled the "Default" endpoint.

I want to run a query on the services using WCF, however i cant seem to set the SourceEndpoint on the header element.

I have followed the blog msdn.microsoft.com/.../cc652581%28v=ax.50%29.aspx and this allows me to change the "LocalEndpoint". However, the SourceEndpoint element in the Header doesnt get altered.

This is my code so far. Every time i run it i get a message syaing: Endpoint Default does not exist or is disabled.

This gets logged in the Exception table

using SysSvcmod = System.ServiceModel;

using SysSvcmodChan = System.ServiceModel.Channels;

namespace DEL_AIF_Test

{

   class Program

   {

       static void Main(string[] args)

       {

           using (var client = new AxQueryService.MyAxQueryTableServiceClient())

           {

               using (SysSvcmod.OperationContextScope operContextScope = new SysSvcmod.OperationContextScope(client.InnerChannel))

               {

                   //Prepare header;

                   SysSvcmodChan.MessageHeader messageHeader;

                   messageHeader = SysSvcmodChan.MessageHeader.CreateHeader("SourceEndpoint"

                       , "schemas.microsoft.com/.../services", "MyEndpoint");

                   SysSvcmod.OperationContext.Current.OutgoingMessageHeaders.Add(messageHeader);

                   messageHeader = SysSvcmodChan.MessageHeader.CreateHeader("DestinationEndpoint"

                       , "schemas.microsoft.com/.../services", "AUBJ");

                   SysSvcmod.OperationContext.Current.OutgoingMessageHeaders.Add(messageHeader);

                   var xx = client.GetQueryTable(); //This is the service method in Ax

               }

           }

       }

   }

}

Reply
ccolombel responded on 7 Oct 2013 7:01 AM

Hello,

In Ax2009, SourceEndpoint must be set in the From's header property :

use this code to set our SourceEndpoint, and that's working (in the exemple below, my sourceEndpoint is equal to 'TEST')

                   SysSvcmod.OperationContext.Current.OutgoingMessageHeaders.From = new SysSvcmod.EndpointAddress(new Uri("urn:TEST"));

Charles.

Reply
Shashi Sadasivan responded on 7 Oct 2013 2:18 PM

Hi Charles, I had tried something like tht from another blog. But this is the error i get from the code you gave

Unhandled Exception: System.InvalidOperationException: Addressing Version 'Addre

ssingNone (schemas.microsoft.com/.../none)' does not su

pport adding WS-Addressing headers.

  at System.ServiceModel.Channels.MessageHeaders.ValidateHeaderKind(HeaderKind

headerKind)

  at System.ServiceModel.Channels.MessageHeaders.InsertHeader(Int32 headerIndex

, Header header)

  at System.ServiceModel.Channels.MessageHeaders.Insert(Int32 headerIndex, Mess

ageHeader header, HeaderKind kind)

  at System.ServiceModel.Channels.MessageHeaders.SetHeaderProperty(HeaderKind k

ind, MessageHeader header)

  at System.ServiceModel.Channels.MessageHeaders.set_From(EndpointAddress value

)

I am running the console application as a .net 4 application.

Reply