Reputation: 329
I have created a WCF REST service to return a List of class "WsDimension",and the reponse file size is maximum 1 MB,
My class "WsDimension":
[DataContract]
public class WsDimension
{
[DataMember]
public XElement DatasRefernecesValues = new XElement("ReferenceValues");
}
(And in the reponse: every element has a list of Xelements ) exemple of one xelement which has a list of other xelement:
And this is my REST service:
[OperationContract]
[WebGet]
List<WsDimension> GetAllDimensionsByXMLFile(string xmlfile);
And into my implementation of the code, I have three FOREACH :
foreach (var dimension in DimensionsList)
{
//..
foreach (var reference in ReferenceList)
{
//..
foreach (var finalCharac in finalCharacsList)
{
// Here adding a List of Xelement for every Xelement
}
}
}
And the response time is between and 10 minutes and 16 minutes,
How to find the issue in the service implementation?Or is their any advice to fix this problem? Thanks,
Upvotes: 0
Views: 87
Reputation: 7522
The performance of the serialization is related to the performance of the CPU, memory and I/O speed.
I don’t think the DataContractSerializer has an impact on this issue. Alternatively, we could consider the XML serializer to handle these raw XML types.
Please refer to the below official advice.
https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/types-supported-by-the-data-contract-serializer
Besides, Newtonsoft.json
might have a better performance on serialization and deserialization. but we need to change the project framework to create REST API, such as Asp.Net WebAPI since WCF only supports these two kinds of serializers. Building Rest API is not the strength of WCF, serialization performance is one of them. Using the third-party serializer to replace the default DataContractSerializer is complicated.
https://blogs.msdn.microsoft.com/carlosfigueira/2011/05/02/wcf-extensibility-message-formatters/
Feel free to let me know if there is anything I can help with.
Upvotes: 1