Consume web service from AX

Hi,

I am new to AX. I created a simple WebService from Visual Studio and then I added it’s reference to AX. Now how to create class for this ? And what else I need to do ?

When you add service reference to AOT, a WCF proxy class is automatically generated for you. Access it though the namespace you specified in the Add service reference dialog.

Look into Consuming external web services in Microsoft Dynamics AX 2009 for details.

Thank you so much… I have created the class and it’s compiled properly. But when we run it, it gives an error- ‘CLR Object could not be created’. Do you know the solution for this error also ?

This is a very general error. What exact call does throw the error?

Hi Martin,

I tried debugging the code, but I am not able to get the exact reason of the error.
Even I tried many things like adding assembly to GAC-UTIL.
It would be nice if you could elaborate the reason behind that error. I am not able to get, what exactly call is throwing this error.
If you want, I can share a simplified code.

OK, show us the code. It’s impossible to identify the exact problem if all what we know is that “some CLR object can’t be instantiated”.

public static server int CreateSalesOrderUsingWebServiceReference()

{

webService_kd.Service1SoapClient soapClient;

int ret;

;

try

{

// Make sure that we get permission to use the clr interop

new InteropPermission(InteropKind::ClrInterop).assert();

soapClient = new webService_kd.Service1SoapClient(’’);

// Execute one of the method in the web service

ret = soapClient.Add(4,6);

CodeAccessPermission::revertAssert();

}

catch (Exception::CLRError)

{

throw error(AifUtil::getClrErrorMessage());

}

return ret;

}

static void main(Args args)

{

;

info(strfmt("%1",webservice::CreateSalesOrderUsingWebServiceReference()));

}

I suspect that the problem is in SOAP client’s constructor - is empty string a valid configuration name? What if you use the parameterless constructor?