分享

VB 6.0用SOAP去访问Webservice

 昵称33184646 2016-05-10
因为对VB 6.0不太懂,现在项目需要用SOAP去访问Webservice,请问我的soapBody应该怎么去定义...

请大家帮帮忙,项目急呀,重来都没有写过VB,谢谢大家了....

现在我的代码是这样写的:
    Dim revalue As String
    Dim arg As String
    Dim getXmlResult As String
    Dim soapBody As String
    Dim WinhttpReq As WinHttpRequest
    
    arg = "<s1:string>" & s11 & "</s1:string><s1:string0>" & s22 & "</s1:string0><s1:string1>" & s33 & "</s1:string1>" & _
                            "<s1:string2>" & s44 & "</s1:string2><s1:string3>?</s1:string3><s1:string4>?</s1:string4><s1:string5>?</s1:string5><s1:string6>?</s1:string6>"
    
    soapBody = "<soapenv:Envelope xmlns:soapenv=""http://schemas./soap/envelope/"" xmlns:s0=""http://schemas./wsdl/"" xmlns:s1=""" & gServiceNameSpace & """>" & _
        " xmlns:s2=""http://schemas./wsdl/soap/"" xmlns:xs=""http://www./2001/XMLSchema"" <soapenv:Header/><soapenv:Body><s0:service>" & arg & "</s0:service></soapenv:Body></soapenv:Envelope>"
    
    Set WinhttpReq = New WinHttpRequest
    
    WinhttpReq.Open "post", gWSURL, False
    WinhttpReq.setRequestHeader "Content-Type", "text/xml"
    WinhttpReq.setRequestHeader "SOAPAction", gServiceNameSpace
    WinhttpReq.setRequestHeader "Content-Length", Len(soapBody)
    
    
    ' Set the user name and password.
    WinhttpReq.SetCredentials gUserName, gPassword, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
    WinhttpReq.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = &H100
    
    WinhttpReq.setTimeouts gRequestTimeout, gRequestTimeout, gRequestTimeout, gRequestTimeout
    WinhttpReq.send soapBody
    
   ' WinhttpReq.waitForResponse 10000
    
    revalue = WinhttpReq.responseText


XML:
<?xml version="1.0" encoding="UTF-8"?>
<s0:definitions name="TestDefinitions" targetNamespace="http:///TestWebService/Service1" xmlns:s0="http://schemas./wsdl/" xmlns:s1="http:///TestWebService/Service1" xmlns:s2="http://schemas./wsdl/soap/">
  <s0:types>
    <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="java:language_builtins.lang" xmlns:xs="http://www./2001/XMLSchema">
      <xs:complexType name="ArrayOfString">
        <xs:sequence>
          <xs:element maxOccurs="unbounded" minOccurs="0" name="string" nillable="true" type="xs:string"/>
        </xs:sequence>
      </xs:complexType>
    </xs:schema>
    <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http:///TestWebService/Service1" xmlns:tp="java:com.services" xmlns:xs="http://www./2001/XMLSchema">
      <xs:import namespace="java:com.services"/>
      <xs:element name="serviceResponse" type="java:Ws_AHMS_Result" xmlns:java="java:com.services"/>
      <xs:element name="service" type="java:Ws_AHMS_Input" xmlns:java="java:com.mot.pcs.upd.warranty.services"/>
    </xs:schema>
    <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="java:com.services" xmlns:xs="http://www./2001/XMLSchema">
      <xs:complexType name="Ws_AHMS_Result">
        <xs:sequence>
          <xs:element maxOccurs="1" minOccurs="1" name="username" nillable="true" type="xs:string"/>
          <xs:element maxOccurs="1" minOccurs="1" name="userid" nillable="true" type="xs:string"/>
          <xs:element maxOccurs="1" minOccurs="1" name="Tel" nillable="true" type="xs:string"/>
        </xs:sequence>
      </xs:complexType>
      <xs:complexType name="Ws_FSB_Data_Result">
        <xs:sequence>
          <xs:element maxOccurs="1" minOccurs="1" name="fsb_data" nillable="true" type="java:ArrayOfString" xmlns:java="java:language_builtins.lang"/>
          <xs:element maxOccurs="1" minOccurs="1" name="number_of_fsb" type="xs:int"/>
          <xs:element maxOccurs="1" minOccurs="1" name="response_Code" nillable="true" type="xs:string"/>
          <xs:element maxOccurs="1" minOccurs="1" name="response_Message" nillable="true" type="xs:string"/>
        </xs:sequence>
      </xs:complexType>
      <xs:complexType name="Ws_AHMS_Input">
        <xs:sequence>
          <xs:element minOccurs="1" name="string" nillable="true" type="xs:string"/>
          <xs:element minOccurs="1" name="string0" nillable="true" type="xs:string"/>
          <xs:element minOccurs="1" name="string1" nillable="true" type="xs:string"/>
          <xs:element minOccurs="1" name="string2" nillable="true" type="xs:string"/>
          <xs:element minOccurs="1" name="string3" nillable="true" type="xs:string"/>
          <xs:element minOccurs="1" name="string4" nillable="true" type="xs:string"/>
          <xs:element minOccurs="1" name="string5" nillable="true" type="xs:string"/>
          <xs:element minOccurs="1" name="string6" nillable="true" type="xs:string"/>
        </xs:sequence>
      </xs:complexType>
    </xs:schema>
  </s0:types>
  <s0:message name="service">
    <s0:part name="serviceInput" element="s1:service">
    </s0:part>
  </s0:message>
  <s0:message name="serviceResponse">
    <s0:part name="serviceResponse" element="s1:serviceResponse">
    </s0:part>
  </s0:message>
  <s0:portType name="Test">
    <s0:operation name="service" parameterOrder="serviceInput">
      <s0:input message="s1:service">
    </s0:input>
      <s0:output message="s1:serviceResponse">
    </s0:output>
    </s0:operation>
  </s0:portType>
  <s0:binding name="TestSoapBinding" type="s1:TestPort">
    <s2:binding style="document" transport="http://schemas./soap/http"/>
    <s0:operation name="service">
      <s2:operation soapAction="" style="document"/>
      <s0:input>
        <s2:body parts="serviceInput" use="literal"/>
      </s0:input>
      <s0:output>
        <s2:body parts="serviceResponse" use="literal"/>
      </s0:output>
    </s0:operation>
  </s0:binding>
  <s0:service name="Test" xmlns:apwsdl="urn:com.amberpoint.wsdl" xmlns:e="http://com.ssaging/" xmlns:soap="http://schemas./wsdl/soap/" xmlns:wsdl="http://schemas./wsdl/">
    <s0:port name="Test" binding="s1:TestSoapBinding">
      <soap:address location="http:///TestWebService/Service1"/>
    </s0:port>
  </s0:service>
</s0:definitions>

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约