我已经安装了SOAP包,在VB中可以引用。现在需要将一xml发送到已知地址的webservice,如何实现?以前没做过这个,望达人指点。简单几行代码最好了,谢谢!

解决方案 »

  1.   

    obj.MSSoapInit "http://localhost/MyService.asmx?wsdl"
    ret = obj.MyMethod()
      

  2.   

    多谢楼上大虾答复,我现在问题是已知XML文件内容及WebService,如何将XML发送到WebService,如:dim strXML as string, strWebServiceURL as stringstrWebServiceURL="http://128.96.191.32/webapp/DataGetherService"
    strXML="<?xml version="1.0" encoding="GBK"?>" & ....现在是如何将strXML发送到WEBService上?第一次使用,不知道怎么处理,多谢!
      

  3.   

    dim obj as new SoapClient
    obj.MSSoapInit   "http://128.96.191.32/webapp/DataGetherService" 
    ret   =   obj.你的方法()
      

  4.   

    首先工程引用MSXML库。将你的XML加上SOAP Envelope等,使用ServerXMLHTTP40的Send就行了。大致如下:     dim strXMLString As String  '你的XML字串
         dim strWebserviceURL as String 'WEBServic的URL
         
         ......     strSOAPMsg = "<?xml   version='1.0'   encoding='utf-8'?>"
        strSOAPMsg = strSOAPMsg & "<env:Envelope  xmlns:env='http://schemas.xmlsoap.org/soap/envelope/' "
        strSOAPMsg = strSOAPMsg & "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' "
        strSOAPMsg = strSOAPMsg & "xmlns:soapenc = 'http://schemas.xmlsoap.org/soap/encoding/' "
        strSOAPMsg = strSOAPMsg & "xmlns:xsd='http://www.w3.org/2001/XMLSchema'>"
        strSOAPMsg = strSOAPMsg & "<env:Body   env:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>"
        strSOAPMsg = strSOAPMsg & "<m:writeErrorInfo xmlns:m='http://webService.northking.net'>"
        strSOAPMsg = strSOAPMsg & "<string xsi:type='xsd:string'>" & strXMLString & "</string>"
        strSOAPMsg = strSOAPMsg & "</m:writeErrorInfo>"
        strSOAPMsg = strSOAPMsg & "</env:Body>"
        strSOAPMsg = strSOAPMsg & "</env:Envelope>"    With oXMLHttp
            .open "POST", strWebserviceURL, False
            .setRequestHeader "Content-Type", "text/xml;   charset=utf-8"
            .setRequestHeader "Content-Length", Len(strSOAPMsg)
            .setRequestHeader "SOAPAction", "writeErrorInfo" '"hk/GetBeta3"
            .send strSOAPMsg
            While .readyState <> 4
            Wend
            Debug.Print .responseText
        End With