Wednesday, December 14, 2011

In c# WSE security

First,Install WSE 2. From Microsoft.

Before you call for service;

svc.RequestSoapContext.Security.Tokens.Add(new UsernameToken(UserName, Password, PasswordOption.SendPlainText));

Why did not write Nlog to targets

In  NLog.config write nlog tabs; throwExceptions="true" internalLogFile="c:\nlog.txt" internalLogLevel="Trace" 


<nlog xmlns=""
      xmlns:xsi="" throwExceptions="true" internalLogFile="c:\nlog.txt" internalLogLevel="Trace" >

Monday, November 28, 2011

Basic Authentication

protected override System.Net.WebRequest GetWebRequest(Uri uri)
            string pass = "pass" + ":" + "****";           
            var key = Convert.ToBase64String(new System.Text.ASCIIEncoding().GetBytes(pass));
            var basicKey= "Basic " + key;
            var getWebRequest = base.GetWebRequest(uri);          
            getWebRequest.Headers.Add("authorization", basicKey);
            return getWebRequest;

Wednesday, November 2, 2011

The remote server returned an error: (404) Not Found

In web.config file, change endpoint address http to basic

Tuesday, October 11, 2011

InArgument and OutArgument in Workflow(WF 4)

            //Input Argument WF
            IDictionary<stringobject> inputs = new Dictionary<stringobject>
                {"Person1"new Person{ Name="Tom", Age=26}}
            //Output Argument
            IDictionary<string,object> outputs=WorkflowInvoker.Invoke(new Activity1(),inputs);

Elmah Error Filtering(Ignore Some Exceptions)

Open the Global.asax file then write code;

void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
            if (e.Exception.GetBaseException() is FileNotFoundException || e.Exception.GetBaseException() is HttpException)

Send Mail on Exception With Extensible Method

class Program
        static void Main(string[] args)
                throw new Exception("Expection");
            catch (Exception ex)
    public static class MyExtension
        public static void SendErrorEmail(this Exception ex)
            //Write your send mail code