简体   繁体   中英

Calling Java webservice (wsdl) from VB.net

Below is my java wsdl, I need to pass parameter purchase and item through this wsdl.

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://createpo.org/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="PurchaseorderService" targetNamespace="http://createpo.org/">
  <wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://createpo.org/" elementFormDefault="unqualified" targetNamespace="http://createpo.org/" version="1.0">
<xs:element name="createpo" type="tns:createpo"/>
<xs:element name="createpoResponse" type="tns:createpoResponse"/>
<xs:element name="item" type="tns:item"/>
<xs:element name="purchase" type="tns:purchase"/>
<xs:element name="responsepo" type="tns:responsePO"/>
<xs:complexType name="createpo">
<xs:sequence>
<xs:element name="purchaseOrder" type="tns:purchase"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="purchase">
<xs:sequence>
<xs:element name="compCode" type="xs:string"/>
<xs:element name="docType" type="xs:string"/>
<xs:element minOccurs="0" name="vendor" type="xs:string"/>
<xs:element name="purchOrg" type="xs:string"/>
<xs:element name="purchGroup" type="xs:string"/>
<xs:element name="currency" type="xs:string"/>
<xs:element name="docDate" type="xs:string"/>
<xs:element name="supplyPlant" type="xs:string"/>
<xs:element maxOccurs="unbounded" name="item" type="tns:item"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="item">
<xs:sequence>
<xs:element name="poItem" type="xs:string"/>
<xs:element name="material" type="xs:string"/>
<xs:element name="plant" type="xs:string"/>
<xs:element name="quantity" type="xs:int"/>
<xs:element name="valType" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="createpoResponse">
<xs:sequence>
<xs:element name="responsepo" type="tns:responsePO"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="responsePO">
<xs:sequence>
<xs:element minOccurs="0" name="status" type="xs:string"/>
<xs:element minOccurs="0" name="poNumber" type="xs:string"/>
<xs:element minOccurs="0" name="message" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
  </wsdl:types>
  <wsdl:message name="createpoResponse">
    <wsdl:part element="tns:createpoResponse" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="createpo">
    <wsdl:part element="tns:createpo" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:portType name="Purchaseorder">
    <wsdl:operation name="createpo">
      <wsdl:input message="tns:createpo" name="createpo">
    </wsdl:input>
      <wsdl:output message="tns:createpoResponse" name="createpoResponse">
    </wsdl:output>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="PurchaseorderServiceSoapBinding" type="tns:Purchaseorder">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="createpo">
      <soap:operation soapAction="" style="document"/>
      <wsdl:input name="createpo">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="createpoResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="PurchaseorderService">
    <wsdl:port binding="tns:PurchaseorderServiceSoapBinding" name="PurchaseorderPort">
      <soap:address location="http://xx.xx.xxx.xxx:9091/wsdl_purchaseorder"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

I can't pass the item with list type parameter from vb.net to that wsdl, below is my vb.net code

Imports System.Xml
Imports Ext.Net
Imports System.Xml.Serialization

Public Class WebForm1

    Inherits System.Web.UI.Page
    Private wsCreatePO As New CreatePO.PurchaseorderService
    Dim wsItem As New CreatePO.item

    Structure sItem
        Public poitem As String
        Public material As String
        Public plant As String
        Public qty As Int16
        Public valType As String
    End Structure


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

       Dim array(4) As sItem
        array(0).poitem = "10"
        array(1).material = "NONSTOCK-MATERIAL"
        array(2).plant = "3012"
        array(3).qty = 10
        array(4).valType = "NEW"

        Dim purchases As New CreatePO.purchase

        purchases.compCode = "3000"
        purchases.docType = "ZCKT"
        purchases.vendor = ""
        purchases.purchOrg = "3000"
        purchases.purchGroup = "3ST"
        purchases.currency = "IDR"
        purchases.docDate = "20150603"
        purchases.supplyPlant = "3011"
        purchases.item = array

        Dim response As New CreatePO.responsePO

        response = wsCreatePO.createpo(purchases)

    End Sub

End Class

There's an error mark on variable 'array' on line "purchases.item = array", it says that

"value of type '1-dimensional-array of WebApplication1.WebForm1.sItem' cannot be converted to '1-dimensional-array of WebApplication1.CreatePO.item' because 'WebApplication1.WebForm1.sItem' is not derived from 'WebApplication1.CreatePO.item'

I would get rid of your array variable and try something along these lines:

Dim allItems As New List(Of CreatePO.item)

allItems.Add(new CreatePO.item With {.material = "Item 1 material",
                                     .plant = "Item 1 plant",
                                     .qty = 10})

purchases.item = allItems.ToArray()

You can then add multiple items by calling .Add multiple times (if required).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM