使用多值Web服务,vb.net

时间:2012-08-17 18:35:42

标签: web-services

我是使用asp和webservice技术的新手。我正在尝试阅读Web服务并使用返回的数据。

我的Web服务返回许多字段,因此我正在寻找使用此返回数据的最佳方法。

我的Web服务返回的XML如下所示:

<DataSet xmlns="http://tempuri.org/wsexportaproducto/Productos">
<xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Exportacion">
<xs:complexType>
<xs:sequence>
<xs:element name="gtin" type="xs:string" minOccurs="0"/>
<xs:element name="gtinreemplazado" type="xs:string" minOccurs="0"/>
<xs:element name="refidcateglobal" type="xs:string" minOccurs="0"/>
<xs:element name="refidcatelocal" type="xs:decimal" minOccurs="0"/>
<xs:element name="gln" type="xs:string" minOccurs="0"/>
<xs:element name="glnfabricante" type="xs:string" minOccurs="0"/>
<xs:element name="nombrefabricante" type="xs:string" minOccurs="0"/>
<xs:element name="refpaismercado" type="xs:string" minOccurs="0"/>
<xs:element name="iniciovigenciadn" type="xs:dateTime" minOccurs="0"/>
<xs:element name="finvigenciadn" type="xs:dateTime" minOccurs="0"/>
<xs:element name="vida" type="xs:decimal" minOccurs="0"/>
<xs:element name="nomproducto" type="xs:string" minOccurs="0"/>
<xs:element name="marca" type="xs:string" minOccurs="0"/>
<xs:element name="descproducto" type="xs:string" minOccurs="0"/>
<xs:element name="descripcioncorta" type="xs:string" minOccurs="0"/>
<xs:element name="profundo" type="xs:decimal" minOccurs="0"/>
<xs:element name="unidprofundo" type="xs:string" minOccurs="0"/>
<xs:element name="alto" type="xs:decimal" minOccurs="0"/>
<xs:element name="unidalto" type="xs:string" minOccurs="0"/>
<xs:element name="ancho" type="xs:decimal" minOccurs="0"/>
<xs:element name="unidancho" type="xs:string" minOccurs="0"/>
<xs:element name="pesobruto" type="xs:decimal" minOccurs="0"/>
<xs:element name="unidpesobruto" type="xs:string" minOccurs="0"/>
<xs:element name="pesoempaque" type="xs:decimal" minOccurs="0"/>
<xs:element name="unidpesoempaque" type="xs:string" minOccurs="0"/>
<xs:element name="contenidoneto" type="xs:decimal" minOccurs="0"/>
<xs:element name="unidcontenidoneto" type="xs:string" minOccurs="0"/>
<xs:element name="escontenidovariable" type="xs:boolean" minOccurs="0"/>
<xs:element name="refembalaje" type="xs:string" minOccurs="0"/>
<xs:element name="esretornable" type="xs:boolean" minOccurs="0"/>
<xs:element name="factorestiba" type="xs:decimal" minOccurs="0"/>
<xs:element name="esunidadminima" type="xs:boolean" minOccurs="0"/>
<xs:element name="contenidos" type="xs:string" minOccurs="0"/>
<xs:element name="refpaisorigen" type="xs:string" minOccurs="0"/>
<xs:element name="variedadcolorcodigo" type="xs:string" minOccurs="0"/>
<xs:element name="variedadcoloragencia" type="xs:string" minOccurs="0"/>
<xs:element name="variedadcolor" type="xs:string" minOccurs="0"/>
<xs:element name="variedadtalleagencia" type="xs:string" minOccurs="0"/>
<xs:element name="variedadtallecodigo" type="xs:string" minOccurs="0"/>
<xs:element name="variedadtalle" type="xs:string" minOccurs="0"/>
<xs:element name="esunidadordenable" type="xs:boolean" minOccurs="0"/>
<xs:element name="cantminimapedir" type="xs:decimal" minOccurs="0"/>
<xs:element name="multiplopedir" type="xs:decimal" minOccurs="0"/>
<xs:element name="esfacturable" type="xs:boolean" minOccurs="0"/>
<xs:element name="esunidadembarque" type="xs:boolean" minOccurs="0"/>
<xs:element name="nrocapasartcomercial" type="xs:decimal" minOccurs="0"/>
<xs:element name="nroartcomercialesporcapa" type="xs:decimal" minOccurs="0"/>
<xs:element name="unidadesporpallet" type="xs:decimal" minOccurs="0"/>
<xs:element name="unidporcapa" type="xs:decimal" minOccurs="0"/>
<xs:element name="nrodecapas" type="xs:decimal" minOccurs="0"/>
<xs:element name="submarca" type="xs:string" minOccurs="0"/>
<xs:element name="variedadtipo" type="xs:string" minOccurs="0"/>
<xs:element name="oferta" type="xs:boolean" minOccurs="0"/>
<xs:element name="dscompania" type="xs:string" minOccurs="0"/>
<xs:element name="nombregen" type="xs:string" minOccurs="0"/>
<xs:element name="variedadsabor" type="xs:string" minOccurs="0"/>
<xs:element name="continentes" type="xs:string" minOccurs="0"/>
<xs:element name="reftiponivel" type="xs:string" minOccurs="0"/>
<xs:element name="esunidadconsumo" type="xs:boolean" minOccurs="0"/>
<xs:element name="pesoneto" type="xs:decimal" minOccurs="0"/>
<xs:element name="unidpesoneto" type="xs:string" minOccurs="0"/>
<xs:element name="cantidadtotalcontenida" type="xs:decimal" minOccurs="0"/>
<xs:element name="reftipogtin" type="xs:string" minOccurs="0"/>
<xs:element name="esprivado" type="xs:boolean" minOccurs="0"/>
<xs:element name="statussecodat" type="xs:string" minOccurs="0"/>
<xs:element name="accion" type="xs:int" minOccurs="0"/>
<xs:element name="fechaaccion" 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">
<NewDataSet xmlns="">
<Exportacion diffgr:id="Exportacion1" msdata:rowOrder="0">
<gtin>07500112045058</gtin>
<refidcateglobal>10005730</refidcateglobal>
<gln>7505000010064</gln>
<refpaismercado>484</refpaismercado>
<iniciovigenciadn>2012-08-09T00:00:00-05:00</iniciovigenciadn>
<finvigenciadn>4999-12-31T23:59:59-06:00</finvigenciadn>
<marca>PINTACOLOR</marca>
<descproducto>PINTACOLOR BLANCO</descproducto>
<descripcioncorta>PINTURA PINTACOLOR 18 L</descripcioncorta>
<profundo>40.000000000000000</profundo>
<unidprofundo>CM</unidprofundo>
<alto>60.000000000000000</alto>
<unidalto>CM</unidalto>
<ancho>40.000000000000000</ancho>
<unidancho>CM</unidancho>
<pesobruto>26.200000000000000</pesobruto>
<unidpesobruto>KG</unidpesobruto>
<unidpesoempaque>KG</unidpesoempaque>
<escontenidovariable>false</escontenidovariable>
<esretornable>false</esretornable>
<esunidadminima>true</esunidadminima>
<contenidos/>
<esunidadordenable>false</esunidadordenable>
<esfacturable>true</esfacturable>
<esunidadembarque>false</esunidadembarque>
<oferta>false</oferta>
<dscompania>DISTRIBUIDOR</dscompania>
<nombregen>PINTURA</nombregen>
<continentes/>
<reftiponivel>EA</reftiponivel>
<esunidadconsumo>false</esunidadconsumo>
<esprivado>false</esprivado>
<statussecodat>2</statussecodat>
</Exportacion>
</NewDataSet>
</diffgr:diffgram>
</DataSet>

到目前为止,我已经能够阅读webservice,这里是代码:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
    Try
        Dim SerSyncfonia As Syncfonia.Productos
        SerSyncfonia = New Syncfonia.Productos()

        Dim v1 = "7505000010064"
        Dim v2 = "DISTRIBU"
        Dim v3 = "DISTRIBU"
        Dim v4 = ""
        Dim v5 = "7500112045058"

        Label1.Text = SerSyncfonia.ObtieneProducto(v1, v2, v3, v4, v5).ToString
    Catch ex As Exception
        Label1.Text = ex.Message.ToString
    End Try

End Sub

按下Button1后我为Label1.Text获得的结果是“System.Data.DataSet”

因此,在我阅读了Web服务之后,如何将这些数据存储在某个地方以便能够处理数据。例如,获取 nombregen 元素或 gtin 元素的值并将其存储在某处。

1 个答案:

答案 0 :(得分:0)

通常,在使用Web服务时传递DataSet类或特定于.NET的任何其他类型是一个坏主意。这使得它们只能由兼容的.NET版本(例如,不是Java)使用。

但是,在您的情况下,有一个更简单的问题:即使成功传递了DataSet,您对ToString方法的期望究竟是什么?即使没有Web服务,DataSet.ToString()也不会产生有用的输出。