durick
asked on
use XMLHTTP to read a web service
here is my code that does nothing ??
Sub plireader()
Dim Request As XMLHTTP
Dim Parameter1 As String
Dim Doc As DOMDocument60
Parameter1 = "demo"
Set Request = New XMLHTTP
Set Doc = New DOMDocument60
'"http://www.pli.edu/public/CEM/Service.asmx?op=CEMgetAttendence"
With Request
.Open "POST", "http://www.pli.edu/public/CEM/Service.asmx?op=CEMgetAttendence", False
.setRequestHeader "Content-Type", "application/soap+xml; charset=utf-8"
.send "company=" & Parameter1 'Name & Value of the Parameter
Doc.loadXML .responseText
End With
Doc.loadXML Doc.Text
MsgBox Doc.XML
End Sub
Sub plireader()
Dim Request As XMLHTTP
Dim Parameter1 As String
Dim Doc As DOMDocument60
Parameter1 = "demo"
Set Request = New XMLHTTP
Set Doc = New DOMDocument60
'"http://www.pli.edu/public/CEM/Service.asmx?op=CEMgetAttendence"
With Request
.Open "POST", "http://www.pli.edu/public/CEM/Service.asmx?op=CEMgetAttendence", False
.setRequestHeader "Content-Type", "application/soap+xml; charset=utf-8"
.send "company=" & Parameter1 'Name & Value of the Parameter
Doc.loadXML .responseText
End With
Doc.loadXML Doc.Text
MsgBox Doc.XML
End Sub
zc2 is correct that the server expects a SOAP request.
Clicking on the URL also shows (near the very top)
Clicking on the URL also shows (near the very top)
The test form is only available for requests from the local machine.which means that the URL-encoded request only works when issued from local machine, i.e., from where the server is running.
ASKER
ok here is my new code still not working
Sub plireader()
Dim strrequest As String
Dim objhttp As Object
strXmlToSend = "<company>demo</company>"
webserviceurl = "http://www.pli.edu/public/CEM/Service.asmx?op=CEMgetAttendence"
Set objhttp = CreateObject("MSXML2.XMLHT TP.3.0")
MsgBox "send now"
strrequest = "<?xml version=""1.0"" encoding=""utf-8""?>" _
& "<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope"">" _
& "<soap:Header>" _
& "<soap:Body>" _
& "<soap:Request>" _
& "<soap:Company>demo</soap: Company>" _
& "</soap:Request>" _
& "</soap:Header>" _
& "</soap:Body>" _
& "</soap:Envelope>"
objhttp.Open "GET", webserviceurl, False
objhttp.setRequestHeader "Content-Type", "text/xml"
objhttp.send strrequest
MsgBox objhttp.responseText
Set objhttp = Nothing
Set XMLDOC = Nothing
End Sub
Sub plireader()
Dim strrequest As String
Dim objhttp As Object
strXmlToSend = "<company>demo</company>"
webserviceurl = "http://www.pli.edu/public/CEM/Service.asmx?op=CEMgetAttendence"
Set objhttp = CreateObject("MSXML2.XMLHT
MsgBox "send now"
strrequest = "<?xml version=""1.0"" encoding=""utf-8""?>" _
& "<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope"">" _
& "<soap:Header>" _
& "<soap:Body>" _
& "<soap:Request>" _
& "<soap:Company>demo</soap:
& "</soap:Request>" _
& "</soap:Header>" _
& "</soap:Body>" _
& "</soap:Envelope>"
objhttp.Open "GET", webserviceurl, False
objhttp.setRequestHeader "Content-Type", "text/xml"
objhttp.send strrequest
MsgBox objhttp.responseText
Set objhttp = Nothing
Set XMLDOC = Nothing
End Sub
Your xml request still does not match what the web service expects. Try sending
<?xml version="1.0" encoding="utf-8"?>
<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/">
<soap:Body>
<CEMgetAttendence xmlns="http://www.pli.edu/public/CEM/">
<company>string</company>
</CEMgetAttendence>
</soap:Body>
</soap:Envelope>
ASKER
ok herte is my new code as you suggested: still not working
Sub plireader()
Dim strrequest As String
Dim objhttp As Object
strXmlToSend = "<company>demo</company>"
webserviceurl = "http://www.pli.edu/public/CEM/Service.asmx?op=CEMgetAttendence"
Set objhttp = CreateObject("MSXML2.XMLHT TP.3.0")
MsgBox "send now"
strrequest = "<?xml version=""1.0"" encoding=""utf-8""?>" _
& "<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/"">" _
& "<soap:Body>" _
& "<CEMgetAttendence xmlns=""https://www.pli.edu/public/CEM/"">" _
& "<company>demo</company>" _
& "</CEMgetAttendence>" _
& "</soap:Body>" _
& "</soap:Envelope>"
MsgBox strrequest
objhttp.Open "GET", webserviceurl, False
objhttp.setRequestHeader "Content-Type", "text/xml"
objhttp.send strrequest
Set objhttp = Nothing
Set XMLDOC = Nothing
End Sub
Sub plireader()
Dim strrequest As String
Dim objhttp As Object
strXmlToSend = "<company>demo</company>"
webserviceurl = "http://www.pli.edu/public/CEM/Service.asmx?op=CEMgetAttendence"
Set objhttp = CreateObject("MSXML2.XMLHT
MsgBox "send now"
strrequest = "<?xml version=""1.0"" encoding=""utf-8""?>" _
& "<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/"">" _
& "<soap:Body>" _
& "<CEMgetAttendence xmlns=""https://www.pli.edu/public/CEM/"">" _
& "<company>demo</company>" _
& "</CEMgetAttendence>" _
& "</soap:Body>" _
& "</soap:Envelope>"
MsgBox strrequest
objhttp.Open "GET", webserviceurl, False
objhttp.setRequestHeader "Content-Type", "text/xml"
objhttp.send strrequest
Set objhttp = Nothing
Set XMLDOC = Nothing
End Sub
According to the service description page ( https://www.pli.edu/public/CEM/Service.asmx?op=CEMgetAttendence ) you need to pass the SOAPAction http header. Add to your script the following line:
Change the line which starts the content of the SOAP envelope body to
objhttp.setRequestHeader "SOAPAction", "http://www.pli.edu/public/CEM/Service.asmx?op=CEMgetAttendence"
Change the value of webserviceurl from "http://www.pli.edu/public/CEM/Service.asmx?op=CEMgetAttendence" to "https://www.pli.edu/public/CEM/Service.asmx"Change the line which starts the content of the SOAP envelope body to
& "<CEMgetAttendence xmlns=""http://www.pli.edu/public/CEM/"">" _
( The namespace should be "http://www.pli.edu/public/CEM/", not "https://www.pli.edu/public/CEM/" )
ASKER
added your changes not sure if working
Sub plireader()
Dim strrequest As String
Dim objhttp As Object
strXmlToSend = "<company>demo</company>"
webserviceurl = "https://www.pli.edu/public/CEM/Service.asmx?op=CEMgetAttendance"
Set objhttp = CreateObject("MSXML2.XMLHT TP.3.0")
MsgBox "send now"
strrequest = "<?xml version=""1.0"" encoding=""utf-8""?>" _
& "<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/"">" _
& "<soap:Body>" _
& "<CEMgetAttendence xmlns=""http://www.pli.edu/public/CEM/"">" _
& "<company>demo</company>" _
& "</CEMgetAttendence>" _
& "</soap:Body>" _
& "</soap:Envelope>"
MsgBox strrequest
objhttp.Open "GET", webserviceurl, False
objhttp.setRequestHeader "SOAPAction", "http://www.pli.edu/public/CEM/Service.asmx"
objhttp.setRequestHeader "Content-Type", "text/xml"
objhttp.send strrequest
MsgBox "response" & objhttp.responseText
Set objhttp = Nothing
Set XMLDOC = Nothing
End Sub
Sub plireader()
Dim strrequest As String
Dim objhttp As Object
strXmlToSend = "<company>demo</company>"
webserviceurl = "https://www.pli.edu/public/CEM/Service.asmx?op=CEMgetAttendance"
Set objhttp = CreateObject("MSXML2.XMLHT
MsgBox "send now"
strrequest = "<?xml version=""1.0"" encoding=""utf-8""?>" _
& "<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/"">" _
& "<soap:Body>" _
& "<CEMgetAttendence xmlns=""http://www.pli.edu/public/CEM/"">" _
& "<company>demo</company>" _
& "</CEMgetAttendence>" _
& "</soap:Body>" _
& "</soap:Envelope>"
MsgBox strrequest
objhttp.Open "GET", webserviceurl, False
objhttp.setRequestHeader "SOAPAction", "http://www.pli.edu/public/CEM/Service.asmx"
objhttp.setRequestHeader "Content-Type", "text/xml"
objhttp.send strrequest
MsgBox "response" & objhttp.responseText
Set objhttp = Nothing
Set XMLDOC = Nothing
End Sub
Why did you change the HTTP method to "GET"? It should be "POST" since you are sending the content.
In the previous comment I suggested to add the following header:
objhttp.setRequestHeader "SOAPAction", "http://www.pli.edu/public/CEM/Service.asmx?op=CEMgetAttendence"
but you reduced it to
objhttp.setRequestHeader "SOAPAction", "http://www.pli.edu/public/CEM/Service.asmx"
Because of that causes the server responds with a failure:
instead of the correct response:
In the previous comment I suggested to add the following header:
objhttp.setRequestHeader "SOAPAction", "http://www.pli.edu/public/CEM/Service.asmx?op=CEMgetAttendence"
but you reduced it to
objhttp.setRequestHeader "SOAPAction", "http://www.pli.edu/public/CEM/Service.asmx"
Because of that causes the server responds with a failure:
<soap:Fault><faultcode>soap:Client</faultcode><faultstring>Server did not recognize the value of HTTP Header SOAPAction: http://www.pli.edu/public/CEM/Service.asmx.</faultstring><detail /></soap:Fault>
instead of the correct response:
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><CEMgetAttendenceResponse xmlns="http://www.pli.edu/public/CEM/"><CEMgetAttendenceResult><CEM xmlns="" /></CEMgetAttendenceResult></CEMgetAttendenceResponse></soap:Body></soap:Envelope>
ASKER
getting closer
Sub plireader()
Dim strrequest As String
Dim objhttp As Object
strXmlToSend = "<company>demo</company>"
webserviceurl = "https://www.pli.edu/public/CEM/Service.asmx"
Set objhttp = CreateObject("MSXML2.XMLHT TP.3.0")
MsgBox "send now"
strrequest = "<?xml version=""1.0"" encoding=""utf-8""?>" _
& "<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/"">" _
& "<soap:Body>" _
& "<CEMgetAttendence xmlns=""http://www.pli.edu/public/CEM/"">" _
& "<company>demo</company>" _
& "</CEMgetAttendence>" _
& "</soap:Body>" _
& "</soap:Envelope>"
MsgBox strrequest
objhttp.Open "POST", webserviceurl, False
objhttp.setRequestHeader "SOAPAction", "http://www.pli.edu/public/CEM/Service.asmx?op=CEMgetAttendence"
objhttp.setRequestHeader "Content-Type", "text/xml"
objhttp.send strrequest
MsgBox "response" & objhttp.responseText
Set objhttp = Nothing
Set XMLDOC = Nothing
End Sub
Sub plireader()
Dim strrequest As String
Dim objhttp As Object
strXmlToSend = "<company>demo</company>"
webserviceurl = "https://www.pli.edu/public/CEM/Service.asmx"
Set objhttp = CreateObject("MSXML2.XMLHT
MsgBox "send now"
strrequest = "<?xml version=""1.0"" encoding=""utf-8""?>" _
& "<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/"">" _
& "<soap:Body>" _
& "<CEMgetAttendence xmlns=""http://www.pli.edu/public/CEM/"">" _
& "<company>demo</company>" _
& "</CEMgetAttendence>" _
& "</soap:Body>" _
& "</soap:Envelope>"
MsgBox strrequest
objhttp.Open "POST", webserviceurl, False
objhttp.setRequestHeader "SOAPAction", "http://www.pli.edu/public/CEM/Service.asmx?op=CEMgetAttendence"
objhttp.setRequestHeader "Content-Type", "text/xml"
objhttp.send strrequest
MsgBox "response" & objhttp.responseText
Set objhttp = Nothing
Set XMLDOC = Nothing
End Sub
Your code looks fine, but the server www.pli.edu is seemingly down.
ASKER
thanks will try later today
ASKER
srill getting error = the parameter is incorrect at this statement
objhttp.send strrequest
objhttp.send strrequest
According to the following articles COM XMLHTTP objects are not supported in .net applications:
https://social.msdn.microsoft.com/Forums/windowsapps/en-US/05afaa66-7df4-47f9-9a56-4cb3ee029e48/vbnet-xmlhttpsend-the-parameter-is-incorrect?forum=vbgeneral
https://support.microsoft.com/en-us/help/815112/the-use-of-msxml-is-not-supported-in--net-applications
https://social.msdn.microsoft.com/Forums/windowsapps/en-US/05afaa66-7df4-47f9-9a56-4cb3ee029e48/vbnet-xmlhttpsend-the-parameter-is-incorrect?forum=vbgeneral
https://support.microsoft.com/en-us/help/815112/the-use-of-msxml-is-not-supported-in--net-applications
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
that worked - thanks so much for all your help and handholding
You are welcome
The question author was apparently satisfied by this answer.
Open in new window
Now it prints the server response which contains an error:Open in new window
I think, the server expects some SOAP-like XML to be sent, not just URL-encoded parameters.