【问题标题】:WCF - Object losing it's values when passed to WCF ServiceWCF - 对象在传递给 WCF 服务时丢失其值
【发布时间】:2011-12-01 04:15:00
【问题描述】:

我是使用 WCF 服务的新手,但我开始编写一个新项目并遇到了这个问题。我也是编程新手,如果措辞不正确,请见谅!

我有一个名为 Profile 的对象,我可以在我的客户端上从 WCF 检索它,并且可以正常工作 - 使用 GetProfile 方法。

然后我想在客户端对对象进行修改,并使用 UpdateProfile 方法通过 WCF 服务将其发送回。此时,对象似乎总是被重新实例化(因此将所有值覆盖为 null)。

感谢任何帮助。

所以 GetProfile 方法工作得很好。 对我的客户端上的 RAIS_Profile 进行更改效果很好 使用 UpdateProfile 将 RAIS_Profile 发回,并且在该方法中对象中的每个值都是空白的。

Public Function GetProfile(ByVal DocumentNumber As Integer) As RAIS_Profile Implements IRAISAPI.GetProfile
        Dim Doc As New RAIS_Profile
        'blah
        'blah
        Return Doc
    End Function

    Public Function UpdateProfile(ByVal pDoc As RAIS_Profile) As String Implements IRAISAPI.UpdateProfile
        Return pDoc.DocumentNumber
    End Function

感谢任何帮助!

【问题讨论】:

  • 您是否使用 DataMemberAttribute 标记了 RAIS_Profile 对象的属性?
  • 您能否发布更新客户端上的 RAIS_Profile 的代码,然后调用 UpdateProfile 方法。您能否也发布 RAIS_Profile 类的代码。

标签: c# vb.net wcf parameters


【解决方案1】:

查看您在客户端和服务器上的服务合同。如果参数的命名方式不完全相同,那么您将遇到这种行为。

Here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-24
    • 1970-01-01
    相关资源
    最近更新 更多