问题描述
我想为我的项目使用 Web 服务,并且我确信 Web 服务可以正常工作(我在 boomerang - SOAP & REST Client 中进行了测试)。网络服务链接是 https://api.n11.com/ws/ProductService.wsdl。但是当我尝试从服务中获取数据时,服务返回空值、空值或 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";
}
此外,当我使用 boomerang - SOAP & REST Client 时,这是响应
解决方法
幸运的是我解决了它。当我添加服务引用时,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)]