Under view, C # WebService WSDL BUG automatically generated code array parameter. . . ArrayOfString

ArrayOfString
ArrayOfString
ArrayOfString

C # client ArrayOfString solve the problem parameters. (I want the search engine can be found to help you solve the magical ArrayOfString)


ASP.NET server add asmx WebService file and add the following method. Note that this only add the following method:

Parameter is a string array:

    [WebMethod]
        public string HelloWorld(string[] inputs)
        {
            return "Hello World";
        }

Other items to add servers reference this WebService (in fact, the program automatically generates code based on wsdl.exe WDSL file WebService statement.)
Generates the following code

public string HelloWorld(ConsoleApp2.ServiceReference1.ArrayOfString inputs) 

NOTE: The parameter string [] becomes ArrayOfString object. . .

Amazingly, with so many years of WebService I did not find this a problem. .

    [WebMethod]
        public string HelloWorld(string[] inputs)
        {
            return "Hello World";
        }
        
    //添加下边的这个方法后,重新引用,上边的string[] 参数就不会变成ArrayOfString对象。。。
    [WebMethod]
        public DataTable AddTable()
        {
            return null;
        }

Comparison of two WDSL, just add DataTable, WDSL in the statement structure is not the same. . .


            //没有添加Datatable 的WebService会导致声明的string[]参数变为ArrayOfString 对象
            ServiceReference1.WebService1SoapClient client = new ServiceReference1.WebService1SoapClient();
            client.HelloWorld(new ServiceReference1.ArrayOfString());

            //添加Datatable声明的WebService就是正常的
            ServiceReference2.WebService2SoapClient client2 = new ServiceReference2.WebService2SoapClient();
            string[] input = new string[0];
            client2.HelloWorld(input);

DEMO:

https://github.com/zifeiniu/WebserviceArrayOfString.git

Guess you like

Origin www.cnblogs.com/zifeiniu/p/12069224.html