从VB.net调用Java webservice(wsdl)

时间:2015-06-05 07:09:14

标签: java vb.net web-services soap wsdl

下面是我的java wsdl,我需要通过这个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>

我无法将带有列表类型参数的项目从vb.net传递到该wsdl,下面是我的vb.net代码

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

在“purchases.item = array”行上的变量'array'上有一个错误标记,它表示

"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'

1 个答案:

答案 0 :(得分:0)

我会摆脱你的array变量并尝试这些方法:

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()

然后,您可以多次调用.Add来添加多个项目(如果需要)。