Microsoft WCF Web服务参考提供程序生成Web服务。空数组返回

时间:2018-09-20 15:12:26

标签: wcf asp.net-core .net-core

因此,我有了我首先与Postman进行测试的SOAP Web服务,并且该服务正常工作:

<Soap:Envelope xmlns:Soap="http://schemas.xmlsoap.org/soap/envelope/">
    <Soap:Body>
        <Read_Result xmlns="urn:microsoft-dynamics-schemas/page/salesorder">
            <SalesOrder>
                <Key>28;JAAAAACLAQAAAAJ7BDEAMAAwADE=6;4923601;10;SalesLines1;36;JQAAAACLAQAAAAJ7BDEAMAAwADEAAAAAhxAn6;4923840;</Key>
                <No>1001</No>
                <SalesLines>
                    <Sales_Order_Line>
                        <Key>36;JQAAAACLAQAAAAJ7BDEAMAAwADEAAAAAhxAn6;4923840;</Key>
                        <Type>Item</Type>
                        <FilteredTypeField>Item</FilteredTypeField>
                        <No>1000</No>
                    </Sales_Order_Line>
                </SalesLines>
            </SalesOrder>
        </Read_Result>
    </Soap:Body>
</Soap:Envelope>

如您所见,响应“ Sales_Order_Line”中有一个子元素

因此,我使用WCF Web服务参考提供程序为该Web服务生成代理。现在,在调用Web服务时,Sales_Order_Line为Null。

以下是工具生成的部分代码:

[System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "1.0.0.1")][System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:microsoft-dynamics-schemas/page/salesorder")]


public partial class SalesOrder
{

    private string keyField;

    private string noField;

   private Sales_Order_Line[] salesLinesField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=0)]
    public string Key
    {
        get
        {
            return this.keyField;
        }
        set
        {
            this.keyField = value;
        }
    }

    [System.Xml.Serialization.XmlElementAttribute(Order=1)]
    public string No
    {
        get
        {
            return this.noField;
        }
        set
        {
            this.noField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlArrayAttribute(Order=85)]
    [System.Xml.Serialization.XmlArrayItemAttribute(IsNullable=false)]
    public Sales_Order_Line[] SalesLines
    {
        get
        {
            return this.salesLinesField;
        }
        set
        {
            this.salesLinesField = value;
        }
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "1.0.0.1")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:microsoft-dynamics-schemas/page/salesorder")]
public partial class Sales_Order_Line
{

    private string keyField;

    private Type typeField;

    private bool typeFieldSpecified;

    private string filteredTypeFieldField;

    private string noField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=0)]
    public string Key
    {
        get
        {
            return this.keyField;
        }
        set
        {
            this.keyField = value;
        }
    }
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "1.0.0.1")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(WrapperName="Read", WrapperNamespace="urn:microsoft-dynamics-schemas/page/salesorder", IsWrapped=true)]
public partial class Read
{

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="urn:microsoft-dynamics-schemas/page/salesorder", Order=0)]
    public string No;

    public Read()
    {
    }

    public Read(string No)
    {
        this.No = No;
    }
}`

这是我对Web服务的呼叫:

`public async Task Post([FromBody]字符串数据)         {             SalesOrder_PortClient订单=新的SalesOrder_PortClient();

        Read_Result res = new Read_Result();
        res = await order.ReadAsync("1001");
        //All SalesOrder fields have a value, but its SalesLines array is Null
        Sales_Order_Line[] salesLines = res.SalesOrder.SalesLines;  //salesLines is always null

        if (salesLines.Length > 0)  //Throws a null reference exception
        {  
            string key = salesLines[0].Key;                  
        }  


        return res;

    }`

关于我生成的reference.cs的可能修复的任何想法吗?

0 个答案:

没有答案