I am trying to call a soap request from classic asp (it will be updated at some later point, but for now it stays classic asp), but I'm only getting half of the response?
When I use the request string in SoapUI, I get the response I'm looking for, but in asp I only receive part of the response??
ASP Request:
Set oXmlHTTP = CreateObject("Microsoft.XMLHTTP")
oXmlHTTP.Open "POST", "http://webservice-string?wsdl", False
oXmlHTTP.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
oXmlHTTP.setRequestHeader "SOAPAction", "urn:action"
SOAPRequest = _
"<?xml version=""1.0"" encoding=""utf-8""?>" &_
"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:head=""http://header.com"" xmlns:ser=""http://service.com"" xmlns:add=""http://service.com/domain/address"">" &_
"<soapenv:Header>" &_
"<head:OnBehalfOfUserId>stine</head:OnBehalfOfUserId>" &_
"<head:RequestId>?</head:RequestId>" &_
"<head:AuthenticationHeader>" &_
"<head:SessionID>?</head:SessionID>" &_
"</head:AuthenticationHeader>" &_
"</soapenv:Header>" &_
"<soapenv:Body>" &_
"<ser:searchVisitationRequest>" &_
"<ser:UserId>Stine</ser:UserId>" &_
"<ser:RequestId>?</ser:RequestId>" &_
"<add:SomeId>1234</add:SomeId>" &_
"</ser:searchVisitationRequest>" &_
"</soapenv:Body>" &_
"</soapenv:Envelope>"
On Error Resume Next
oXmlHTTP.send SOAPRequest
If Err.Number Then
Err.Clear
Else
SOAPResponse = oXmlHTTP.responseXML.text
End If
On Error Goto 0
if len(SOAPResponse) > 0 then
Response.Write SOAPResponse
end if
ASP Response:
2018-06-25T09:56:36.016+02:00server_ID{bla bla}5
SoapUI response
(made from same request - contains "SearchVisitation" which is the result I need!)
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<searchVisitationResponse xmlns="http://service.com">
<ReplyInfo>
<ReplyTimestamp>2018-06-25T08:47:48.204+02:00</ReplyTimestamp>
<ServerId>server_ID</ServerId>
<StatusMessage>{bla bla}</StatusMessage>
<TransactionDuration>3</TransactionDuration>
</ReplyInfo>
<SearchVisitation>
<OtherID>12345678</OtherID>
<SearchVisitationID>
<SubscriptionNo>Test1</SubscriptionNo>
</SearchVisitationID>
</SearchVisitation>
</searchVisitationResponse>
</S:Body>
</S:Envelope>
What am I doing wrong?
Turns out that
oXmlHTTP.setRequestHeader "SOAPAction", "urn:action"
was the part that would cause the request to error (I've - again - triple checked that the urn:action was correct).
Removing it gave me the correct response.
Related
I keep getting a 404 error.
It works fine if I call the REST API from SoapUI.
I’m using Visual Basic VS2015.
I have a sample function which I’m calling from a simple forms project. This is just to get the REST API to work. The REST API call will go into a Visual Basic Windows Service once I get it working,
There is a form named form1 which has a txtURL textbox, a button to call sub Main(), and an output textbox called textbox1.
Public Shared Sub Main()
Try
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(Form1.txtURL.Text), HttpWebRequest)
With myHttpWebRequest
.Method = "POST"
.ContentType = "application/json"
.Accept = "application/json"
.MediaType = "jsonp"
With .Headers
.Add("Authorization", "Bearer ABCDabcd1234=")
.Add("riskLevelStatus", "6897")
.Add("userId", "12345")
.Add("applicationName", "MyApp")
End With
End With
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
Form1.TextBox1.Text = Form1.TextBox1.Text & myHttpWebResponse.ToString() & vbCrLf
myHttpWebResponse.Close()
'Catch exception if trying to add a restricted header.
Catch e As ArgumentException
Form1.TextBox1.Text = Form1.TextBox1.Text & "Error-ArgumentException: " & e.Message & vbCrLf
Catch e As WebException
Form1.TextBox1.Text = Form1.TextBox1.Text & "Error-WebException: " & e.Message & vbCrLf
If e.Status = WebExceptionStatus.ProtocolError Then
Form1.TextBox1.Text = Form1.TextBox1.Text & "Error-Status Code: " & CType(e.Response, HttpWebResponse).StatusCode & vbCrLf
Form1.TextBox1.Text = Form1.TextBox1.Text & "Error-Status Description: " & CType(e.Response, HttpWebResponse).StatusDescription & vbCrLf
Form1.TextBox1.Text = Form1.TextBox1.Text & "Error-Server: " & CType(e.Response, HttpWebResponse).Server & vbCrLf
End If
Catch e As Exception
Form1.TextBox1.Text = Form1.TextBox1.Text & "Error-Exception: " & e.Message & vbCrLf
End Try
End Sub 'Main
Here is what is outputted to textbox1:
Error -WebException: The remote server returned an Error: (400) Bad Request.
Error -Status Code: 400
Error -Status Description
Error -Server
What should be returned is a single line JSON, similar to this:
{“quid”: “jhgdsjdshg-hdbw-akjhjk-kdhbfsihg”}
It works fine when calling from SoapUI.
I believe this issue is how do I add data to the body?
I figured it out. I cannot believe nobody had an answer.
Public Sub Try01(URL)
Try
Dim myReq As HttpWebRequest
Dim myResp As HttpWebResponse
Dim myReader As StreamReader
myReq = HttpWebRequest.Create(URL)
myReq.Method = "POST"
myReq.ContentType = "application/json"
myReq.Accept = "application/json"
myReq.Headers.Add("Authorization", "Bearer LKJLMLKJLHLMKLJLM839800K=")
Dim myData As String = "{""riskLevelStatus"":""0001"",""userId"":""10000004030"",""applicationName"":""MyTestRESTAPI""}"
myReq.GetRequestStream.Write(System.Text.Encoding.UTF8.GetBytes(myData), 0, System.Text.Encoding.UTF8.GetBytes(myData).Count)
myResp = myReq.GetResponse
myReader = New System.IO.StreamReader(myResp.GetResponseStream)
TextBox1.Text = myReader.ReadToEnd
Catch ex As Exception
TextBox1.Text = TextBox1.Text & "Error: " & ex.Message
End Try
End Sub
I have the following simple Soap request code. (using classic ASP)
I've read many tutorials on consuming SOAP feeds in classic ASP, but none of them seem to work at all.
I try the following code:
soapEnvelope = _
"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/""" &_
"xmlns:etp=""https://test.mpay24.com/soap/etp/1.5/ETP.wsdl"">" &_
"<soapenv:Header/>" &_
" <soapenv:Body>" &_
" <etp:SelectPayment>" &_
" <merchantID>XXXXXX</merchantID>" &_
" <mdxi>" &_
" <Order>" &_
" <Tid>cust9126</Tid>>" &_
" <Price>10.00</Price>" &_
" </Order>" &_
" </mdxi>" &_
" </etp:SelectPayment>" &_
" </soapenv:Body>" &_
" </soapenv:Envelope>"
Set SoapRequest = CreateObject("Microsoft.XMLHTTP")
Set myXML =Server.CreateObject("MSXML.DOMDocument")
myXML.Async=False
SoapRequest.Open "POST", "https://test.mpay24.com/app/bin/etpproxy_v15", False, "user", "password"
SoapRequest.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
sSOAPAction = "https://test.mpay24.com/soap/etp/1.5/ETP.wsdl" + "SelectPayment"
SoapRequest.setRequestHeader "SOAPAction", sSOAPAction
SoapRequest.send soapEnvelope
myResponseText = SoapRequest.responseText
responseText is:
"SOAP-ENV:ClientMethod 'etp:SelectPayment' not implemented: method name or namespace not recognized"
I think my
SoapRequest.setRequestHeader "SOAPAction" is false.
I have the unfortunate task of sending e-mail through a client that needs to connect to Outlook Anywhere through VBScript. I may not understand the correct terminology when dealing with Exchange Server, therefore the answer may be evading me simply because I don't know what I'm searching for, and after hours on Google I still haven't found the answer.
I cannot use SMTP, since the script will be connecting from many locations/networks and they may or may not block the traffic through the default port. I cannot change the default port because the network admin (who is the actual customer) will not change it.
Any pointers in the right direction will be appreciated.
If I understand your question correctly, you actually want to be able to use the installed/running version of Outlook on a client machine to generate and send an email message which it will hand off to whatever configured MTA it is using, probably via the Exchange Server it is configured to on a private LAN or over VPN when on a public network. If so, what you want to look at is using what is called "Automation" in Microsoft's nomenclature. For most scripting languages and development tools, you can do this via COM. The following Microsoft article shows how to do this in VBA which should give you enough specifics to use almost as-is for VBScript.
http://support.microsoft.com/kb/209948
The answer to my question is partially on stackoverflow already at the following question Ways to send E-Mails over MS Exchange with VBScript.
The code below (VBA, but close enough to VBScript) is simply sending a SOAP message to the Exchange Web Service. It was built from various bits and pieces found all over the web (including the links above).
Option Explicit
' ---------------------------------------------------------
' CONFIGURATION - change as needed
' ---------------------------------------------------------
Const TARGETURL = "https://mail.XXXXX.com/ews/exchange.asmx"
Const USERNAME = "XXXXX\dnreply"
Const PASSWORD = "X1X2X3X4X!x#x#x$x%"
Sub SendMessageEWS()
Dim SOAP
SOAP = CreateMessageSOAP()
' Send the SOAP request, and return the response
Dim oXMLHTTP, oXml
Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
Set oXml = CreateObject("MSXML2.DOMDocument")
' Send the request
oXMLHTTP.Open "POST", TARGETURL, False, USERNAME, PASSWORD
oXMLHTTP.setRequestHeader "Content-Type", "text/xml"
oXMLHTTP.send SOAP
If oXMLHTTP.Status = "200" Then
' Get response
If oXml.LoadXML(oXMLHTTP.ResponseText) Then
' Success
Debug.Print oXml.XML
End If
Else
Debug.Print oXMLHTTP.ResponseText
MsgBox "Response status: " & oXMLHTTP.Status
End If
End Sub
Function CreateMessageSOAP()
' Normally this is done by using the DOM, but this is easier for a demo...
Dim SOAPMsg
SOAPMsg = SOAPMsg & "<?xml version='1.0' encoding='utf-8'?>"
SOAPMsg = SOAPMsg & " <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:t='http://schemas.microsoft.com/exchange/services/2006/types' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>"
SOAPMsg = SOAPMsg & " <soap:Body>"
SOAPMsg = SOAPMsg & " <CreateItem MessageDisposition='SendAndSaveCopy' xmlns='http://schemas.microsoft.com/exchange/services/2006/messages'>"
SOAPMsg = SOAPMsg & " <SavedItemFolderId>"
SOAPMsg = SOAPMsg & " <t:DistinguishedFolderId Id='sentitems' />"
SOAPMsg = SOAPMsg & " </SavedItemFolderId>"
SOAPMsg = SOAPMsg & " <Items>"
SOAPMsg = SOAPMsg & " <t:Message>"
SOAPMsg = SOAPMsg & " <t:Subject>Exchange Web Service E-Mail Test</t:Subject>"
' For HTML message body
SOAPMsg = SOAPMsg & " <t:Body BodyType='HTML'><![CDATA[<h1>Test html body</h1>]]></t:Body>"
' For text message body
' SOAPMsg = SOAPMsg & " <t:Body BodyType='Text'><![CDATA[Test text body]]></t:Body>"
SOAPMsg = SOAPMsg & " <t:ToRecipients>"
SOAPMsg = SOAPMsg & " <t:Mailbox>"
SOAPMsg = SOAPMsg & " <t:EmailAddress>recipient#XXXXX.com</t:EmailAddress>"
SOAPMsg = SOAPMsg & " </t:Mailbox>"
SOAPMsg = SOAPMsg & " </t:ToRecipients>"
SOAPMsg = SOAPMsg & " </t:Message>"
SOAPMsg = SOAPMsg & " </Items>"
SOAPMsg = SOAPMsg & " </CreateItem>"
SOAPMsg = SOAPMsg & " </soap:Body>"
SOAPMsg = SOAPMsg & " </soap:Envelope>"
CreateMessageSOAP = SOAPMsg
End Function
I have been tasked with obtaining a response from a SOAP request, using classic asp. The request is about as basic as it gets - I just need to fire off 3 parameters to a web service URL and write out the response (which is in simple plain text format). I've checked the service using a couple of SOAP testing utilities and it outputs the response fine.
I've also read about 10 different tutorials on consuming SOAP feeds in classic ASP, but none of them seem to work at all.
The latest one I'm trying has given me the following code:
<%
Set oXmlHTTP = CreateObject("Microsoft.XMLHTTP")
oXmlHTTP.Open "POST", "http://www.webservicehost.co.uk/B2bservice.asmx?wsdl", False
oXmlHTTP.setRequestHeader "Content-Type", "application/soap+xml; charset=utf-8"
oXmlHTTP.setRequestHeader "SOAPAction", "http://ourNameSpace/ourFunction"
SOAPRequest = _
"<?xml version=""1.0"" encoding=""utf-8""?>" &_
"<soap12:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap12=""http://www.w3.org/2003/05/soap-envelope"">" &_
"<soap12:Body>" &_
"<ourFunction xmlns=""http://ourNameSpace/"">" &_
"<Ccode>OurCode</Ccode>" &_
"<Pword>1d2s45a</Pword>" &_
"<OrderNo>9876</OrderNo>" &_
"</ourFunction>" &_
"</soap12:Body>" &_
"</soap12:Envelope>"
oXmlHTTP.send SOAPRequest
response.write oXmlHTTP.responseText
%>
I have all the correct values for the POST URL, the Ccode, Pword and OrderNo variables, but have no idea what to use for the "SoapAction" or values. As a result, when I run the page I just get an error:
soap:SenderUnable to handle request without a valid action parameter. Please supply a valid soap action.
Can anyone suggest what to use for the SoapAction and ourFunction xmlns values?
Many thanks for any pointers...
your code should work ok with a few changes
<%
Response.Write "<br>START<hr>"
Set oXmlHTTP = CreateObject("Microsoft.XMLHTTP")
oXmlHTTP.Open "POST", "http://www.crusaderb2b.co.uk/b2bservice.asmx", False
oXmlHTTP.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
oXmlHTTP.setRequestHeader "SOAPAction", "http://crusaderb2b.co.uk/TrackingId"
SOAPRequest = _
"<?xml version=""1.0"" encoding=""utf-8""?>" &_
"<soap12:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap12=""http://www.w3.org/2003/05/soap-envelope"">" &_
"<soap12:Body>" &_
"<ourFunction xmlns=""http://ourNameSpace/"">" &_
"<Ccode>OurCode</Ccode>" &_
"<Pword>1d2s45a</Pword>" &_
"<OrderNo>9876</OrderNo>" &_
"</ourFunction>" &_
"</soap12:Body>" &_
"</soap12:Envelope>"
oXmlHTTP.send SOAPRequest
Response.Write oXmlHTTP.responseText
Response.Write "<br>END<hr>"
%>
changes are
remove ?wdsl
change content type
method call needs to be the same server of the webservice as it's the method name
added
I changed the code as you provided the Web Service. All you need you have in the service page as:
original image here
answer with the code above:
var oXMLDoc, oXMLHttp, soapRequest, soapResponse;
oXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
oXMLHttp.open("POST", "http://nerdbox/HelloService.svc", false);
// Add HTTP headers
oXMLHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
oXMLHttp.setRequestHeader("SOAPAction", "http://tempuri.org/IHelloService/SayHello");
// Form the message
soapRequest = '<?xml version="1.0" encoding="utf-16"?><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><SayHello xmlns="http://tempuri.org/"><name>Zuhaib</name></SayHello></soap:Body></soap:Envelope>';
WScript.Echo("Request : " + soapRequest);
oXMLHttp.send(soapRequest);
soapResponse = oXMLHttp.responseXML.xml;
WScript.Echo("Respose : " + soapResponse);
Whats wrong with this JScript? why am I getting 400 Bad Request. I read similar threads in stackoverflow .. some say its soap message formatting problem.
This is what the message looks like if I take it from fiddler.
Try changing your action from IHelloService to HelloService.
And let me ask you, why are you doing it the hard way. Just add a webHttpBinding and use JSON.
See a very easy example here.
I had to change your code to the following to get it to run in VBSEdit...then I (obviously) got the error about it not being able to find the resource...but change your code to this and see if it makes a difference?
Dim oXMLDoc, oXMLHttp, soapRequest, soapResponse
Set oXMLHttp = CreateObject("Microsoft.XMLHTTP")
oXMLHttp.open "POST", "http://nerdbox/HelloService.svc", False
'// Add HTTP headers
oXMLHttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
oXMLHttp.setRequestHeader "SOAPAction", "http://tempuri.org/IHelloService/SayHello"
'// Form the message
soapRequest = "<?xml version=""1.0"" encoding=""utf-16""?><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><SayHello xmlns=""http://tempuri.org/""><name>Zuhaib</name></SayHello></soap:Body></soap:Envelope>"
WScript.Echo "Request : " + soapRequest
oXMLHttp.send soapRequest
soapResponse = oXMLHttp.responseXML.xml
WScript.Echo "Respose : " + soapResponse