XML serialization error in ASMX service

I wrote an asmx in 4.5.1 and below is the code . But always getting error . Not sure what is wrong here. If u have any code snippets for this that will really help

To be XML serializable, types which inherit from IEnumerable must have an implementation of Add(System.Object) at all levels of their inheritance hierarchy. System.Net.Http.Headers.HttpContentHeaders does not implement Add(System.Object).

public HttpResponseMessage GetProductImages ()

string ret = String.Empty;
string url = “”; // url to be requested
System.Net.Http.HttpRequestMessage request;
using (var client = new HttpClient ())
// we make TLS 1.2 the default security protocol when requesting

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls;

client.Timeout = new TimeSpan (0, 2, 0); // 2 min

request = new System.Net.Http.HttpRequestMessage();
var response = client.GetAsync (url) .Result;

if (response.IsSuccessStatusCode)
ret = response.Content.ReadAsStringAsync (). Result;
var msg = “url:” + url + “\n”

  • “StatusCode:” + response.StatusCode.ToString () + “\n”
  • “ReasonPhrase:” + response.ReasonPhrase;
    throw new Exception (msg);




return request.CreateResponse(System.Net.HttpStatusCode.OK, ret);



How is it related to topic of this thread (HTTP Request must use TLS Protocol version 1.2)? If it isn’t, let’s move it to a separate thread. It’s also not clear how it’s related to Dynamics AX, e.g. whether it belongs to this forum in the first place.

Martin , this is AX2009 issue as it uses 3.5 .NET and it supports only SSL3 and TLS1.0, but not TLS1.2 , So i have to write asmx and reference it in AX2009 and call its method. But im stuck in this asmx code as it throws XML serielize error . Lemme know if u need more info

Okay, so it’s indeed a different problem and I’ll move it to its own thread. The fact that both errors are related to the same business requirement doesn’t mean that they’re identical. We’ll keep discussion about “HTTP Request must use TLS Protocol version 1.2” in its own thread and discuss the problem with XML serialization elsewhere.

You didn’t mention the type of exception, so I’m adding it’s InvalidOperationException (produced by XML serializer). At least that’s the usual case.

But the crucial missing piece (which I can’t add) is where the error is coming from. I don’t see any XML serialization in the code above, therefore I assume the problem is not there. It looks like the error is coming from the service you call, but you didn’t give us any information about it.

Please go and collect more information about the exception.

error.txt (16 KB)

i martin , I have uploaded the error msg .in detail . Any windows , C$ class , asmx would work provided it can be referenced in AX2009 which uses TLS1.2 . , For past 2 months most of the 3rd party API are disablibg TLS1.0 and moving to TLS1.2 , thats why in AX2009 we have to make to change to support it

Okay, so it’s about System.Net.Http.Headers.HttpContentHeaders. Can you tell us more about your implementation; you showed a single method so far but not the context; i.e. how you’ve implemented the service class.

Also, I have no idea what you’re referring in “Any windows , C$ class , asmx would work”. Can you clarify it, please?

As this question is purely about .NET development, you should rather ask in a .NET forum. You won’t find many .NET developers in this forum (which is about Dynamics AX) and I’ll be very busy for the rest of this week.

thanks martin . I know its more or .NET question as i need to consume this webservice in AX2009 . when compilong this websevice im getting error . Whole requirement is to How to use TLS1.2 in AX2009 .

If you want to discuss the error about XML serialization, please look at me previous reply.

If you want to stop it and talk about TLS1.2 in AX 2009 instead , please do in thread HTTP Request must use TLS Protocol version 1.2.

I made it to work , i have to install .NET framework 4.6.2 , it worked