Search code examples
c#entity-frameworkwcfstored-proceduresvisual-studio-2015

'Doesn't have the matching return type of'; create wcf service using data entity with two variable stored procedure


This is my first attempt to create WCF service using data entity.

I have a simple stored procedure to find address with specified number of return.

Stored procedure (prcGetCOBAddress):

SELECT TOP (@NumberOfRecord)
    *
FROM
    COB_ADDRESS
WHERE
    ADD_FULL LIKE '%' + @FullAddress + '%'

IService1.cs:

public interface IService1
{
    [OperationContract]
    COB_ADDRESS FindAddress(int NumReturn, string FullAdd);
}

Service1.svc.cs:

public class Service1 : IService1
{
    public COB_ADDRESS[] FindAddress(int NumReturn, string FullAdd)
    {
        try
        {
            using (TestingEntities de = new TestingEntities())
            {
                return de.prcGetCOBAddress(NumReturn, FullAdd)
                         .Select(p => new COB_ADDRESS
                         {
                             UID_NUM = p.UID_NUM,
                             ADD_FULL = p.ADD_FULL
                         }).ToArray();
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            return null;
        }
    }        
}

I got the squirrelly underline below IService1 and error message says Service1 does not implement interface member IService1.FindAddress(int, string). Service1.FindAddress(int, string)} cannot implement IService1.FindAddress(int, string) because it does not have the matching return type of COB_ADDRESS.

Can anyone help me out what I'm missing?


Solution

  • As @PaulAbbott says, the interface and its implementation does not match. Your interface is:

    public interface IService1
    {
        [OperationContract]
        COB_ADDRESS FindAddress(int NumReturn, string FullAdd);
    }
    

    and it should be:

    public interface IService1
    {
        [OperationContract]
        COB_ADDRESS[] FindAddress(int NumReturn, string FullAdd);
    }