Consuming a web service from VB 6

S

Samantha Dixon

Hi,

I have written a web service use ASP.NET
I can access i from VB 6 via XMLHTTP and everything works
fine until I try to pass parameters to it. According to
what documentation I can find I could pass the parameters
in an XML file or as a querystring attatched to the URL.
However these both return 'Invalid request'

Is there something I'm missing ? Any ideas of where else I
can look ?

Thanks for you time
Sam

PS. Code

sBuffer
= "http://localhost/MapWS/MapService.asmx/GetMapURL"

XMLhttp.open "POST", sBuffer, False
XMLhttp.setRequestHeader "Content-type", "text/xml"
XMLhttp.send ("C:\Coords.xml")
MsgBox XMLhttp.responseText

PosHTTP = InStr(XMLhttp.responseText, ">http")

XML File :

<?xml version="1.0" encoding="utf-8"?>
<GetMapURL xmlns="MaporamaWS">
<Latitude>51.522249476571</Latitude>
<Longitude>-0.105867806149086</Longitude>
</GetMapURL>
 
B

BruceJohnson

Unless I'm mistaken, the problem is a misunderstanding of what the Send
method does. It sends a string. It doesn't send the contents of a
file. So the request you're sending to the service is "C:\Coords.xml",
which by almost any definition is a badly formatted request.

HTH

Bruce Johnson
http://www.ObjectSharp.com/Bruce
 
S

Samantha Dixon

Thanks,

Found it worked if I sent the parameters as a string
ie. XMLHTTP.send "Longitude=-0.105867806149086&Latitude=51.522249476571"

and changed the 'Content-type' from "text/xml" to
"application/x-www-form-urlencoded"

Thanks
Sam
 
M

Matthew Holton

Hello, I hope that you have already found the solution.
If not, here is what I do.

Private Function Login()

' Determine who our user is
' Via AUTH
' Log them in that way
'
'

On Error GoTo Login_Error

Dim objXMLHeader As XMLDocument
Dim objHTTP As MSXML2.XMLHTTP
Dim strEnvelope As String

Dim sUserName As String
Dim sPassword As String

sUserName = GetNetworkUserName
sPassword = GetNetworkPassword(sUserName)

Set objXMLHeader = New XMLDocument
Set objHTTP = New MSXML2.XMLHTTP

strEnvelope = "<?xml version='1.0' encoding='utf-8'?>"
strEnvelope = strEnvelope & "<soap:Envelope
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>"
strEnvelope = strEnvelope & " <soap:Body>"
strEnvelope = strEnvelope & " <Login
xmlns='https://apps.americasdoctor.com/'>"
strEnvelope = strEnvelope & " <UserName>" &
sUserName & "</UserName>"
strEnvelope = strEnvelope & " <Password>" &
sPassword & "</Password>"
strEnvelope = strEnvelope & " </Login>"
strEnvelope = strEnvelope & " </soap:Body>"
strEnvelope = strEnvelope & "</soap:Envelope>"

objHTTP.Open "POST", WebserviceLocation, False
Call objHTTP.setRequestHeader("Content-
Type", "text/xml")

objHTTP.setRequestHeader "SOAPAction", "https://localhost/
Login"
objHTTP.send strEnvelope


'Do While Not objHTTP.readyState = 4
'Sleep 1
'Loop

Dim x As MSXML2.DOMDocument
Set x = New DOMDocument

If x.loadXML(objHTTP.responseText) Then
If x.selectSingleNode
("soap:Envelope/soap:Body/LoginResponse/LoginResult/Status
").nodeTypedValue = "lSuccess" Then
UserHandle = x.selectSingleNode
("soap:Envelope/soap:Body/LoginResponse/LoginResult/Return
Value").nodeTypedValue
mIsLoggedIn = True
Else
Err.Raise vbObjectError + 1001, "SOAP:Login",
x.selectSingleNode
("soap:Envelope/soap:Body/LoginResponse/LoginResult/ErrDes
cription").nodeTypedValue
End If
End If

Exit Function

Login_Error:

End Function
 
M

Matthew Holton

I should also point out that...

if you view the http://localhost/servicename.asmx
file. WDSL will display your functions and methods. If
you choose one of those functions (a link), you will be
directed to a page describing that method or function.
Below that description and, usually a means to test, will
be the SOAP definition for both the input and output of
that method or function. This part describes how you
create the SOAP envelope to communicate via the XMLHTTP
object, and the ACTION header to specify.


HTH,

Matthew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top