![](/img/trans.png)
[英]How to Keep from Receiving a NullReferenceException when Accessing the Result of a Web Service?
[英]NullReferenceException Commerce Server Web Service
我的代码:
ws.CategoryConfiguration cc = new ws.CategoryConfiguration();
cc.LoadChildProducts = true;
cc.ChildProducts.SearchOptions.PropertiesToReturn = new string[] { "BasePrice" };
当我运行此命令时,在ChildProducts
行上收到NullReferenceException
。 我知道string[]
是一个对象,因为它就在那里,因此它必须是PropertiesToReturn
。 有人知道这个问题是什么吗? LoadChildProducts
可以正常工作。
您需要像这样SearchOptions
对象:
CatalogSearchOptions searchOptions = new CatalogSearchOptions();
然后,您可以添加PropertiesToReturn
,如下所示:
searchOptions.PropertiesToReturn = "BasePrice";
最后,您可以将searchOptions
分配给CategoryConfiguration.ChildProducts.SearchOptions
属性,如下所示:
cc.ChildProducts.SearchOptions = searchOptions;
它要么是ChildProducts
或SearchOptions
的ChildProducts内。
确保它们在CategoryConfiguration
的构造函数中已初始化
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.