Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Unanswered

How to get web service with x++

Posted on by Microsoft Employee

I need to call the interface URL as below.

http://devgw.OOOO.co.kr/approval/legacy/goFormLink.do?mode=DRAFT&logonId=220409&ERPworkkey=20220819094015&legacyFormID=WF_FORM_075&dataType=JSON

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

0456.fix.png

-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("">devgw.OOOO.co.kr/.../goFormLink.do

System.IO.Stream streamstr,responsestr;

System.IO.StreamWriter streamWriter;

System.Net.WebResponse webresponse;

System.IO.StreamReader reader;


webreq.set_Method("Get");

webreq.set_ContentType('application/Json');

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

// streamstr = webreq.GetRequestStream();

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

//streamWriter.Write("CountryName=New+Zealand");

// 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;
    
    	webreq.set_Method("Get");
    	webreq.set_ContentType('application/Json');
    
    	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;
    
    	try
    	{
    		webReq.set_Method("Get");
    		webReq.set_ContentType('application/Json');
    
    		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 . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 225,610 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans