Populate DataTable in a WCF Service

jean-francois collombet 1 Reputation point
2022-12-18T03:40:02.797+00:00

Hello i'm trying to populate a Datatable in a C# WCF Service.

In the Iservice part i have a class :

[DataContract]  
public class Batiments  
{  
	[DataMember]  
	public DataTable DtNavires { get; set; }  
}  

And the method :

[OperationContract]  
	Batiments GetNavires();  

In the Service Part :

public Batiments GetNavires()  
    {  
        XDocument doc = XDocument.Load(FilePath);  
        Batiments b = new Batiments();  
        DataTable dt = new DataTable("Navires");  
  
        dt.Columns.Add("Type");  
        dt.Columns.Add("Nom");  
        string[] arr = new string[2];  
  
        var dr = from n in doc.Descendants("Nom")  
                 select new string[]{  
                         arr[0] = n.Attribute("Type").Value,  
                         arr[1] = n.Attribute("Nom").Value  
                     };  
  
        foreach (var item in dr)  
        {  
            dt.Rows.Add(item[0], item[1]);  
        }  
        b.DtNavires = dt;  
        return b;  
    }  

When i start the service in Debug mode (F5) i can see that this method is not available since it's using the Batiments type.
271704-1.png

What is wrong in this service ???

Developer technologies .NET Other
Developer technologies C#
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2022-12-19T08:05:19.21+00:00

    Hi @jean-francois collombet ,

    First you can open your config file to see if the client configuration has been added. Then make sure the client and server bindings are the same. Please share your configuration file if you can. Thanks.

    Best Regards,
    Jiayao Wu

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.