Invoking webservices using dotnet variables

smshydsmshyd Member Posts: 72
edited 2014-10-13 in NAV Three Tier
Hi experts ,
I found below link for invoking webservices
http://codeverge.com/asp.net.handlers-m ... ttp/211661
Dim oURI As New System.Uri(msURL)
        Dim oRequest As HttpWebRequest
        oRequest = CType(WebRequest.CreateDefault(oURI), HttpWebRequest)
        oRequest.Method = "POST"
        oRequest.ContentType = "text/html"
        oRequest.KeepAlive = True
        oRequest.Timeout() = miConnectorTimeout
        oRequest.Credentials = New NetworkCredential(msUserID, msPassword)
        Dim oResponse As HttpWebResponse
        oRequest.ContentLength = sHeader.Length
        Dim oStream As New StreamWriter(oRequest.GetRequestStream, Encoding.ASCII)
        oStream.Write(sHeader)
        oStream.Close()
        oResponse = CType(oRequest.GetResponse, HttpWebResponse)
        If oResponse.StatusCode = 200 Then
            Dim oReader As New StreamReader(oResponse.GetResponseStream)
            Return oReader.ReadToEnd
        ElseIf oResponse.StatusCode = 401 Then
            Return "Unauthorized"
        End If
I have mapped navision code as follows
msURL := 'http://tempuri.org/sometext';
Ouri := Ouri.Uri(msURL);
//oRequest = (HttpWebRequest)WebRequest.CreateDefault(oURI);
oRequest.Method := 'POST';
oRequest.ContentType := 'text/html'; //'XML'
oRequest.KeepAlive := TRUE;
oRequest.Timeout := 10;
oRequest.Credentials(NetworkCredential);
oRequest.ContentLength := 1024;
oStream := oStream.StreamWriter(oRequest.GetRequestStream);
oStream.Write('demo');
oStream.Close;
//oResponse = CType(oRequest.GetResponse, HttpWebResponse)

IF oResponse.StatusCode = 200 THEN BEGIN
 oReader := oReader.StreamReader(oResponse.GetResponseStream);
  oReaderReadtoend := oReader.ReadToEnd ;
END ELSE
 IF oResponse.StatusCode = 401 THEN BEGIN

   MESSAGE('Unauthorized');
END;
How can I map below 2 lines code in navision which containing typecasting

oRequest = (HttpWebRequest)WebRequest.CreateDefault(oURI);
oResponse = CType(oRequest.GetResponse, HttpWebResponse);
where variables are given below
Name	DataType	Subtype	Length
oRequest	DotNet	System.Net.HttpWebRequest.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
oResponse	DotNet	System.Net.HttpWebResponse.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
Ouri	DotNet	System.Uri.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
msURL	Text		
NetworkCredential	DotNet	System.Net.NetworkCredential.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
oStream	DotNet	System.IO.StreamWriter.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
oReader	DotNet	System.IO.StreamReader.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
oReaderReadtoend	Text		

Comments

  • PrebenRasmussenPrebenRasmussen Member Posts: 137
    oRequest = (HttpWebRequest)WebRequest.CreateDefault(oURI);
    should be written as:
    oRequest := WebRequest.Create(msURL);
    
    oResponse = CType(oRequest.GetResponse, HttpWebResponse);
    should be written as:
    oResponse := oRequest.GetResponse()
    
  • tina11tina11 Member Posts: 2
    I m trying your solution but I m unable to find System.Net.HttpWebResponse in .net library.
  • ftorneroftornero Member Posts: 524
    You can copy and paste in the variable DotNet Subtype part the following:

    System.Net.HttpWebResponse.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

    Regards.
Sign In or Register to comment.