2014-09-02 166 views
0

我想在我的VB6.0應用程序中調用WCF服務方法(帶參數)。我的WCF服務的URL是: - HTTP://10.1.1.169:7794/和我想調用的方法是ConvertXMLDataToDBFAndAccess並且有將由該method.The參數使用四個參數是: - XMLDATAisCompressedAccessFileNameDBFFileName如何在VB6.0應用程序中調用WCF服務方法

目前我沒有任何與服務相關的代碼。所以沒有任何服務代碼的變化你可以提供代碼在Visual Basic 6.0中。這項服務運行在另一臺計算機和我的機器是在同一個網絡,所以這就是爲什麼我能夠訪問服務

+0

可能重複[如何調用WCF服務並將其配置中使用VB6(http://stackoverflow.com/questions/ 14720704/how-to-call-wcf-service-and-set-its-configuration-using-vb6) – 2014-09-02 13:01:52

+0

This [鏈接](http://www.drdobbs.com/web-development/integrating-xml-web-services-with-vb6-ap/184405550)可能有幫助 – 2014-09-02 13:03:39

回答

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 
+0

雖然這可能會回答這個問題,請您提供一些評論或至少描述了這是在做什麼?雖然我們有些人可能會弄清楚,但不是每個人都可以。 – Deanna 2014-09-05 07:38:20

+0

嗨。我已經添加了一些評論,我希望他們能提供幫助。如果還有其他事情你認爲我必須解釋,請告訴我。謝謝。 – 2014-09-05 18:48:35

+0

感謝您的回覆,但它不起作用。我已替換您標記的所有必需信息,但是當光標轉到「調用xmlhttp.send(strSoap)」時,它會給出錯誤。錯誤是: - 「運行時錯誤 - 2147221020(800401e4)Syntax語法無效「 – user3817749 2014-09-05 18:56:15

-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 
相關問題