I am practising with ASMX web services, where I encounter this problem. I have a class file Employee.cs
which consists of three fields Id, Name, Salary.
My Service Code :
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public string GetEmlpoyees() {
Employee emps = new Employee[]{
new Employee ()
{
// data...
}
};
return emps;
}
Here it returns an error red marking the instance emps that cannot implicitly convert type ProjectName.Employee[] to string
I think it might be a minor issue but as i am new to web service.....it's getting on my nerves......How to get rid of this issue....Thanks in advance
The signature of the public function GetEmlpoyees says you are going to return a string, but instead you are returning emps which is an array of Employee[]
The compiler is expecting you to return the type you declare in the functions signature, so both types should match.
You need to change the return type to Employee[] like this:
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public Employee[] GetEmlpoyees() {
Employee emps = new Employee[]{
new Employee ()
{
// data...
}
};
return emps;
}