How to call WCF service and set its configuration

2019-06-11 03:17发布

问题:

I have gone through some topics and was able to call a service in vb6 by using the following code:

Dim sUrl As String
Dim response As String
Dim xmlHttp

Private Sub Form_Load()
sUrl = "http://abc.com/services/abc.svc"


Set xmlHttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlHttp.Open "POST", sUrl, False

xmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlHttp.send
Dim response As String
response = xmlHttp.responseText

Set xmlHttp = Nothing


End Sub

The question is how do i call a WCF service in vb6 and pass params to its methods and get the results?

回答1:

If you try it this way, you'll have to build the request XML by hand, send it, then parse the response XML, again, by hand.

The better way to do this is to create a WCF Client in VB.NET or C#, then expose the client as a COM object. Your VB6 code will be able to treat it exactly like any other COM object, so it won't have to play with XML at all.

See "Communicate with WCF Windows Service in VB6?".



标签: xml wcf vb6