Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.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# 无法序列化System.Tuple,因为它没有无参数构造函数_C#_Asp.net_Web Services - Fatal编程技术网

C# 无法序列化System.Tuple,因为它没有无参数构造函数

C# 无法序列化System.Tuple,因为它没有无参数构造函数,c#,asp.net,web-services,C#,Asp.net,Web Services,我试图创建一个只包含一个返回元组项的函数的简单Web服务,问题是在部署ASMX文件后出现此错误: 导致此问题的功能是: [WebMethod] public Tuple<String[],String> BeginTest(String url, String ip_public, int port_external, String ip_internal, int port_inner, bool isInner) { P

我试图创建一个只包含一个返回元组项的函数的简单Web服务,问题是在部署ASMX文件后出现此错误:

导致此问题的功能是:

 [WebMethod]
        public Tuple<String[],String> BeginTest(String url, String ip_public, int port_external, String ip_internal, int port_inner, bool isInner)
        {
            Ping ping = new Ping();
            String errorMSG = "Null";
            String[] info = new string[3];
            PingReply pingreply = null;

            try
            {
                if (isInner)
                {
                     pingreply = ping.Send(ip_internal);
                }
                else
                {
                     pingreply = ping.Send(ip_public);
                }

                info[0] = pingreply.RoundtripTime.ToString() ;
                info[1] = pingreply.Options.Ttl.ToString();
                info[2] = pingreply.Buffer.Length.ToString();


            }
            catch (Exception err)
            {
                errorMSG = err.Message.ToString();
            }

            return new Tuple<string[], string>(info, errorMSG);



        }
[WebMethod]
公共元组开始(字符串url、字符串ip_public、int-port_external、字符串ip_internal、int-port_internal、bool-isInner)
{
Ping Ping=新Ping();
字符串errorMSG=“Null”;
字符串[]信息=新字符串[3];
PingReply PingReply=null;
尝试
{
如果(伊森纳)
{
pingreply=ping.Send(ip_内部);
}
其他的
{
pingreply=ping.Send(ip_public);
}
info[0]=pingreply.RoundtripTime.ToString();
info[1]=pingreply.Options.Ttl.ToString();
info[2]=pingreply.Buffer.Length.ToString();
}
捕获(异常错误)
{
errorMSG=err.Message.ToString();
}
返回新元组(info,errorMSG);
}

创建您自己的元组类,称为MyTuple,它有一个无参数构造函数

public class MyTuple<TypeParameter1, TypeParameter2>
{
    public TypeParameter1 Value1 { get; set; }
    public TypeParameter2 Value2 { get; set; }

    public MyTuple()
    {

    }
    public MyTuple(TypeParameter1 value1, TypeParameter2 value2)
    {
        Value2 = value2;
        Value1 = value1;
    }
}
公共类MyTuple
{
公共类型参数1值1{get;set;}
公共类型参数2值2{get;set;}
公共MyTuple()
{
}
公共MyTuple(类型参数1值1,类型参数2值2)
{
Value2=Value2;
Value1=Value1;
}
}
更多信息请点击此处:
创建您自己的元组类MyTuple,它有一个无参数构造函数

public class MyTuple<TypeParameter1, TypeParameter2>
{
    public TypeParameter1 Value1 { get; set; }
    public TypeParameter2 Value2 { get; set; }

    public MyTuple()
    {

    }
    public MyTuple(TypeParameter1 value1, TypeParameter2 value2)
    {
        Value2 = value2;
        Value1 = value1;
    }
}
公共类MyTuple
{
公共类型参数1值1{get;set;}
公共类型参数2值2{get;set;}
公共MyTuple()
{
}
公共MyTuple(类型参数1值1,类型参数2值2)
{
Value2=Value2;
Value1=Value1;
}
}
更多信息请点击此处:

为什么要使用元组then@LeiYang如果可能的话,我需要检索两个不同的字符串,如果有更好的方法,我不会有问题来更改代码。知道WCF中的
DataContract
吗?@LeiYang不,我不知道为什么要使用Tuplethen@LeiYang如果可能,我需要检索两个不同的字符串,如果有更好的方法,我不会有问题来更改代码。知道WCF中的DataContract吗?@LeiYang不知道我以前不知道