简体   繁体   English

WCF测试客户端错误

[英]WCF Test Client error

I am running my WCF service with Entity Framework. 我正在使用实体框架运行WCF服务。

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: 但是,当我使用Visual Studio 2012调用服务时,出现错误:

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. 由于我是WCF的新手,所以我不知道在哪里搜索和做什么。

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: 从WCF返回的复杂对象需要用DataContract属性包装,例如:

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

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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