Hello in a C# WCF Service application i want to return an array of 5 strings in a method. The above code isn't returning any errors but when i launch the Service in debug mode it only shows the first string on the Array.
Here's the IService side :
[OperationContract]
string[] NaviresXml();
Here's the Service side :
public string[] NaviresXml()
{
try
{
XMLReader x = new XMLReader(FilePath);
return new string[] { x.ReadXmlDocument_Navires() };
}
catch (Exception ex)
{
throw new Exception(ex.Message + "\n" + ex.StackTrace);
}
}
And the XMLReader Class :
public class XMLReader
{
public string XmlFilePath { get; set; }
public XMLReader(string XmlFilePath)
{
this.XmlFilePath = XmlFilePath;
}
public string ReadXmlDocument_Navires()
{
XmlDocument xmlDoc1 = new XmlDocument();
xmlDoc1.Load(XmlFilePath);
XmlNodeList itemNodes = xmlDoc1.GetElementsByTagName("Navire");
if (itemNodes.Count > 0)
{
foreach (XmlElement node in itemNodes)
return "Navire" + node.Attributes["Type"].Value + "Nom" + node.Attributes["Nom"].Value;
}
return null;
}
}
When i launch the Service i can see only the first string but not the others. enter image description here
What is wrong with this code?
I've tried to do it without the XMLReader Class and put the code directly in the Service side but this didn't worked.
Move the return statement outside your loop.