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.
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 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.
One of my websites contact/reservations form has suddenly stopped working and I now receive the following error.
Server object error 'ASP 0177 : 800401f3'
Server.CreateObject Failed
/contact2.asp, line 51
I've done a bit of research and it seems to relate to classic ASP commands but
my knowledge of ASP is limited.
Here is the full code:-
<%
name = request.form("name")
email = request.form("email")
phone = request.form("phone")
guests = request.form("guests")
datum2 = request.form("datum2")
info = request.form("info")
time_hour = request.form.item("time_hour")
time_minute = request.form.item("time_minute")
moda_event = request.form.item("modaEvent")
sign_up = request.form.item("signup")
If name="" or email="" Then
url = "reservations.asp?reqd=* indicates required field&name=" & mname & "&email=" & memail
If name="" Then
url = url & "&mname=*"
End if
If email="" Then
url = url & "&memail=*"
End if
response.redirect url & "&foobar=foobar#form"
response.end
End if
Dim objCDONTS ' Email object
Dim strFromName ' From persons' real name
Dim strFromEmail, strToEmail ' Email addresses
Dim strSubject, strName, strPhone, strEmail, strGuests, strDate, strHour, strMinute, strEvent, strInfo, strSignup 'Message
Dim misccompo
strSubject = "Reservation Form"
strFromName = Trim(Request.Form("name"))
strFromEmail = Trim(Request.Form("email"))
strToEmail = "reservations#modarestaurant.co.uk"
strName = Trim(Request.Form("name"))
strPhone = Trim(Request.Form("phone"))
strEmail = Trim(Request.Form("email"))
strGuests = Trim(Request.Form("guests"))
strDate = Trim(Request.Form("datum2"))
strHour = Trim(Request.Form.Item("time_hour"))
strMinute = Trim(Request.Form.Item("time_minute"))
strEvent = Trim(Request.Form.Item("moda_event"))
strInfo = Trim(Request.Form("info"))
strSignup = Trim(Request.Form.Item("signup"))
Set objCDONTS = Server.CreateObject("CDONTS.NewMail")
objCDONTS.From = strFromName & " <" & strFromEmail & ">"
objCDONTS.To = strToEmail
objCDONTS.Subject = strSubject
objCDONTS.Body = "--------------------------------------" & vbcrlf & vbcrlf & "Name: " & strName & vbcrlf & "Contact Number: " & strPhone & vbcrlf & "Email Address: " & strEmail & vbcrlf & "No. of Guests: " & strGuests & vbcrlf & "Date: " & strDate & vbcrlf & "Time: " & strHour & ":" & strMinute & vbcrlf & "Event: " & strEvent & vbcrlf & "Additional Info: " & vbcrlf & strInfo & vbcrlf & "Newsletter Signup: " & strSignup &vbcrlf & "--------------------------------------------------------------" & vbcrlf & "MESSAGE ENDS: End of info"
objCDONTS.Send
Set objCDONTS = Nothing
response.redirect "thank-you.asp"
response.end
%>
The line 51 error is this line;
Set objCDONTS = Server.CreateObject("CDONTS.NewMail")
Any help would be greatly appreciated.
The error
Server object error 'ASP 0177 : 800401f3'
Server.CreateObject Failed
/contact2.asp, line 51
means that the object could not be created because it could not find the appropriate DLL for the object requested. In other words, it is looking for the CDONTS COM component that was included with NT SP4 as the file cdont.dll. CDONTS was deprecated in Windows 2000 and completely removed in Windows 2003. Therefore, if you are using Window 2003, Windows 2008 or Windows 2012 server this error makes sense since the DLL is not present.
To fix this problem try the following - use CDOSYS. CDOSYS (cdosys.dll) is a library file provided as part of IIS for Windows 2000, Windows 2003 Server, and Windows 2008 Server. This DLL enabled applications to route SMTP messages across multiple platforms and added much more functionality over the older CDONTS library.
Here is a greatly simplified example to model some changes on
Dim Message As New CDO.Message
sch = "http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = CreateObject("CDO.Configuration")
with cdoConfig.Fields
.item(sch & "sendusing") = 2
.Item(sch & "smtpserver") = "mail.xxxx.com" ' your SMTP mail server
.Item(sch & "smtpserverport") = 2525
.update
end with
'Create CDO message object
Set Message = CreateObject("CDO.Message")
With Message
set .configuration = cdoConfig
'Set email adress, subject And body
.From = strFromName
.To = strToEmail
.Subject = strSubject
.TextBody = TextBody
'Send the message
.Send
End With
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: