0

问题是当 wcf 服务向客户端发送类对象列表时,这些值为空。任何帮助或指导表示赞赏。

我的服务接口是

IPswdService.cs

namespace GetPasswordsSvc
{
    [ServiceContract]
    public interface IPswdService
    {
        [OperationContract]
        List<dbVal> GetData(int value);
    }

[DataContract]
    public class dbVal
    {
        public string Group;
        public string Title;
        public string Username;
    } ;
}

GetPasswords.svc.cs

namespace GetPasswordsSvc
{
    public class PswdService : IPswdService
    {

       public List<dbVal> GetData(int value)
        {
          List<dbVal> kpdata= (from entry in db.RootGroup.GetEntries(true)
                         select new dbVal
                         {
                             Group = entry.ParentGroup.Name,
                             Title = entry.Strings.ReadSafe("Title"),
                             Username = entry.Strings.ReadSafe("UserName"),
                         }).ToList();

            List<dbVal> l = kpdata.ToList();
             return l;
        }

=======================================

WCF 客户端代码

SvcRef.PswdServiceClient wcfClient = new SvcRef.PswdServiceClient();
wcfClient.Open();
List<GetPasswords.dbVal> dbValues = wcfClient.GetData(0);

===============================================

客户端配置文件是

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IPswdService" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
          useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://xxxxxxx:444/GetPasswords.svc" binding="basicHttpBinding"
        bindingConfiguration="BasicHttpBinding_IPswdService" contract="SvcRef.IPswdService"
        name="BasicHttpBinding_IPswdService" />
    </client>
  </system.serviceModel>
4

1 回答 1

2

很难确切地说出原因是什么,但只要看看您的服务数据合同,我可以看到您错过了DataMember数据合同字段上的属性,您的数据合同应该是:

[DataContract]
public class dbVal
{
    [DataMember]
    public string Group;
    [DataMember]
    public string Title;
    [DataMember]
    public string Username;
} 
于 2012-06-29T21:18:56.310 回答