public static void Main()
var CustomActionExecution = new CustomActionExecuteCutonActionWrapper();
CustomActionExecution.Execute();
public class CustomActionExecuteCutonActionWrapper
public System.Collections.Generic.Dictionary<string, string> ExecutionProperties = new System.Collections.Generic.Dictionary<string, string>();
public bool ForceRollback { get; set; }
public string CustomActionReceivedContent { get;private set;}
public string ContentTypeRequest { get;private set;}
public string CustomActionResponseContent { get; set; }
public string ContentTypeResponse { get; private set;}
public CustomActionExecuteCutonActionWrapper()
ExecutionProperties.Add("Url", "https://globo.com");
ExecutionProperties.Add("BodyRequest", "bla bla bla");
ExecutionProperties.Add("Token", "bla bla bla");
Url = ExecutionProperties["Url"];
BodyRequest = ExecutionProperties["BodyRequest"];
Token = ExecutionProperties["Token"];
bool resultUri = System.Uri.TryCreate(Url, System.UriKind.Absolute, out uri) && (uri.Scheme == System.Uri.UriSchemeHttp || uri.Scheme == System.Uri.UriSchemeHttps);
throw new System.UriFormatException("Url em formato não suportado.");
if (uri.Scheme == System.Uri.UriSchemeHttps)
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
int resultHttpStatusCode = 0;
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(Url);
System.Net.HttpWebResponse httpResponse = null;
request.Accept = "application/xml";
request.ContentType = "application/xml";
request.Headers.Add("Authentication", "Bearer " + Token);
using (var streamWriter = new System.IO.StreamWriter(request.GetRequestStream()))
streamWriter.Write(BodyRequest);
httpResponse = (System.Net.HttpWebResponse)request.GetResponse();
if (httpResponse != null)
using (var streamReader = new System.IO.StreamReader(httpResponse.GetResponseStream()))
BodyResponse = streamReader.ReadToEnd();
resultHttpStatusCode = (int)httpResponse.StatusCode;
catch (System.Net.WebException webEx)
ErrorMessage = webEx.Message;
using (System.Net.WebResponse response = webEx.Response)
httpResponse = (System.Net.HttpWebResponse)response;
if (httpResponse != null)
using (var streamReader = new System.IO.StreamReader(httpResponse.GetResponseStream()))
BodyResponse = streamReader.ReadToEnd();
resultHttpStatusCode = (int)httpResponse.StatusCode;
catch (System.Exception ex)
ErrorMessage = ex.Message;
ExecutionProperties.Add("BodyResponse", BodyResponse);
ExecutionProperties.Add("HasError", HasError.ToString());
ExecutionProperties.Add("ErrorMessage", ErrorMessage);