【问题标题】:Error accessing a WCF service访问 WCF 服务时出错
【发布时间】:2012-06-19 22:15:39
【问题描述】:

我有一个很奇怪的问题。 我有一个有效的 WCF 服务。

[ServiceContract]
public interface IService
{
    [OperationContract]
    int AddResult(int result, string name);

    [OperationContract]        
    int list(int count);
}

在另一个类中,我实现了这项服务。它有效。 但是当我像这样更改方法“列表”时:

[ServiceContract]
public interface IService
{
    [OperationContract]
    int AddResult(int result, string name);

    [OperationContract]        
    List<string> list(int count);        
}

当我从目标项目(它是一个 Windows Phone 应用程序)添加服务引用时,我收到了几个错误和警告。它们的关键思想是无法加载服务(或无法加载端点)。 两种方法之间的区别非常小 - List 而不是 int 类型。但这很关键。 为什么会这样?为什么我不能使用 List?

【问题讨论】:

    标签: wcf deployment hosting


    【解决方案1】:

    您是否尝试将 List 集合封装到代理类中?您可以尝试以下方法:

    [DataContract]
    public class MyData
    {
        [DataMember]
        public List<string> list { get; set; }
    }
    
    [ServiceContract]
    public interface IService
    {
        [OperationContract]
        int AddResult(int result, string name);
    
        [OperationContract]        
        MyData list(int count);        
    }
    

    另外,看看这个link,我想它可能就是你要找的。​​p>

    更新

    根据该线程的 cmets 部分所讨论的,问题不在于 WCF 服务本身,而在于@user1460819 Windows Phone 应用程序中生成的客户端。

    WCF服务绑定改成“basicHttpBinding”后,这个问题解决了,客户端的WCF引用重新生成,整个项目重新构建。

    【讨论】:

    • 警告之一是:“自定义工具警告:调用目标已引发异常。C:\Documents\Visual Studio 2010\Projects\project\project\Service References\ServiceReference1\参考.svcmap"
    • 另一个警告是“自定义工具警告:未找到与 Silverlight 3 兼容的端点。除非通过构造函数提供端点信息,否则生成的客户端类将不可用。C:\Documents\Visual Studio 2010 \Projects\project\project\Service References\ServiceReference1\Reference.svcmap"
    • 还有一个非常重要的事实(我在几分钟前注意到)是从控制台应用程序中我可以使用我的 WCF 服务而没有任何错误,但在 Windows Phone 应用程序中存在一些错误。
    • 好吧,那么我想你的错误应该是在 Windows Phone 应用程序中......你用什么来连接你的移动应用程序中的 WCF 服务?它是 Microsoft API 吗?即使您在应用程序中使用 Microsoft API,它也可能不支持那些花哨的 WCF 绑定,例如:wsHttpBinding。如果您正在使用此绑定(或任何其他绑定),请尝试将其更改为:basicHttpBinding。
    • 另外,据我所知,除了 basicHttpBinding 之外,Microsoft 之外的任何其他绑定都不支持。所以如果你想要兼容性,你应该坚持这个绑定。以下是 WCF 中绑定的快速浏览:wcftutorial.net/WCF-Types-of-Binding.aspx
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多