Skip to main content



No record found.

Microsoft Dynamics AX forum

How to get web service with x++

Posted on by Microsoft Employee

I need to call the interface URL as below.

When i call that URL from a browser, the following 3rd party web page is popuped.


-my code is simple. 

Webresponse ended without any reaction from the area.

webresponse = webreq.GetResponse();

--- Job Class --

static void CreateWebAPI(Args _args)

System.Net.WebRequest webreq = System.Net.WebRequest::Create("">

System.IO.Stream streamstr,responsestr;

System.IO.StreamWriter streamWriter;

System.Net.WebResponse webresponse;

System.IO.StreamReader reader;



// webreq.set_ContentType('application/x-www-form-urlencoded');

// streamstr = webreq.GetRequestStream();

// streamWriter = new System.IO.StreamWriter(streamstr);


// streamWriter.Flush();

// streamWriter.Close();

// streamWriter.Dispose();

webresponse = webreq.GetResponse();

// responsestr = webresponse.GetResponseStream();

// reader = new System.IO.StreamReader(responsestr);

// info(reader.ReadToEnd());


  • Martin Dráb Profile Picture
    Martin Dráb 225,610 Super User on at
    RE: How to get web service with x++

    First of all, let me re-post your code in the right way and throw away unused code. Next time, please use Insert > Code to paste source code to this forum.

    static void CreateWebAPI(Args _args)
    	System.Net.WebRequest webreq = System.Net.WebRequest::Create(...):
    	System.Net.WebResponse webresponse;
    	webresponse = webreq.GetResponse();

    My guess is that your code throws an exception, but you aren't aware of it, because you forgot to add exception handling. The key is catching CLRError. Then there are different ways how to extract informaton from the exception; let's use a simple one:

    static void createWebAPI(Args _args)
    	System.Net.WebRequest webReq = System.Net.WebRequest::Create(...):
    	System.Net.WebResponse webResponse;
    		webResponse = webReq.GetResponse();
    	catch (Exception::CLRError)
    		throw error(AifUtil::getClrErrorMessage());

    Run the code and you'll likely learn more about what happened.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .


André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,995 Super User

Martin Dráb Profile Picture

Martin Dráb 225,610 Super User

nmaenpaa Profile Picture

nmaenpaa 101,148


Featured topics

Product updates

Dynamics 365 release plans