【发布时间】:2019-12-06 09:37:36
【问题描述】:
我想从NetSuite WebService 获取数据。这就是我的代码的样子:
public class HomeController : Controller
{
WebServiceGenesisSoapClient service;
public HomeController()
{
var aa = WebServiceGenesisSoapClient.EndpointConfiguration.WebServiceGenesisSoap;
service = new WebServiceGenesisSoapClient(aa);
}
public async Task<IActionResult> Index()
{
WebServiceGenesisSoapClient client = new WebServiceGenesisSoapClient(aa, "http://82.71.28.125/WebServiceGenesis/WebServiceGenesis.asmx");
GetStockQuantityArrayRequest getStockQuantityArrayRequest = new GetStockQuantityArrayRequest();
var stocklist = client.GetStockQuantityArrayAsync(getStockQuantityArrayRequest).Result;
ArrayOfXElement res = stocklist.GetStockQuantityArrayResult;
}
}
res 变量中存在两个节点。这是第一个节点的样子:
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="StockQuantityArray">
<xs:complexType>
<xs:sequence>
<xs:element name="Colour" type="xs:string" minOccurs="0" />
<xs:element name="Quantity1" type="xs:int" minOccurs="0" />
<xs:element name="Quantity2" type="xs:int" minOccurs="0" />
<xs:element name="Quantity3" type="xs:int" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
这是我的第二个节点的样子:
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" />
如果响应中存在数据,则它们存在于第二个节点中。如果数据不存在,我想在第一个节点的xs:sequence 元素中获取name 属性的值。
编辑 1: 如果存在数据,则第一个节点如下所示:
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Departments">
<xs:complexType>
<xs:sequence>
<xs:element name="Code" type="xs:string" minOccurs="0" />
<xs:element name="Description" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
第二个节点看起来像:
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<NewDataSet xmlns="">
<Departments diffgr:id="Departments1" msdata:rowOrder="0">
<Code>ALL</Code>
<Description>ALL</Description>
</Departments>
<Departments diffgr:id="Departments2" msdata:rowOrder="1">
<Code>BABY</Code>
<Description>BABY</Description>
</Departments>
<Departments diffgr:id="Departments3" msdata:rowOrder="2">
<Code>CHIL</Code>
<Description>CHILD</Description>
</Departments>
<Departments diffgr:id="Departments4" msdata:rowOrder="3">
<Code>TEEN</Code>
<Description>TEEN</Description>
</Departments>
<Departments diffgr:id="Departments5" msdata:rowOrder="4">
<Code>WM</Code>
<Description>WOMAN</Description>
</Departments>
</NewDataSet>
</diffgr:diffgram>
【问题讨论】:
标签: c# xml asp.net-mvc web-services netsuite