First of all, apologies for this question. Let me write first, I've tried the below code for calling a SOAP
web service using C#
that worked perfectly. Now I am stuck with the conversion of the code into VB.NET
:
public void CallService(string username, string password)
{
HttpWebRequest request = CreateSOAPWebRequest();
XmlDocument SOAPReqBody = new XmlDocument();
SOAPReqBody.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"">
<SOAP-ENV:Header>
<wsse:Security xmlns:wsse=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"">
<wsse:UsernameToken>
<wsse:Username>" + username + @"</wsse:Username>
<wsse:Password>" + password + @"</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<OTA_PingRQ xmlns=""http://www.opentravel.org/OTA/2003/05"" EchoToken=""abc123"" TimeStamp=""2016-07-12T10:00:29.0Z"" Version=""1"">
<EchoData> Hello World </EchoData>
</OTA_PingRQ>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>");
using (Stream stream = request.GetRequestStream())
{
SOAPReqBody.Save(stream);
}
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
using (WebResponse Serviceres = request.GetResponse())
{
using (StreamReader rd = new StreamReader(Serviceres.GetResponseStream()))
{
var ServiceResult = rd.ReadToEnd();
lblMsg.Text = ServiceResult;
}
}
}
public HttpWebRequest CreateSOAPWebRequest()
{
HttpWebRequest Req = (HttpWebRequest)WebRequest.Create(@"https://cmtpi.siteminder.com/pmsxchangev2/services/CITRUS");
Req.Headers.Add(@"SOAP:Action");
Req.ContentType = "text/xml;charset=\"utf-8\"";
Req.Accept = "text/xml";
Req.Method = "POST";
return Req;
}
The above is a working code and my problem is when I try to convert it VB.NET
and there are few errors with quotations and even the Import keyword (Instead of using
in C#
) shows error as follows: I am not that expert with VB.NET
and would just expect some directions to make it work (Googled but unable to find the appropriate solution)
Public Sub CallService(ByVal username As String, ByVal password As String)
Dim request As HttpWebRequest = CreateSOAPWebRequest()
Dim SOAPReqBody As XmlDocument = New XmlDocument()
SOAPReqBody.LoadXml("<?xml version=""1.0"" encoding=""utf-8""?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http:schemas.xmlsoap.org/soap/envelope/"">
<SOAP-ENV:Header>
<wsse:Security xmlns:wsse=""http:'docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"">
<wsse:UsernameToken>
<wsse:Username>" + username + "</wsse:Username>
<wsse:Password>" + password + "</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<OTA_PingRQ xmlns=""http:'www.opentravel.org/OTA/2003/05"" EchoToken=""abc123"" TimeStamp=""2016-07-12T10:00:29.0Z"" Version=""1"">
<EchoData> Hello World </EchoData>
</OTA_PingRQ>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>")
Imports (Stream stream = request.GetRequestStream())
{
SOAPReqBody.Save(Stream)
}
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
Imports (WebResponse Serviceres = request.GetResponse())
{
Imports (StreamReader rd = New StreamReader(Serviceres.GetResponseStream()))
{
Dim ServiceResult As Var = rd.ReadToEnd()
Console.WriteLine(ServiceResult)
Console.ReadLine()
}
}
End Sub
Public Function CreateSOAPWebRequest() As HttpWebRequest
Dim Req As HttpWebRequest = CType(WebRequest.Create("https://cmtpi.siteminder.com/pmsxchangev2/services/CITRUS"), HttpWebRequest)
Req.Headers.Add("SOAP:Action")
Req.ContentType = "text/xml;charset=\"utf-8\""
Req.Accept = "text/xml"
Req.Method = "POST"
Return Req
End Function