Start a new topic

XML response from API

I am working on an integration in Dynamics AX 2009 against Virto http api. AX 2009 has very poor JSON support so I tried setting the Accept header to XML, but it still returns JSON. 

Is it possible to get XML from the api? 

It looks like the XML formatter was removed by mistake.

I've fixed this in the dev branch and now you can use the Accept header to choose XML or JSON.

Also I've configured JSON formatter to respond to text/html requests which is handy when testing with a browser.

Thanx! I have tried a few different API and the XML serialization is working now. 

But I am getting an serialization error from the server on the Customers API (api/members/{id}). This is the error I'm getting:


    <Message>An error has occurred.</Message>

    <ExceptionMessage>The 'ObjectContent`1' type failed to serialize the response body for content type 'application/xml; charset=utf-8'.</ExceptionMessage>


    <StackTrace />


        <Message>An error has occurred.</Message>

        <ExceptionMessage>Type 'VirtoCommerce.Domain.Customer.Model.Contact' with data contract name 'Contact:' is not expected. Consider using a DataContractResolver if you are using DataContractSerializer or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to the serializer.</ExceptionMessage>


        <StackTrace> at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeAndVerifyType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, Boolean verifyKnownType, RuntimeTypeHandle declaredTypeHandle, Type declaredType)

   at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithXsiTypeAtTopLevel(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle originalDeclaredTypeHandle, Type graphType)

   at System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)

   at System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)

   at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)

   at System.Runtime.Serialization.DataContractSerializer.WriteObject(XmlWriter writer, Object graph)

   at System.Net.Http.Formatting.XmlMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content)

   at System.Net.Http.Formatting.XmlMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)

--- End of stack trace from previous location where exception was thrown ---

   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

   at System.Web.Http.WebHost.HttpControllerHandler.&lt;WriteBufferedResponseContentAsync&gt;d__1b.MoveNext()</StackTrace>



API methods returned polymorphic types (Member) do not work with XML serialization. Please use api/contacts/{id} instead.

1 person likes this

I am getting the same error when using the contacts api (api/contacts/{id}). Both members and contacts api work fine when returning json, but fails with the above error message when returning xml.

Fixed both api/contacts/{id} and api/members/{id} in the dev branch.

Actually fixed all methods in the CustomerModuleController except Search().

Login or Signup to post a comment