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

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

send data to a external web service x++

(0) ShareShare
ReportReport
Posted on by

Hi everyone.

I've been doing some research about how to send some (tentatively big amount of) data to an external web service.

I've encountered contradictory opinions about sending the information inside an XML document and I'm starting to get a bit muddled about which is the best approach for this case.

The web service should be called only once per day (of x time period... it hasn't been defined yet) sending all the information in one attempt.

so in your opinion, which option is more reliable for this case and why?

if is the xml document option, i could not find how exactly send it from x++ to the receiver aplication. i'd be really thankful if anyone can provide an example.

*This post is locked for comments

I have the same question (0)
  • Mea_ Profile Picture
    60,284 on at
    RE: send data to a external web service x++

    Hi luis torres,

    It's well documented here blogs.msdn.microsoft.com/.../consuming-external-wcf-services-from-dynamics-ax-2009-x-code-dynamics-ax-5-0

    Idea behind is to create a proxy .Net library and call it from x++. It could be done manually or using VS studio or AX, so .Net library will be responsible for xml message creation and transport.

  • Martin Dráb Profile Picture
    236,513 Most Valuable Professional on at
    RE: send data to a external web service x++

    The best approach depends on several things.

    In general, sending a huge amount of data in a single buffered SOAP message isn't a good idea, because you would run into a limit of the buffer size and possibly other limits such as time outs.

    If you want to use WCF, you can split the data to several smaller messages or use streaming.

    Web services also aren't the only possible approach. For example, you could export the data to a file and transfer the file.

  • Community Member Profile Picture
    on at
    RE: send data to a external web service x++

    hi ievgen, i actually had already read that blog, although its really clear how we can call an externar web service i don't get to see how we can pass the xml file as a parameter and how the external service will be processing this file.

    i mean can i create a simple class like:

    static void createXMLFile (Args _Args)

    {

       //xmlvariables

       //instanciate objects

       while select table

       {

             //inicialize variables

             //insert data in file

       }

    }

    and send the created file thought another class?

  • Community Member Profile Picture
    on at
    RE: send data to a external web service x++

    hi martin, thanks for your reply, looks like mi boss overstate "massive data" he has example of the files that would be sending to the web service and the heaviest is about 15 kb, it's actually possible that this size could cause over limit or tome outs?

  • Mea_ Profile Picture
    60,284 on at
    RE: send data to a external web service x++

    Read a file into a string and pass a string or binary array.

  • Community Member Profile Picture
    on at
    RE: send data to a external web service x++

    because you are using AX2009 then it's quite hard to call a web method, but you can always create a DLL project using VS 2010 and call the dll from AX

    this is sample code to create http request to a web service

    https://stackoverflow.com/questions/4015324/how-to-make-http-post-web-request

    you can parse XML as string to put into the parameter of the method

    and this is sample code to call a DLL from AX

    http://blogs.solidq.com/en/dynamics-ax/executing-net-code-in-dynamics-ax-2009-solving-error-the-selected-file-is-not-a-valid-net-assembly/

  • Martin Dráb Profile Picture
    236,513 Most Valuable Professional on at
    RE: send data to a external web service x++

    It's actually pretty easy in AX 2009 (with SOAP web services). You add a service reference to AOT and all the managed code gets generated for you; you don't have to do it manually by yourself.

    15kb is no problem. That's not a lot.

  • Community Member Profile Picture
    on at
    RE: send data to a external web service x++

    hi iegven, can this be done with x++ code? i've searched alot how to read an xml into a string and i haven't found anything for ax, only the c# and java methods which doesn't work in ax

  • Mea_ Profile Picture
    60,284 on at
    RE: send data to a external web service x++

    Yes, look at generateXML() method in this blog post donatas.xyz/generate-xml-string.html

  • Community Member Profile Picture
    on at
    RE: send data to a external web service x++

    hello,

    I created a simple job, hope it can help

    
    
    static void Job1(Args _args)
    {
    
    	System.Net.WebRequest webreq = System.Net.WebRequest::Create("your address");
    
    	System.IO.Stream streamstr,responsestr;
    
    	System.IO.StreamWriter streamWriter;
    
    	System.Net.WebResponse webresponse;
    
    	System.IO.StreamReader reader;
    	
    	XmlDocument xmldoc;
    	;
    	//do stuff with your xmldoc
    	
    	//
    	webreq.set_Method("POST");
    
    	webreq.set_ContentType('application/x-www-form-urlencoded');
    
    	streamstr = webreq.GetRequestStream();
    
    	streamWriter = new System.IO.StreamWriter(streamstr);
    
    	streamWriter.Write(System.Web.HttpUtility::UrlEncode("xmlcontent="+xmldoc.toString()));//xmlcontent is a parameter of your webservice (replace it with your web service parm)
    
    	streamWriter.Flush();
    
    	streamWriter.Close();
    
    	streamWriter.Dispose();
    
    	webresponse = webreq.GetResponse();
    
    	responsestr = webresponse.GetResponseStream();
    
    	reader = new System.IO.StreamReader(responsestr);
    
    	info(reader.ReadToEnd());
    
    }

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#2
Community Member Profile Picture

Community Member 2

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans