SBX - Search With Button

SBX - Forum Post Title

Custom Web Service

Microsoft Dynamics AX Forum

Norseman asked a question on 13 Jul 2018 3:29 PM

Question Status

Verified

Hi All,

I have created a Web service on AX.  I created an operation 'createPurchaseOrder' and a method in the class.  I want to call this url from my browser.  Looks like the base url without any parameters works fine, but when I added the method name prefix with '?' i.e. http://<servername>:8101/DynamicsAx/Services/My_WebServices?createPurchaseOrder doesn't work.  Any insight into this issue?

Here is an update. I got WSDL from above. It is not an issue.  I am trying to consume the AX custom service in ASP .Net Web API. Here is the code, which gives an error 'Update has been cancelled'. There is no inner exception. Please share your thoughts on what could be an issue?

public class ValuesController : ApiController
{
// GET api/values
public IEnumerable<string> Get()
{
try
{
NOR_WebServicesRef.NOR_WebServiceCreatePurchaseOrderClient poserviceclient = new NOR_WebServicesRef.NOR_WebServiceCreatePurchaseOrderClient();
poserviceclient.createPurchaseOrder(new NOR_WebServicesRef.CallContext());
return new string[] { "value1", "value2" };

}
catch(Exception ex)
{
return new string[] { "error", ex.Message };

}

}

Reply
Norseman responded on 15 Jul 2018 8:24 AM

Please look at the updated post.

Reply
Martin Dráb responded on 16 Jul 2018 7:19 AM
Verified Answer

"Update has been cancelled" comes from AX, therefore you should debug X++ code called from your web service.

You can try to simply call your service class from a job and debug it as any X++ code, or you can debug the actual web service with VS debugger (see Debugging in Microsoft Dynamics AX 2012 > Services).

Reply
Norseman responded on 16 Jul 2018 9:26 AM

Thanks Martin.. That was helpful..I debugged..found that it is creating PO for some random company (not my default) so it is throwing 'Item not found' error.  How do I set the company in my code? It may be naive question though..

Reply
Norseman responded on 16 Jul 2018 9:54 AM

Never mind! I have to put my code with changeCompany'XX'{}.. It works fine.. Thanks

Reply
Martin Dráb responded on 16 Jul 2018 10:44 AM

You can set a company in the CallContext object that you pass to createPurchaseOrder().

By default, it uses the default company of the account under which the code is executed.

Reply
Martin Dráb responded on 16 Jul 2018 7:19 AM
Verified Answer

"Update has been cancelled" comes from AX, therefore you should debug X++ code called from your web service.

You can try to simply call your service class from a job and debug it as any X++ code, or you can debug the actual web service with VS debugger (see Debugging in Microsoft Dynamics AX 2012 > Services).

Reply

SBX - Two Col Forum

SBX - Migrated JS