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)

AIF: Add Services reference dynamically , is there any way ?

(0) ShareShare
ReportReport
Posted on by

 Hi Guys ,

Kindly help me out , I want to add services reference(WSDL services) in AX , but that should be dynamically or runtime , I have one field at form level which will have url ... I know we can add reference in .net via creating C# project but what if same thing I want to do dynamically , In short "Add Services reference" should be done by code or complex parameter link class should be able to pass via web URL ....

any good link or code, job would be Appreciated....

Thanks

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    Does it mean that you don't know what kind of service will be there? How are you going to call it if you don't know what it is? Maybe you're able to add the reference and generate proxy classes (which is clearly a design-time step) and you merely want to take the actual address from a parameter, which is a completely different problem. In such a case, you want to add a reference as usual; you'll update the address only at run-time.

    If you're really going to support services unknown at design-time, you probably should call the service directly without generating proxy classes, although you also can generate them on demand if needed.

  • Community Member Profile Picture
    on at

    Thanks Martin for reply , My problem is want to create/ call web services which will have same Parameter and same runable code at back but hosted on different location that means will have different url and end points...

    you mentioned call services directly without proxy ... could you kindly give a brief idea how i could do that ,

    suppose if i want to access www.restfulwebservices.net/.../CurrencyService.svc   mention wsdl , how i can pass complex parameters  ...  link class or collections

    I took wsdl from daxmusings.codecrib.com/.../consuming-external-webservices-in-ax.html

    Regards

    AMT

  • Verified answer
    Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    If you want to change the endpoint address only, add a service reference and generate proxy classes as usual. There is no reason to give this up.

    You just need an extra stup to set the URL from your parameter, like this:

    endpointAddress = new System.ServiceModel.EndpointAddress(yourTable.YourField);
    serviceEndpoint = serviceClient.get_Endpoint();
    serviceEndpoint.set_Address(endpointAddress);
  • Community Member Profile Picture
    on at

    Main problem is how we can create serviceClient/ proxy (without add reference) from WSDL URL

    I tried to create a client from ChannelFactory Class, ref : msdn.microsoft.com/.../ms734681(v=vs.110).aspx

    ... it gives error for endpoints

               string url = "http://DAXAOS01:XXXX/DynamicsAx/Services/DataPull";

               BasicHttpBinding myBinding = new BasicHttpBinding();

               EndpointAddress myEndpoint = new EndpointAddress(url);

               ChannelFactory<DAXMapperServiceContract> channel = new ChannelFactory<DAXMapperServiceContract>(myBinding, myEndpoint);

               DAXMapperServiceContract wcfClient1 = channel.CreateChannel();

               //System.Collections.IList custList = (System.Collections.IList)wcfClient1.retrieveCustomerIds();

               System.Collections.IList custList = wcfClient1.retrieveCustomerIds();

               foreach (var rec in custList)

               {

                   string s = rec.ToString();

               }

               ((IClientChannel)wcfClient1).Close();

               channel.Close();

              "DAXMapperServiceContract" is the C# interface (Service contract) with retrieveCustomerIds as a operation contract ...

    it gives error on wcfClient1.retrieveCustomerIds();

    Address or Endpoint is not valid...

    endpointAddress = new System.ServiceModel.EndpointAddress(URL); // it could help

    but we do not have serviceClient as of now and wcfClient1 would not have get_Endpoint()

    So Main thing How we can create client or proxy with out doing Add reference , I have almost created that but not able to set Address/endpoints....

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    Why exactly do you want to spend a plenty of time creating by hand something that Visual Studio will create for you? If it's true that you merely want to use a different URL, why don't you simply update the URL?

    Unless you gave me wrong information about your requirements (you need something else then just changing URL), you're going to a wrong direction. You've decided that you must avoid adding the reference, but it's not true. You can happily do it, therefore writing your current code is a waste of time.

  • Community Member Profile Picture
    on at

    Hi Martin,

    Might be it not clear , but my idea is add wsdl , create a proxy  dynamically by code,

    in given link from "daxmusings" site we have one step i.e Add web reference , by doing it VS creates proxy client to consume in code , add web reference is purely development task , so my idea is to figure out a way to avoid "Add web reference " anyhow in vs we gives url while doing add reference .

    On google I found that its possible to create a serviceProxy or client by code by Channel factory , I tried but not working  ...

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    But why? What's the business requirement behind it?

    You told me that you want to use a different URL, but that doesn't require creating proxy classes by code.

  • Ian Schofield Profile Picture
    393 on at

    If your original requirement is... Say... Interact with a currency conversión / exchange rate service in AX 2012 R2 or higher, then AX does a lot of the heavy lifting already for you.  See HariKiran Varre's comment in the link below:

    https://community.dynamics.com/ax/f/33/t/101445

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
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans