当前位置 : 主页 > 网页制作 > Nodejs >

SoapUI5.0创建WebService接口模拟服务端

来源:互联网 收集:自由互联 发布时间:2021-06-24
 使用SoapUI创建WebService接口模拟服务端需要接口描述文件 MathUtil.wsdl: [plain] view plain copy print ? ?xmlversion="1.0"encoding="UTF-8"? wsdl:definitionstargetNamespace="http://sean.com" xmlns:apachesoap="http://


使用SoapUI创建WebService接口模拟服务端需要接口描述文件

MathUtil.wsdl:

[plain] view plain copy print ?
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <wsdl:definitions targetNamespace="http://sean.com"   
  3.         xmlns:apachesoap="http://xml.apache.org/xml-soap"   
  4.         xmlns:impl="http://sean.com"   
  5.         xmlns:intf="http://sean.com"   
  6.         xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"   
  7.         xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"   
  8.         xmlns:xsd="http://www.w3.org/2001/XMLSchema">  
  9.  <wsdl:types>  
  10.   <schema elementFormDefault="qualified"   
  11.         targetNamespace="http://sean.com"   
  12.         xmlns="http://www.w3.org/2001/XMLSchema">  
  13.    <element name="add">  
  14.     <complexType>  
  15.      <sequence>  
  16.       <element name="x" type="xsd:int"/>  
  17.       <element name="y" type="xsd:int"/>  
  18.      </sequence>  
  19.     </complexType>  
  20.    </element>  
  21.    <element name="addResponse">  
  22.     <complexType>  
  23.      <sequence>  
  24.       <element name="addReturn" type="xsd:int"/>  
  25.      </sequence>  
  26.     </complexType>  
  27.    </element>  
  28.   </schema>  
  29.  </wsdl:types>  
  30.    <wsdl:message name="addResponse">  
  31.       <wsdl:part element="impl:addResponse" name="parameters">  
  32.       </wsdl:part>  
  33.    </wsdl:message>  
  34.    <wsdl:message name="addRequest">  
  35.       <wsdl:part element="impl:add" name="parameters">  
  36.       </wsdl:part>  
  37.    </wsdl:message>  
  38.    <wsdl:portType name="MathUtil">  
  39.       <wsdl:operation name="add">  
  40.          <wsdl:input message="impl:addRequest" name="addRequest">  
  41.        </wsdl:input>  
  42.          <wsdl:output message="impl:addResponse" name="addResponse">  
  43.        </wsdl:output>  
  44.       </wsdl:operation>  
  45.    </wsdl:portType>  
  46.    <wsdl:binding name="MathUtilSoapBinding" type="impl:MathUtil">  
  47.       <wsdlsoap:binding style="document"  
  48.             transport="http://schemas.xmlsoap.org/soap/http"/>  
  49.       <wsdl:operation name="add">  
  50.          <wsdlsoap:operation soapAction=""/>  
  51.          <wsdl:input name="addRequest">  
  52.             <wsdlsoap:body use="literal"/>  
  53.          </wsdl:input>  
  54.          <wsdl:output name="addResponse">  
  55.             <wsdlsoap:body use="literal"/>  
  56.          </wsdl:output>  
  57.       </wsdl:operation>  
  58.    </wsdl:binding>  
  59.    <wsdl:service name="MathUtilService">  
  60.       <wsdl:port binding="impl:MathUtilSoapBinding" name="MathUtil">  
  61.          <wsdlsoap:address   
  62.                 location="http://localhost:8080/webservice_create/services/MathUtil"/>  
  63.       </wsdl:port>  
  64.    </wsdl:service>  
  65. </wsdl:definitions>  

通过MathUtil.wsdl文件在SoapUI中创建一个SOAP项目:

确认后,会在新建的SOAP项目下自动生成模拟客户端

在模拟客户端的基础上创建一个接口模拟服务端(Mock Service):

双击Response1可以设置接口服务端返回值:

返回值默认为"?",一定要进行修改,否则调用该接口时会报错

[plain] view plain copy print ?
  1. AxisFault  
  2.  faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException  
  3.  faultSubcode:   
  4.  faultString: java.lang.NumberFormatException: For input string: "?"  
  5.  faultActor:   
  6.  faultNode:   
  7.  faultDetail:   
  8.     {http://xml.apache.org/axis/}stackTrace:java.lang.NumberFormatException: For input string: "?"  

双击创建的接口模拟服务端:

修改接口模拟服务端配置:

配置完成后,启动模拟服务端:

此时模拟服务端已经启动,可以使用了:


http://www.voidcn.com/article/p-ghfuwvou-tu.html


 


网友评论