Hi,
The below code can be used to call an external web service from AX D365 for operations.
public static void main(Args _args)
{
System.Net.HttpWebRequest request = null;
System.Net.HttpWebResponse response = null;
CLRObject webResponse;
System.Net.WebHeaderCollection headers;
System.IO.MemoryStream stream;
Binary requestContent;
str responseData;
System.Exception ex;
System.Net.WebException webException;
RetailWebResponse retailWebResponse;
int httpStatusCode;
str contentType;
RetailWebRequest _request;
System.IO.Stream streamLoc;
try
{
request = System.Net.WebRequest::Create("https://www.google.co.in/") as System.Net.HttpWebRequest;
_request = RetailWebRequest::newUrl("https://www.google.co.in/");
if (strLen(_request.parmMethod()) > 0)
{
request.set_Method(_request.parmMethod());
}
headers = request.get_Headers();
if (strLen(_request.parmHeader()) > 0)
{
headers.Add(_request.parmHeader());
}
if (strLen(_request.parmContentType()) > 0)
{
request.set_ContentType(_request.parmContentType());
}
requestContent = _request.parmContent();
if (requestContent)
{
streamLoc = requestContent.getMemoryStream();
System.Byte[] _bytes = stream.ToArray();
request.set_ContentLength(_bytes.get_Length());
streamLoc = request.GetRequestStream();
streamLoc.Write(_bytes, 0, _bytes.get_Length());
streamLoc.Close();
}
webResponse = request.GetResponse();
response = webResponse as System.Net.HttpWebResponse;
}
catch (Exception::CLRError)
{
ex = ClrInterop::getLastException();
if (ex != null)
{
ex = ex.get_InnerException();
if ((ex != null) && (ex is System.Net.WebException))
{
webException = ex as System.Net.WebException;
webResponse = webException.get_Response();
response = webResponse as System.Net.HttpWebResponse;
}
}
}
}
Regards,
Pradeep
The below code can be used to call an external web service from AX D365 for operations.
public static void main(Args _args)
{
System.Net.HttpWebRequest request = null;
System.Net.HttpWebResponse response = null;
CLRObject webResponse;
System.Net.WebHeaderCollection headers;
System.IO.MemoryStream stream;
Binary requestContent;
str responseData;
System.Exception ex;
System.Net.WebException webException;
RetailWebResponse retailWebResponse;
int httpStatusCode;
str contentType;
RetailWebRequest _request;
System.IO.Stream streamLoc;
try
{
request = System.Net.WebRequest::Create("https://www.google.co.in/") as System.Net.HttpWebRequest;
_request = RetailWebRequest::newUrl("https://www.google.co.in/");
if (strLen(_request.parmMethod()) > 0)
{
request.set_Method(_request.parmMethod());
}
headers = request.get_Headers();
if (strLen(_request.parmHeader()) > 0)
{
headers.Add(_request.parmHeader());
}
if (strLen(_request.parmContentType()) > 0)
{
request.set_ContentType(_request.parmContentType());
}
requestContent = _request.parmContent();
if (requestContent)
{
streamLoc = requestContent.getMemoryStream();
System.Byte[] _bytes = stream.ToArray();
request.set_ContentLength(_bytes.get_Length());
streamLoc = request.GetRequestStream();
streamLoc.Write(_bytes, 0, _bytes.get_Length());
streamLoc.Close();
}
webResponse = request.GetResponse();
response = webResponse as System.Net.HttpWebResponse;
}
catch (Exception::CLRError)
{
ex = ClrInterop::getLastException();
if (ex != null)
{
ex = ex.get_InnerException();
if ((ex != null) && (ex is System.Net.WebException))
{
webException = ex as System.Net.WebException;
webResponse = webException.get_Response();
response = webResponse as System.Net.HttpWebResponse;
}
}
}
}
Regards,
Pradeep
No comments:
Post a Comment