简体   繁体   中英

WCF Test Client error

I am running my WCF service with Entity Framework.

public List<Website> getWebsites()
{
        try
        {
            using (MyInfoEntities ent = new MyInfoEntities())
            {
                return ent.Websites.ToList();
            }
        }
        catch (Exception e)
        {
            throw e;
        }
}

But when I invoke my service using Visual Studio 2012 I get an error:

Failed to invoke the service.
Possible causes: The service is offline or inaccessible; the client-side configuration does not match the proxy; the existing proxy is invalid. Refer to the stack trace for more detail. You can try to recover by starting a new proxy, restoring to default configuration, or refreshing the service.

As I am totally new to WCF I don't know where to search and what to do.

Your probably not going to be able to return an entity framework object like that directly. Complex objects that are returned from WCF need to be wrapped around a DataContract attribute such as the following:

    [DataContract]
    public class Website
    {
        [DataMember]
        public long idWebsite{ get; set; }

        [DataMember]
        public string Name{ get; set; }

        [DataMember]
        public string MacAddHostess { get; set; }
     }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM