Reputation: 2987
I'm working with a WebApi and XML as result.
I just keep receiving a weird namespace in my result, for exemple:
<QueryId>FE04A4E6-A584-47BF-9DA1-7360DFB08A8D</QueryId>
<ExecutionError>true</ExecutionError>
<OperationResult xmlns:d2p1="http://schemas.datacontract.org/2004/07/MyTypes" i:nil="true"/>
<ErrorMessage>INVALID ACCOUNT</ErrorMessage>
I read some solutions and included this at my WebApiConfig.cs:
config.Formatters.XmlFormatter.UseXmlSerializer = true;
But using this parameter, my return was the same without OperationResult tag (the only one that was not filled out):
<QueryId>FE04A4E6-A584-47BF-9DA1-7360DFB08A8D</QueryId>
<ExecutionError>true</ExecutionError>
<ErrorMessage>INVALID ACCOUNT</ErrorMessage>
I was trying to use my result object like this:
[DataContract(Namespace = "")]
public class CustomRecordResult
{
[DataMember]
public string QueryId { get; set; }
[DataMember]
public bool ExecutionError { get; set; }
[DataMember]
public string ErrorMessage { get; set; }
[DataMember]
public CustomSourceRecord OperationResult { get; set; }
}
But it´s not working. My result object is empty in this case
Any ideas?
Thank you very much!
Upvotes: 3
Views: 1277
Reputation: 100
Use the EmitDefaultValue option to control whether that member will be serialized when it is null.
[DataMember(EmitDefaultValue = false)]
public CustomSourceRecord OperationResult { get; set; }
Upvotes: 1