How to create a SOAP REQUEST using ASP.NET (VB) without using Visual
- by user311691
Hi all , I urgently need your help .
I am new to consuming a web service using SOAP protocol. I have been given a demo webservice URL which ends in .WSDL and NOT .asml?WSDL. The problem is I cannot add a web reference using Visual studio OR Disco.exe or Wsdl.exe - This webservice has been created on a java platform and for security reasons the only way to make a invoke the webservice is at runtime using SOAP protocol IN asp.net (VB).
I
I have created some code but cannot seem to send the soap object to the receiving web service.
If I could get a solution with step by step instructions on how I can send a SOAP REQUEST.
Below is my code and all am trying to do is send a SOAP REQUEST and receive a SOAP RESPONSE which I will display in my browser.
<%@ page language="vb" %>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Xml"%>
<%@ Import Namespace="System.Net"%>
<%@ Import Namespace="System.IO"%>
<%@ Import Namespace="System.Text"%>
<script runat=server>
Private Sub Page_Load()
Dim objHTTPReq As HttpWebRequest
Dim WebserviceUrl As String = "http://xx.xx.xx:8084/asy/wsdl/asy.wsdl"
objHTTPReq = CType(WebRequest.Create(WebserviceUrl), HttpWebRequest)
Dim soapXML As String
soapXML = "<?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> "& _
" <validatePaymentData xmlns='http://asybanks.webservices.asycuda.org'> " & _
" <bankCode>"& bankCode &"</bankCode> " & _
" <PaymentDataType>" & _
" <paymentType>"& payment_type &"</paymentType> " & _
" <amount>"& ass_amount &"</amount> " & _
" <ReferenceType>" & _
" <year>"& year &"</year> " & _
" <customsOfficeCode>"& station &"</customsOfficeCode> " & _
" </ReferenceType>" & _
" <accountNumber>"& zra_account &"</accountNumber> " & _
" </PaymentDataType> " & _
" </validatePaymentData> " & _
" </soap:Body> " & _
" </soap:Envelope> "
objHTTPReq.Headers.Add("SOAPAction", "http://asybanks.webservices.asycuda.org")
objHTTPReq.ContentType = "text/xml; charset=utf-8"
objHTTPReq.ContentLength = soapXML.Length
objHTTPReq.Accept = "text/xml"
objHTTPReq.Method = "POST"
Dim objHTTPRes As HttpWebResponse = CType(objHTTPReq.GetResponse(), HttpWebResponse)
Dim dataStream As Stream = objHTTPRes.GetResponseStream()
Dim reader As StreamReader = new StreamReader(dataStream)
Dim responseFromServer As String = reader.ReadToEnd()
OurXml.text = responseFromServer
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>
XML TRANSACTION SIMULATION - N@W@ TJ
</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<p>ZRA test Feedback:</p>
<asp:label id="OurXml" runat="server"/>
</div>
</form>
</body>
</html>
the demo webservice looks like this:
<?xml version="1.0" encoding="UTF-8" ?>
- <!-- WEB SERVICE JAVA DEMO
-->
- <definitions targetNamespace="http://asybanks.webservices.asycuda.org" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:y="http://asybanks.webservices.asycuda.org">
- <types>
- <xs:schema elementFormDefault="qualified" targetNamespace="http://asybanks.webservices.asycuda.org" xmlns="http://www.w3.org/2001/XMLSchema">
SOME OTHER INFORMATION AT THE BOTTOM
<soap:address location="http://xx.xx.xx:8084/asy/services/asy" />
</port>
</service>
</definitions>
From the above excerpt of the wsdl url webservice, I am not sure which namespace to use for soapACTION - please advise....
Please if you could comment every stage of a soap request and provide a working demo - I would be most grateful as I would be learning rather than just assuming stuff :)