如何在VB6.0应用程序中调用WCF服务方法

时间:2014-09-02 12:56:35

标签: vb6

我想在我的VB6.0 Apllication中调用WCF服务方法(带参数)。我的WCF服务的URL是: - HTTP://10.1.1.169:7794/我要调用的方法是 ConvertXMLDataToDBFAndAccess 此方法使用了四个参数。参数为: - xmldata isCompressed AccessFileName DBFFileName < /强>

目前我没有与service相关的代码。所以服务代码没有任何变化你能不能在visual basic 6.0中提供代码。这个服务在另一台计算机上运行而我的机器在同一个网络中,这就是为什么我我能够访问该服务

2 个答案:

答案 0 :(得分:0)

我希望这会有所帮助......

Dim strSoap, strSOAPAction As String
Dim strURL As String ' WEB SERVICE URL
Dim DataToSend as String 

strSoap = "<?xml version=""1.0"" encoding=""utf-8""?><s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/"">" & _
          "<s:Body>" & _
          "<YOURMethodName xmlns=""http://tempuri.org/"">" & _
                "<YOURMethodParameterName>DataToSend</YOURMethodParameterName>" & _
          "</YOURMethodName>" & _
          "</s:Body></s:Envelope>"            
          'REPLACE WITH YOUR DATA

strSOAPAction = "http://tempuri.org/YOURContractName/YOURMethodName" ' REPLACE HERE

Dim xmlhttp As MSXML2.XMLHTTP30

Set xmlhttp = New MSXML2.XMLHTTP30
xmlhttp.open "POST", strURL, False 'HERE YOU OPEN THE CONECTION WITH THE WebService
xmlhttp.setRequestHeader "Man", "POST " & strURL & " HTTP/1.1" ' DEFINE THE COMUNICATION TYPE
xmlhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8" 'DEFINE CONTENT TYPE
xmlhttp.setRequestHeader "SOAPAction", strSOAPAction ' ASSOCIATE THE SOAP ACTION
DoEvents
Call xmlhttp.send(strSoap) ' SEND THE REQUEST
DoEvents
If xmlhttp.Status = 200 Then
    ' IT WORKED
Else
  'ERROR
End If

答案 1 :(得分:-1)

Dim strSoap, strSOAPAction As String
    Dim strURL As String ' WEB SERVICE URL
    Dim DataToSend As String
    DataToSend = "demo.mdb"
    strURL = "10.4.5.169:7794"
    strSoap = "<?xml version=""1.0"" encoding=""utf-8""?><s:Envelopexmlns:s=""http://schemas.xmlsoap.org/wsdl/soap/envelope/"">" & _
              "<s:Body>" & _
              "<MoveFile xmlns=""http://tempuri.org/"">" & _
                    "<fileName>DataToSend</fileName>" & _
              "</MoveFile>" & _
              "</s:Body></s:Envelope>"
              'REPLACE WITH YOUR DATA

    strSOAPAction = "http://tempuri.org/DemoConnect/MoveFile" ' REPLACE HERE

    Dim xmlhttp As MSXML2.XMLHTTP30

    Set xmlhttp = New MSXML2.XMLHTTP30
    xmlhttp.Open "POST", strURL, False
    xmlhttp.setRequestHeader "Man", "POST " & strURL & " HTTP/1.1"
    xmlhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
    xmlhttp.setRequestHeader "SOAPAction", strSOAPAction

    xmlhttp.send (strSoap)

here MoveFile is method name  and fileName is parameter name