Tony Lanzer
Tony Lanzer

Reputation: 291

Error with simple Acumatica contract soap api call

I'm trying to get a simple Acumatica contract-based SOAP API Get() or GetList() call to work and all I'm getting is an error:

System.ServiceModel.FaultException: 'System.ArgumentNullException: Value cannot be null. Parameter name: model

See the code below. I first tried the REST API, but couldn't get around different issues (which I'll also probably add in another post). Any ideas what the error is referring to?

using (var soapClient = new ServiceReference1.DefaultSoapClient())
{
    //Log in to Acumatica ERP
    soapClient.Login
    (
        "admin",
        "admin",
        "Company",
        null,
        null
    );

    ServiceReference1.SalesOrder orderToFind = new 
        ServiceReference1.SalesOrder
        {
            CustomerID = new ServiceReference1.StringValue { Value = "2" },
            OrderType = new ServiceReference1.StringValue { Value = "SO" },
            OrderNbr = new ServiceReference1.StringValue { Value = 
                "SO001337" },
        };

        var getOrder = soapClient.Get(orderToFind);

        var getOrders =
            soapClient.GetList(orderToFind);
}

Acumatica v17.204.0019.

Upvotes: 2

Views: 937

Answers (3)

RuslanDev
RuslanDev

Reputation: 6778

Just encountered the same error and a little ashamed to admit that solution appeared to be super simply for me: the binding was simply missing allowCookies="true" in app.config

Having enabled cookies, error ArgumentNullException: Value cannot be null. Parameter name: model got resolved:

<binding name="DefaultSoap" allowCookies="true" />

Upvotes: 6

Mike Samons
Mike Samons

Reputation: 61

The solution for me was to add the WSDL as a ServiceReference instead of a WebReference, long story. Another thing to check might be the app.config to make sure it has the correct endpoint, bindings, etc. as per Acumatica documentation.

Upvotes: 2

RuslanDev
RuslanDev

Reputation: 6778

When searching for a record, one must always work with a proper variation of the [FieldType]Search type. In your case the orderToFind object should be declared as follows:

ServiceReference1.SalesOrder orderToFind = new ServiceReference1.SalesOrder
{
    OrderType = new ServiceReference1.StringSearch { Value = "SO" },
    OrderNbr = new ServiceReference1.StringSearch { Value = "SO001337" }
};

var getOrder = soapClient.Get(orderToFind);

To export orders for the given customer, you should define the ordersToFind object as follows:

ServiceReference1.SalesOrder ordersToFind = new ServiceReference1.SalesOrder
{
    CustomerID = new ServiceReference1.StringSearch { Value = "2" },
};

var getOrders = soapClient.GetList(orderToFind);

Upvotes: 1

Related Questions