Domino Notes调用 WebService ,输入类中包含数组

前言

这是两个古老技术,但是我遇到了,而且发现网上没有详细教程,所以特意写了出来,以便后来人

一、获取WSDL文件或WSDL文件的URL

1.1 WSDL

<?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. --><!-- Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. --><definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://WebService.Server.leige.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://WebService.Server.leige.com/" name="OutStockInfService">
<types>
<xsd:schema>
<xsd:import namespace="http://WebService.Server.leige.com/" schemaLocation="http://192.168.0.42:10088/DataBus/CreateOutStockDoc?xsd=1"></xsd:import>
</xsd:schema>
</types>
<message name="CretaOutStockDoc">
<part name="parameters" element="tns:CretaOutStockDoc"></part>
</message>
<message name="CretaOutStockDocResponse">
<part name="parameters" element="tns:CretaOutStockDocResponse"></part>
</message>
<portType name="OutStockInf">
<operation name="CretaOutStockDoc">
<input wsam:Action="http://WebService.Server.leige.com/OutStockInf/CretaOutStockDocRequest" message="tns:CretaOutStockDoc"></input>
<output wsam:Action="http://WebService.Server.leige.com/OutStockInf/CretaOutStockDocResponse" message="tns:CretaOutStockDocResponse"></output>
</operation>
</portType>
<binding name="OutStockInfPortBinding" type="tns:OutStockInf">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"></soap:binding>
<operation name="CretaOutStockDoc">
<soap:operation soapAction=""></soap:operation>
<input>
<soap:body use="literal"></soap:body>
</input>
<output>
<soap:body use="literal"></soap:body>
</output>
</operation>
</binding>
<service name="OutStockInfService">
<port name="OutStockInfPort" binding="tns:OutStockInfPortBinding">
<soap:address location="http://192.168.0.42:10088/DataBus/CreateOutStockDoc"></soap:address>
</port>
</service>
</definitions>

1.2 XSD

<?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. --><xs:schema xmlns:tns="http://WebService.Server.leige.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" targetNamespace="http://WebService.Server.leige.com/">

<xs:element name="CretaOutStockDoc" type="tns:CretaOutStockDoc"></xs:element>

<xs:element name="CretaOutStockDocResponse" type="tns:CretaOutStockDocResponse"></xs:element>

<xs:complexType name="CretaOutStockDoc">
<xs:sequence>
<xs:element name="arg0" type="tns:jsonRootBean" minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>

<xs:complexType name="jsonRootBean">
<xs:sequence>
<xs:element name="items" type="tns:items" nillable="true" minOccurs="0" maxOccurs="unbounded"></xs:element>
<xs:element name="memo" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="planTime" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="projectCode" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="sapDept" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="transCode" type="xs:string" minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>

<xs:complexType name="items">
<xs:sequence>
<xs:element name="itemCode" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="itemSeq" type="xs:int"></xs:element>
<xs:element name="planNum" type="xs:int"></xs:element>
<xs:element name="supplier" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="whCode" type="xs:string" minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>

<xs:complexType name="CretaOutStockDocResponse">
<xs:sequence>
<xs:element name="return" type="tns:httpRespon" minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>

<xs:complexType name="httpRespon">
<xs:sequence>
<xs:element name="responBody" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="status" type="xs:string" minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>

关注XSD的比较少,因为我们在用IDE生成Webservice客户端的时候IDE会默认帮我们追索和解析它,它的作用是指导输入和输出对象生成的。

二、生成 WebService客户端

2.1 生成客户端

在这里插入图片描述
Notes新建WebService客户端很简单,按提示操作就可以了

可以导入本地WSDL文件,也可以填写WSDL的URL,本例是导入的URL

2.2 客户端代码(导入WSDL后默认自动生成,不用修改)

%INCLUDE "lsxsd.lss"
Class JsonRootBean_n0 As XSD_ANYTYPE
    
    Public items() As Items_n0
    Public memo As XSD_STRING
    Public planTime As XSD_STRING
    Public projectCode As XSD_STRING
    Public sapDept As XSD_STRING
    Public transCode As XSD_STRING
    
    Sub NEW
    End Sub
    
End Class

Class Items_n0 As XSD_ANYTYPE
    
    Public itemCode As XSD_STRING
    Public itemSeq As Long
    Public planNum As Long
    Public supplier As XSD_STRING
    Public whCode As XSD_STRING
    
    Sub NEW
    End Sub
    
End Class

Class HttpRespon_n0 As XSD_ANYTYPE
    
    Public responBody As XSD_STRING
    Public status As XSD_STRING
    
    Sub NEW
    End Sub
    
End Class

Const n0 = "http://WebService.Server.leige.com/"
Class OutStockInf_n0 As PortTypeBase
    
    Sub NEW
        Call Service.Initialize ("HttpWebServiceServerLeigeComOutStockInfService", _
        "OutStockInfService.OutStockInfPort", "http://192.168.0.42:10088/DataBus/CreateOutStockDoc", _
        "OutStockInf_n0")
        
    End Sub
    
    Function CretaOutStockDoc(arg0 As JsonRootBean_n0) As HttpRespon_n0
        Set CretaOutStockDoc = Service.Invoke("CretaOutStockDoc", arg0)
    End Function
    
End Class

重点注意几个 class 的类名,后面的代码中要用到。
由输入、输出、服务三种类组成

三、在Notes表单调用WebService客户端

3.1 在表单添加引入WebService客户端

在这里插入图片描述

在表单添加引入WebService客户端

3.2 编写接口调用代码

Function CreateOtherOutStockDocOnMes As String
    ' 调用 WebService 接口在MES系统创建其他出库单
    Dim CurUIDoc As NotesUIDocument
    Dim CurWs As New NotesUIWorkspace
    Dim CurDoc As NotesDocument
    Dim Session As New NotesSession
    Dim CurDB As NotesDatabase
    Dim cBasic As New BasicTool
    Dim i As Integer
    
    Set CurDB = Session.CurrentDatabase
    Set CurUIDoc = CurWs.CurrentDocument
    Set CurDoc = CurUIDoc.Document
    
    ' 接口服务类
    Dim OutStockInf As New OutStockInf_n0()
    ' 输入类
    Dim inpt As New JsonRootBean_n0()
    ' 输入类赋值------开始--------
    ' -- 项目
    Dim ProjectCode As New XSD_STRING
    ProjectCode.setValueFromString(CurDoc.ProjectCode(0))
    Set inpt.ProjectCode = ProjectCode
    ' -- 成本中心
    Dim sapDept As New XSD_STRING
    sapDept.setValueFromString(CurDoc.CostCenterCode(0))
    Set inpt.sapDept = sapDept
    ' -- 收发事务类型
    Dim transCode As New XSD_STRING
    transCode.setValueFromString(CurDoc.SendReceivCode(0))
    Set inpt.transCode = transCode
    ' -- 时间
    Dim planTime As New XSD_STRING
    planTime.setValueFromString(Format(cBasic.GetServerTime(),"YYYY-MM-DD hh:mm:ss"))
    Set inpt.planTime = planTime
    ' -- 备注
    Dim memo As New XSD_STRING
    memo.setValueFromString("Notes领料单号:"&CurDoc.sn(0)&"申请人信息:" & CurDoc.Dept(0) & " " & CurDoc.UserName(0))
    Set inpt.memo = memo
    ' -- 行项目赋值  设置数组大小
    Redim inpt.items(Curdoc.line(0) - 1)
    For i = 1 To Curdoc.line(0)
        ' -- 行项目数组
        Dim item As New Items_n0()
        ' ---- 料号
        Dim itemCode As New XSD_STRING
        itemCode.setValueFromString(Curdoc.GetItemValue("ItemCode_" & Cstr(i))(0))
        Set item.itemCode = itemCode
        ' ---- 行序号
        Dim itemSeq As Long
        itemSeq = i
        item.itemSeq = itemSeq
        ' ---- 仓库
        Dim whCode As New XSD_STRING
        whCode.setValueFromString(Curdoc.GetItemValue("Warehouse_" & Cstr(i))(0))
        Set item.whCode = whCode
        ' ---- 领料数量
        Dim planNum As Long
        planNum = Clng(Curdoc.GetItemValue("Quantity_" & Cstr(i))(0))
        item.planNum = planNum
        ' ---- 供应商代码
        Dim supplier As New XSD_STRING
        supplier.setValueFromString("")
        Set item.supplier = supplier
        
        Set inpt.items(i-1) = item
    Next
    ' 输入类赋值------结束--------
    ' 输出类
    Dim outpt As New HttpRespon_n0()
    ' 调用接口
    Set outpt = OutStockInf.CretaOutStockDoc(inpt)
    ' 接口解析
    'Msgbox outpt.status.getValueAsString()
    'Msgbox outpt.responBody.getValueAsString()
    Curdoc.MESMaterialRequisitionFo = outpt.responBody.getValueAsString()
    CreateOtherOutStockDocOnMes = outpt.status.getValueAsString()
End Function

注意点:

  1. 输入类、输出类、服务类的定义
  2. 输入类的赋值,String类型赋值和Long类型的赋值不一样
  3. 输入类里有一个元素是数组,在查前文的XSD结构可以看到,数组在赋值前要定义数组的大小而且必须准确,太大会传null,太小会报错
  4. 输出类的取值也有讲究,最好照抄
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值