We are consuming an external web service (WCF) in our AX2012 project. We followed the procedure described in the following blog. We are implementing security by passing the token in the header. However, what i am not sure of is how to do this in AX2012.

the sample code for getting the token is

static void myTestServiceWSDL(Args _args)
{
    myServiceWSDL.Proxies.Service.ServiceClient  service;
    myServiceWSDL.Proxies.Service.LoginData LoginData;
    str token;
    System.Exception ex;
    System.Type type;
   
    try
    {
        type = CLRInterop::getType('myServiceWSDL.Proxies.Service.ServiceClient');
        
        service = AifUtil::createServiceClient(type);
        LoginData = new myServiceWSDL.Proxies.Service.LoginData();
        LoginData.set_uName("test");
        LoginData.set_pwd("test");
        token=service.Login(LoginData);
        info(token);
        
    }
    catch(Exception::CLRError)
    {
        ex = CLRInterop::getLastException();
        info(CLRInterop::getAnyTypeForObject(ex.ToString()));
    }

}

The token comes back fine which confirms the code is working. Now the question is how to do i set header values for the message. If it was C# i would have done

using (MemberMasterClient proxy = new MemberMasterClient())
{
  using (OperationContextScope scope 
    = new OperationContextScope(proxy.InnerChannel))
         {
          // set the message in header
          MessageHeader header =
 MessageHeader.CreateHeader("SourceApplication", 
    "urn:spike.WCFHeaderExample:v1", 
    "WCFClient Application 2");
          OperationContext.Current.OutgoingMessageHeaders.Add(header); 
    
          Console.WriteLine("Membership Details");
          Console.WriteLine("Henry's - {0}", proxy.GetMembership("Henry"));
    
          }
         }
       }

Could any one let me know how to do the equivalent in X++ One idea which has been on my mind is to write an assembly in C# which can then be called in AX2012. Will give that a go, but the idea is to code this in X++ in AX2012

有帮助吗?

解决方案

The only thing you do differently in X++ is creating the proxy using the Aif utility. So basically, your C# example you listed, the only difference would be the proxy = new MemberMasterClient() which goes through AIF. All the other code you can take into X++ as-is (except for the "using"). You just need to have the right assemblies reference in the AOT, and use the full namespace in the code. Alternatively, as you mentioned, you can just code it all in C# and call that from AX :-)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top