Hello.
I have created a static method in a class, as the code below is showing.
He is without any errors, just Warning message: "MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "Microsoft.Dynamics.AX.ManagedInterop", "x86". This mismatch may cause runtime failures. Please consider changing" who I think it's just a minor thing, because I'm running on Remote Desktop on the AX2012R3 Demo VM
I created a job who is like this:
staticvoid Job1(Args _args)
{
MyClass::notMarshall();
}
But I got error message - and notice, it's TWO times for ONE run:
CLR object cannot be marshaled to Microsoft Dynamics anytype.
CLR object cannot be marshaled to Microsoft Dynamics anytype.
As it is descripted in the code below, who I fount in a book from PACKT publishing:
// Let AIFUtil create the proxy client because it uses the VSAssemblies path for the config file
client = AifUtil::createServiceClient(type);
But that don't seems to work.
I have also tried to marshall throgh code by using information from this link: http://msdn.microsoft.com/en-us/library/bb986175(v=ax.10).aspx - and I used how to marshall System.String example. When I did that I just got an info windows with just NOTHIN in it - empty message with in Info icon.
Have anyone clue about whatr is happening here: Do I have to do some arrangements about connecting with the webservice on some unusual way?
So I have to use the client and close him at the end like client.Close(); ?
Do I have to set some permission like this:
permission = new InteropPermission(InteropKind::ClrInterop);
permission.assert();
and at the end of the code:
CodeAccessPermission::revertAssert();
The belowed code is like the PACKT book introduce, and I have integrade him by instruction from the service provider:
publicstaticvoid notMarshall()
{
// Determine variable from .NET Service Ref
MyNamespace_1.Client client;
MyNamespace_1.SetInfo input;
MyNamespace_1.GetInfo output;
// determine system variables
System.ServiceModel.Description.ServiceEndpoint endpoint;
System.ServiceModel.EndpointAddress endpointAddress;
System.Exception exception;
System.Type type;
;
//Initialising
input = new MyNamespace_1.SetInfo();
output = new MyNamespace_1.GetInfo();
try
{
//get the .NET type of the client proxy
type = CLRInterop::getType('MyNamespace_1.Client');
// Let AIFUtil create the proxy client because it uses the VSAssemblies path for the config file
client = AifUtil::createServiceClient(type);
//create and endpoint address, This should be a parameter stored in the system
endpointAddress = new System.ServiceModel.EndpointAddress("https://securep.austaxagency.com.au/VAT/WS/VATService.svc");
// Set endpoint
endpoint = client.get_Endpoint();
//set endpoint address
endpoint.set_Address(endpointAddress);
//call the parameters
input.set_Id('1234567890');
input.set_softwVers("version01");
input.set_password("passvord");
//Use the getAnyTypeForObject to marshal the System.String to an AX anytype
info(strFmt('%1', CLRInterop::getAnyTypeForObject(output.get_Error())));
}
catch(Exception::CLRError)
{
// Get the .NET Type Exception
exception = CLRInterop::getLastException();
// Go through the inner exceptions
while(exception)
{
// Print the exception to the infolog
info(CLRInterop::getAnyTypeForObject(exception.ToString()));
// Get the inner exception for more details
exception = exception.get_InnerException();
}
}
}