【问题标题】:Soap Web service return null valueSoap Web 服务返回空值
【发布时间】:2021-09-11 23:38:42
【问题描述】:

我想为我的项目使用 Web 服务,并且我确信 Web 服务可以正常工作(我在 Boomerang - SOAP & REST Client 中进行了测试)。 Web 服务链接是https://api.n11.com/ws/ProductService.wsdl。但是当我尝试从服务中获取数据时,服务返回 null、空或 0 值。我认为VS添加web服务引用不能正常工作,但是找不到问题出在哪里。

  static async Task<String> GetProductAsyncN11()
    {

        ServicePointManager.Expect100Continue = true;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
        var port = new N11ProductServiceReference.ProductServicePortClient();
        var requ = new GetProductListRequest();
        requ.auth = new N11ProductServiceReference.Authentication();         
        requ.auth.appKey = "*****";
        requ.auth.appSecret = "*****";
        requ.pagingData = new N11ProductServiceReference.RequestPagingData();
        requ.pagingData.pageSize = 100;
        requ.pagingData.currentPage = 0;
        var list =await port.GetProductListAsync(requ);
        Console.WriteLine(list.GetProductListResponse.products.Rank);
        Console.WriteLine("xx" + list.GetProductListResponse.result.status);
        Console.WriteLine("xx" + list.GetProductListResponse.products.Length);
        foreach (var item in list.GetProductListResponse.products)
        {
            Console.WriteLine(item.productSellerCode+item.price+item.saleStatus);
        }
        return "n11";
    } 

回复在这里

enter image description here

当我使用 Boomerang - SOAP & REST Client 时,这里是响应

enter image description here

【问题讨论】:

  • 它没有出错,并且填充了一些属性,因此看起来您的服务正在“工作”。结果是否准确是另一回事,不能用给定的信息来回答。

标签: c# visual-studio web-services soap service-reference


【解决方案1】:

幸好我解决了。当我添加服务参考时,Visual Studio 更改了订单。我重新安排了订单并解决了问题。

这是真正的订单(取自 Boomerang - SOAP & REST Client);

          <currencyAmount>51.00</currencyAmount>
                <currencyType>1</currencyType>
                <displayPrice>45.90</displayPrice>
                <isDomestic>false</isDomestic>
                <id>457916487</id>
                <price>51.00</price>
                <productSellerCode>BZRG</productSellerCode>
                <approvalStatus>2</approvalStatus>
                <saleStatus>3</saleStatus>
                <stockItems>
                    <stockItem>
                        <bundle>true</bundle>
                        <currencyAmount>51.00</currencyAmount>
                        <displayPrice>45.90</displayPrice>
                        <optionPrice>51.00</optionPrice>
                        <sellerStockCode>BZRG01BJ</sellerStockCode>
                        <attributes>
                            <attribute>
                                <name>ADET</name>
                                <value>1</value>
                            </attribute>
                            <attribute>
                                <name>RENK</name>
                                <value>BEJ</value>
                            </attribute>
                        </attributes>
                        <id>126921525657</id>
                        <quantity>0</quantity>
                        <version>3</version>
                    </stockItem>
                  ...
                </stockItems>
                <subtitle>Bazerga Lüks Kapı Altı Soğuk Toz Böcek Önleyici</subtitle>
                <title>Bazerga Dekoratif Kapı Altı Rüzgar Önleyici 90 cm Renk Çeşitleri</title>
                <unitInfo/>

这是 Visual Studio 创建的顺序

 private long idField;
    
    private string productSellerCodeField;
    
    private string titleField;
    
    private string subtitleField;
    
    private decimal priceField;
    
    private decimal displayPriceField;
    
    private bool isDomesticField;
    
    private string saleStatusField;
    
    private string approvalStatusField;
    
    private ProductSkuList stockItemsField;
    
    private decimal oldPriceField;
    
    private decimal currencyAmountField;
    
    private string currencyTypeField;

我更改了此部分的订单号

[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=4)]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-08
    • 1970-01-01
    • 2011-04-19
    • 1970-01-01
    • 2012-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多