0

I want to call WCF Service Method(with parameter) in my VB6.0 Apllication.The URL of my WCF Service is :-HTTP://10.1.1.169:7794/ and method which I want to call is ConvertXMLDataToDBFAndAccess and there are four parameters which is using by this method.The Parameters are:-xmldata,isCompressed,AccessFileName,DBFFileName.

Currently I have no code related to service.So without any changes in service code Can you provide me code in visual basic 6.0.This Service running in another computer and my machine is in same network so that's why I am able to access the service

user3817749
  • 99
  • 1
  • 11
  • possible duplicate of [How to call WCF service and set its configuration using VB6](http://stackoverflow.com/questions/14720704/how-to-call-wcf-service-and-set-its-configuration-using-vb6) – Nadeem_MK Sep 02 '14 at 13:01
  • This [LINK](http://www.drdobbs.com/web-development/integrating-xml-web-services-with-vb6-ap/184405550) might help – Nadeem_MK Sep 02 '14 at 13:03

2 Answers2

0

I hope this helps...

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
  • While this may answer the question, can you please provide some commentary or at least a description of what this is doing? While some of us may be able to figure it out, not everyone can. – Deanna Sep 05 '14 at 07:38
  • Hi. I have added some comments, I hope they help. If there is something else you think I have to explain please tell me. Thanks. – Santiago Javier Moreira Sep 05 '14 at 18:48
  • Thanks for your reply but it doesn't work.I have replace all needed information which you mark but when cursor goes to "Call xmlhttp.send(strSoap)" it gives error.The Error is:-"Run-time Error -2147221020(800401e4) Invalid Syntax" – user3817749 Sep 05 '14 at 18:56
  • @user3817749 what data type are you trying to send?, can you edit your question with the code you are using?. – Santiago Javier Moreira Sep 05 '14 at 18:59
  • string data type.but where to put that data type? – user3817749 Sep 05 '14 at 19:06
  • here "Man" represents what? – user3817749 Sep 05 '14 at 19:14
  • I changed the strSoap, you may not need the CDATA tag... Please post the code you are using so I can identify the problem.. – Santiago Javier Moreira Sep 05 '14 at 19:15
  • I Post my problem as a post my answer by mistake.so please have a look – user3817749 Sep 05 '14 at 19:25
  • @user3817749 Is your strURL starting with "http://" and ending in ".svc?wsdl".. make sure of that... also If you open your WebService url with the ?wsdl at the end you can check the action name.. verify that please. – Santiago Javier Moreira Sep 05 '14 at 19:32
  • Thanks For that.Now it works after add http:// but it gives always xmlstatus.status=400 or give xmlstatus.statusText=Bad Request.Can you please give me any solution and one thing it is a webservice which is made in .net not any.svc – user3817749 Sep 06 '14 at 17:37
  • @user3817749 Hi. I saw that you have in your strSoap "Envelopexmlns".. and It should be "Envelope xmlns".. Check that xml text first!.. And I also use .net webservice. – Santiago Javier Moreira Sep 09 '14 at 19:56
  • @user3817749 How are you? Could you finally fix this? – Santiago Javier Moreira Sep 15 '14 at 20:01
  • I am fine.I have tried your solution but doesn't got any success.At this time,I have got not any response and also application hangs.Means application shows "Not responding" message. – user3817749 Sep 17 '14 at 06:25
-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 
user3817749
  • 99
  • 1
  • 11