将2个锯齿状数组传递到Web服务

时间:2018-07-03 10:43:01

标签: c# arrays web-services delphi

我有用C#编写的Web服务,它允许我在两个系统之间进行通信。我想要一种方法接受ClassName[][]作为一个(也是唯一的)参数。 此方法定义如下:

namespace WebService
{
    public enum DocumentType { documentType1, documentType2, documentType3 };

    public class MyClass
    {
        private int? id;
        private DocumentType documentType;

        public int? Id
        {
            get { return id; }
            set { id = value; }
        }

        public DocumentType DocumentType
        {
            get { return documentType; }
            set { documentType = value; }
        }

        public MyClass()
        {
            this.id = null;
        }
        public MyClass(int id, DocumentType documentType)
        {
            this.Id = id;
            this.DocumentType = documentType;
        }
    }

    [ServiceContract]
    public interface IPisma
    {
        [OperationContract]
        Tuple<MyClass, bool>[][] WebserviceMethod(MyClass[][] myClassArray);
    }
}

使用在Delphi中编写的以下代码进行调用:

procedure Call();
var
  webServiceParameter: ArrayOfArrayOfMyClass;
begin
  //init parameter and fill with test data
  SetLength(webServiceParameter, 2, 2);
  webServiceParameter[0][0] := MyClass.Create();
  webServiceParameter[0][0].Id := 1621806;
  webServiceParameter[0][0].DocumentType := DocumentType.documentType1;
  webServiceParameter[0][1] := MyClass.Create();
  webServiceParameter[0][1].Id := 564194;
  webServiceParameter[0][1].DocumentType := DocumentType.documentType2;
  webServiceParameter[1][0] := MyClass.Create();
  webServiceParameter[1][0].Id := 1623444;
  webServiceParameter[1][0].DocumentType := DocumentType.documentType1;
  webServiceParameter[1][1] := MyClass.Create();
  webServiceParameter[1][1].Id := 1624682;
  webServiceParameter[1][1].DocumentType := DocumentType.documentType1;

  //create webservice object and call method
  GetIPisma(False, '', HTTPRIO).WebserviceMethod(webServiceParameter);
end;

试图检查实际发送到Web服务的内容以及在HTTPRIO.BeforeExecution事件中,SOAPRequest中包含以下数据:

<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <SOAP-ENV:Body xmlns:NS1="http://schemas.datacontract.org/2004/07/WebService">
        <WebserviceMethod xmlns="http://tempuri.org/">
            <myClassArray>
                <ArrayOfMyClass>
                    <MyClass xsi:type="NS1:MyClass">
                        <Id xmlns="http://schemas.datacontract.org/2004/07/WebService">1621806</Id>
                        <DocumentType xmlns="http://schemas.datacontract.org/2004/07/WebService">documentType1</DocumentType>
                    </MyClass>
                    <MyClass xsi:type="NS1:MyClass">
                        <Id xmlns="http://schemas.datacontract.org/2004/07/WebService">564194</Id>
                        <DocumentType xmlns="http://schemas.datacontract.org/2004/07/WebService">documentType2</DocumentType>
                    </MyClass>
                </ArrayOfMyClass>
                <ArrayOfMyClass>
                    <MyClass xsi:type="NS1:MyClass">
                        <Id xmlns="http://schemas.datacontract.org/2004/07/WebService">1623444</Id>
                        <DocumentType xmlns="http://schemas.datacontract.org/2004/07/WebService">documentType1</DocumentType>
                    </MyClass>
                    <MyClass xsi:type="NS1:MyClass">
                        <Id xmlns="http://schemas.datacontract.org/2004/07/WebService">1624682</Id>
                        <DocumentType xmlns="http://schemas.datacontract.org/2004/07/WebService">documentType1</DocumentType>
                    </MyClass>
                </ArrayOfMyClass>
            </myClassArray>
        </WebserviceMethod>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

WebserviceMethod参数myClassArray的实现范围内,长度为0。尝试了一些操作,例如将尺寸之一包装到另一个类中,但是没有成功。有趣的事实是,当我尝试传递MyClass的一维数组(MyClass [] myClassArray)时,一切正常,xml如下所示:

<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <SOAP-ENV:Body>
        <WebserviceMethod xmlns="http://tempuri.org/">
            <myClassArray>
                <MyClass xmlns="http://schemas.datacontract.org/2004/07/WebService" xsi:type="MyClass">
                    <Id>1621806</Id>
                    <DocumentType>documentType1</DocumentType>
                </MyClass>
                <MyClass xmlns="http://schemas.datacontract.org/2004/07/WebService" xsi:type="MyClass">
                    <Id>162186</Id>
                    <DocumentType>documentType1</DocumentType>
                </MyClass>
            </myClassArray>
        </WebserviceMethod>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

获取WebserviceMethod的结果没有问题。

是否甚至可以将多维锯齿形数组传递给Web服务?

0 个答案:

没有答案