Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Webservice-无法序列化,因为它没有无参数构造函数_C#_Asp.net_Web Services_Asmx - Fatal编程技术网

C# Webservice-无法序列化,因为它没有无参数构造函数

C# Webservice-无法序列化,因为它没有无参数构造函数,c#,asp.net,web-services,asmx,C#,Asp.net,Web Services,Asmx,我从Web服务调用了以下方法-我不断收到一条错误消息,“无法序列化,因为它没有无参数构造函数。” [WebMethod] 公共阵列列表GetPayers() { 字符串提供程序_JSON=“”; ArrayList=新建ArrayList(); 使用(var webClient=new System.Net.webClient()) { PROVIDER_JSON=webClient.DownloadString(“https://www.eligibleapi.com/resources/in

我从Web服务调用了以下方法-我不断收到一条错误消息,“无法序列化,因为它没有无参数构造函数。”

[WebMethod]
公共阵列列表GetPayers()
{
字符串提供程序_JSON=“”;
ArrayList=新建ArrayList();
使用(var webClient=new System.Net.webClient())
{
PROVIDER_JSON=webClient.DownloadString(“https://www.eligibleapi.com/resources/information-sources.json");
List UserList=JsonConvert.DeserializeObject(PROVIDER\u JSON);
for(int i=0;i
它调用这个类-我认为它有一个无参数构造函数

[JsonObject(MemberSerialization.OptIn)]
public class EligibleProviderType2
{
    EligibleProviderType2(){}

    [JsonProperty(PropertyName = "payer_id")]
    public string PayerID { get; set; }

    [JsonProperty(PropertyName = "names")]
    public IList<string> PayerName { get; set; }

} // EligibleProvider
[JsonObject(MemberSerialization.OptIn)]
公共类EligibleProviderType2
{
EligibleProviderType2(){}
[JsonProperty(PropertyName=“付款人id”)]
公共字符串PayerID{get;set;}
[JsonProperty(PropertyName=“name”)]
公共IList PayerName{get;set;}
}//可识别提供程序

公开您的构造函数。序列化代码无法看到它。

将构造函数公开。序列化代码看不到它。

您的
EligibleProviderType2
的构造函数似乎是
私有的。Private是类字段和方法的默认值。删除它(因为编译器将为您创建一个),或按如下方式进行更改:

[JsonObject(MemberSerialization.OptIn)]
public class EligibleProviderType2
{
    public EligibleProviderType2(){}

    [JsonProperty(PropertyName = "payer_id")]
    public string PayerID { get; set; }

    [JsonProperty(PropertyName = "names")]
    public IList<string> PayerName { get; set; }
} // EligibleProvider
[JsonObject(MemberSerialization.OptIn)]
公共类EligibleProviderType2
{
公共EligibleProviderType2(){}
[JsonProperty(PropertyName=“付款人id”)]
公共字符串PayerID{get;set;}
[JsonProperty(PropertyName=“name”)]
公共IList PayerName{get;set;}
}//可识别提供程序

您的
EligibleProviderType2
的构造函数似乎是
private
。Private是类字段和方法的默认值。删除它(因为编译器将为您创建一个),或按如下方式进行更改:

[JsonObject(MemberSerialization.OptIn)]
public class EligibleProviderType2
{
    public EligibleProviderType2(){}

    [JsonProperty(PropertyName = "payer_id")]
    public string PayerID { get; set; }

    [JsonProperty(PropertyName = "names")]
    public IList<string> PayerName { get; set; }
} // EligibleProvider
[JsonObject(MemberSerialization.OptIn)]
公共类EligibleProviderType2
{
公共EligibleProviderType2(){}
[JsonProperty(PropertyName=“付款人id”)]
公共字符串PayerID{get;set;}
[JsonProperty(PropertyName=“name”)]
公共IList PayerName{get;set;}
}//可识别提供程序

我复制了第二个块并粘贴了它,但仍然得到了它-让我抓狂-所以现在我有了:public-EligibleProviderType2(){}System.InvalidOperationException:生成XML文档时出错。-->System.InvalidOperationException:f__AnonymousType0`2[System.String,System.String]无法序列化,因为它没有无参数构造函数。在System.Xml.Serialization.XmlSerializationWriter.CreateUnknownTypeXcepi中的System.Xml.Serialization.TypeScope.GetTypeDesc(类型类型、MemberInfo源、布尔directReference、布尔throwOnError)中,我在错误中看到这一行:f_uAnonymousType0`2[System.String,System.String]-那是什么?我在中尝试了您的示例,它能够使用JSON.NET正确地反序列化。确保已重建并重新部署(如果不是从IIS Express进行本地测试)。我收到的JSON数据包含547项。我复制了第二个块并粘贴了它,但仍然得到了它-让我抓狂-所以现在我有了:public-eligableProviderType2(){}System.invalidoOperationException:生成XML文档时出错。-->System.InvalidOperationException:f__AnonymousType0`2[System.String,System.String]无法序列化,因为它没有无参数构造函数。在System.Xml.Serialization.XmlSerializationWriter.CreateUnknownTypeXcepi中的System.Xml.Serialization.TypeScope.GetTypeDesc(类型类型、MemberInfo源、布尔directReference、布尔throwOnError)中,我在错误中看到这一行:f_uAnonymousType0`2[System.String,System.String]-那是什么?我在中尝试了您的示例,它能够使用JSON.NET正确地反序列化。确保已重建并重新部署(如果不是从IIS Express进行本地测试)。我收到的JSON数据包含547条items.ASMX是一项遗留技术,不应用于新的开发。WCF或ASP.NET Web API应用于Web服务客户端和服务器的所有新开发。一个提示:微软已经在MSDN上退出了。ASMX是一项遗留技术,不应该用于新的开发。WCF或ASP.NET Web API应用于Web服务客户端和服务器的所有新开发。一个提示:微软已经在MSDN上退出了。