C# wcf 传递数组参数,遇到 System.ServiceModel.FaultException

本文关键字:遇到 System ServiceModel FaultException 参数 wcf 数组 | 更新日期: 2023-09-27 18:31:42

我注意到,如果我在带有数组参数的 Web 服务上发送数组,我会遇到未处理的错误异常,但是当我发送纯字符串时,我可以在带有字符串参数的网络服务上发送数据。我搜索并按照线程传递数组,但它不起作用。我错过了什么吗?

单击以打开图像

client side:
LocalService.Service1Client a = new LocalService.Service1Client();
        LocalService.PersonalDetail[] Entity = new LocalService.PersonalDetail[1];
        LocalService.PersonalDetail Entity2 = null;
        Entity2 = new LocalService.PersonalDetail();
        Entity2.Firstname = "TEST";
        Entity2.Lastname = "TEST";
        Entity2.Middlename = "TEST";
        Entity2.CreatedDate = DateTime.Today;
        Entity[0] = Entity2;
        a.Open();
        Console.Write(a.GetLookOutList(Entity));
        a.Close();


wcf server side.
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetLookOutList(PersonalDetail[] obj);
}
public class Service1 : IService1
{
public string GetLookOutList(PersonalDetail[] obj)
    {
        IResponse Lol = new LookOutList(obj);
        return Lol.Response();
    }
}
    [DataContract(Name = "PersonalDetail")]
public class PersonalDetail
{
    [DataMember(Name = "Firstname")]
    public string Firstname
    { get; set; }
    [DataMember(Name = "Middlename")]
    public string Middlename
    { get; set; }
    [DataMember(Name = "Lastname")]
    public string Lastname
    { get; set; }

    [DataMember(Name = "CreatedDate")]
    public DateTime CreatedDate
    { get; set; }
    }

C# wcf 传递数组参数,遇到 System.ServiceModel.FaultException

public string GetLookOutList(PersonalDetail[] obj)
{
    IResponse Lol = new LookOutList(obj);
    return Lol.Response();
}

其中一个内线是抛出一个例外。

要进行验证,请尝试以下操作:

public string GetLookOutList(PersonalDetail[] obj)
{
    return "TEST";
}

这将起作用。

现在,您需要调试代码。将断点设置为第一行IResponse Lol = new LookOutList(obj);并开始调试过程。您可以在此处找到有关特定异常的帮助。