函数在我的 WFC 服务和客户端中返回的内容存在问题

本文关键字:返回 问题 存在 客户端 我的 WFC 服务 函数 | 更新日期: 2023-09-27 18:37:16

例如,我在客户端中定义了许多函数

[OperationContract]
List<CustomObject> GetObject(string id);

当我尝试从我的接口调用此函数时,如果我尝试:

List<CustomObject> result = cvs.GetObject(5);出现错误,我必须做的是CustomObject[] result = cvs.GetObject(5);

另一个示例是当我定义一条消息时:

[MessageContract]
public class TestRequest
{
     [MessageBodyMember]
     public Int64 Id;
     [MessageBodyMember]
     public int row;
}

以及我的界面的函数:

[OperationContract]
ResponseMessage GetMessage(TestRequest req);

当我尝试以相同的方式使用它时:

TestRequest req = new TestRequest();
req.Id = 2;
req.row = 1;
ResponseMessage resp = cvs.GetMessage(req);

我收到there is no overload for method that takes one argument消息。

以下是由 创建的参考文件的相关部分

[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
ResponseMessage MyService.GetMessage(TestRequest request)
{
    return base.Channel.GetMessage(request);
}
    public string GetMessage(long Id, int row, out long Length, out string Message, out System.IO.MemoryStream ReportMemoryStream)
    {
        TestRequest inValue = new ResponseMessage();
        inValue.Id = Id;
        inValue.row= row;
        ResponseMessage retVal = ((MyService)(this)).GetMessage(inValue);
        Length = retVal.Length;
        Message = retVal.Message;
        ReportMemoryStream = retVal.ReportMemoryStream;
        return retVal.FileName;
    }

为什么客户端和 wfc 服务之间会发生这种断开连接,我该如何解决它。

函数在我的 WFC 服务和客户端中返回的内容存在问题

这里已经有一个问题,其中包含一些答案,可以解释客户端和服务之间所说的"断开连接":

为什么 WCF 返回 myObject[] 而不是我期望的 List?

希望这就是你所追求的。

上次更改方法后是否更新了服务引用?看起来他生成的代理不是最新的。