我想创建一个DataContract,它是一个包含2个不同List成员的类。当我尝试启动Web服务时,我收到测试WCF客户端不支持我的方法SendEmail的错误。 这是我的数据合同:
[DataContract]
[KnownType(typeof(int[]))]
public class EmailInfo
{
private string strFromUserID = string.Empty;
private string strFromAddress = string.Empty;
private string strFromName = string.Empty;
private object lstIndividualIDs = null;
private object lstGroupIDs = null;
private string strSubject = string.Empty;
private string strMessage = string.Empty;
[DataMember]
public string FromUserID
{
get { return strFromUserID; }
set { strFromUserID = value; }
}
[DataMember]
public string FromAddress
{
get { return strFromAddress; }
set { strFromAddress = value; }
}
[DataMember]
public string FromName
{
get { return strFromName; }
set { strFromName = value; }
}
[DataMember]
public object IndividualIDs
{
get { return lstIndividualIDs; }
set { lstIndividualIDs = value; }
}
[DataMember]
public object GroupIDs
{
get { return lstGroupIDs; }
set { lstGroupIDs = value; }
}
[DataMember]
public string Subject
{
get { return strSubject; }
set { strSubject = value; }
}
[DataMember]
public string Message
{
get { return strMessage; }
set { strMessage = value; }
}
}
这是我使用DataContract的方法:
public string SendEmail(EmailInfo emailInfo)
{
string tstrErrorMsg = string.Empty;
SqlConnection SqlConn = null;
try
{
return tstrErrorMsg;
}
catch (Exception ex)
{
return null;
}
finally
{
if (SqlConn != null)
{
SqlConn.Close();
}
}
}
我想在DataContract中有一个类型为List的DataMember。如何将该类型添加到DataContract?
答案 0 :(得分:0)
我通过将lstIndividualIDs和listGroupIDs更改为List来运行Web服务。 我以为我必须使用物体。 万一有其他人有这个问题...
object lstIndividualIDs - >列表listIndividualIDs 与GroupID相同。 这允许测试客户端运行服务..