How to call web service in .net

Leave a comment

Today I have worked on calling web service from console application, and I have searched on google also, but it seems to be not much.

I have done with the following code to call web service.

Imports System.Net
Imports System.IO
Imports System.Text

Public Class ScheduleTrigger

    Public Shared Sub Main()
        Const Template As String = _
"<?xml version=""1.0"" encoding=""utf-8""?>" & vbCrLf & _
"<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" & vbCrLf & _
"  <soap:Body>" & vbCrLf & _
"    <RunResponse xmlns=""http://tempuri.org/"" />" & vbCrLf & _
"  </soap:Body>" & vbCrLf & _
"</soap:Envelope>"

        Dim url = New Uri("http://localhost/Schedule.asmx")

        Dim request As HttpWebRequest = WebRequest.Create(url)
        request.Method = "POST"
        request.ContentType = "text/xml; charset=utf-8"
        request.Headers.Add("SOAPAction", "http://tempuri.org/Run")

        Using stream = New MemoryStream()
            Using writer = New StreamWriter(stream, Encoding.UTF8)
                writer.Write(Template)
            End Using
            Dim bytes As Byte() = stream.ToArray()
            request.ContentLength = bytes.Length
            Using output = request.GetRequestStream()
                output.Write(bytes, 0, bytes.Length)
            End Using
        End Using

        Using response As HttpWebResponse = request.GetResponse()
            If response.StatusCode = HttpStatusCode.OK Then
                Console.Write("Success ")
                Console.WriteLine("Please Press Any Key to Exit!")
                Console.Read()
            End If

        End Using
    End Sub

End Class

JKhmerConverter

Leave a comment

JKhmerConverter
is able to convert legacy Khmer font to Khmer Unicode, and Khmer Unicode to legacy Khmer font.
I build this project in order to contribute with open source community in Cambodia, and sharevisionteam.
This project is converted from http://unicode.codeplex.com that built in C# 3.5 t, and due to there is no Khmer Unicode Converter, I have spent my free time to build it up and it’s developed in Java 6.

You can find the binary file and source code file at google code JKhmerConverter
And click here to download download JKhmerConverter

I’m so happy with my first contribute and I hope that it’s my help to society in IT.

Snippet code as below:



/**
 *
 * @author LEE
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        String str = "eRs‘og";
        LegacyToUnicode legacyToUnicode = new LegacyToUnicode();
        System.out.println(legacyToUnicode.convert(str, "Limon S1"));
    }
}

Automatically login to DNN after registration

Leave a comment

Public Sub AutomaticLogin(ByVal userName As String)
Dim objUserInfo As UserInfo = UserController.GetUserByName(PortalId, userName)
UserController.UserLogin(PortalId, objUserInfo, PortalSettings.PortalName, Request.UserHostAddress, False)
Response.Redirect("/Home.aspx")
End Sub
Public Sub AutomaticLogin(ByVal userName As String)

Dim objUserInfo As UserInfo = UserController.GetUserByName(PortalId, userName)

UserController.UserLogin(PortalId, objUserInfo, PortalSettings.PortalName, Request.UserHostAddress, False)

Response.Redirect("/Home.aspx")

End Sub

iPad for every one

Leave a comment

Send email from CSharp with Gmail Account

Leave a comment

string gMailAccount = "chem.leakhina@gmail.com";
            string password = "leakhina*147";
            string to = "chem.leakhina@gmail.com";
            NetworkCredential loginInfo = new NetworkCredential(gMailAccount, password);
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress(gMailAccount);
            msg.To.Add(new MailAddress(to));
            msg.Subject = "subject";
            msg.Body = "message";
            msg.IsBodyHtml = true;
            SmtpClient client = new SmtpClient("smtp.gmail.com");
            client.EnableSsl = true;
            client.UseDefaultCredentials = false;
            client.Credentials = loginInfo;
            client.Send(msg);

Fix error when IIS install after .Net Framework

Leave a comment

Run this command : %Windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i

Generate Color Ramp in Javascript

Leave a comment

  var theColorBegin = 0x632593;
  var theColorEnd = 0xFF7766;
  var theNumSteps = 5;

  theR0 = (theColorBegin & 0xff0000) >> 16;

  theG0 = (theColorBegin & 0x00ff00) >> 8;

  theB0 = (theColorBegin & 0x0000ff) >> 0;

  theR1 = (theColorEnd & 0xff0000) >> 16;

  theG1 = (theColorEnd & 0x00ff00) >> 8;

  theB1 = (theColorEnd & 0x0000ff) >> 0;

  // return the interpolated value between pBegin and pEnd

  function interpolate(pBegin, pEnd, pStep, pMax) {

    if (pBegin < pEnd) {

      return ((pEnd - pBegin) * (pStep / pMax)) + pBegin;

    } else {

      return ((pBegin - pEnd) * (1 - (pStep / pMax))) + pEnd;

    }

  }

  function generateColor(){
    for (i = 0; i <= theNumSteps; i++) {

      theR = interpolate(theR0, theR1, i, theNumSteps);

      theG = interpolate(theG0, theG1, i, theNumSteps);

      theB = interpolate(theB0, theB1, i, theNumSteps);

      theVal = ((( theR << 8 ) |  theG ) << 8 ) | theB;
      console.log(theVal.toString(16));
      }
  }

The result will display as below:
632593
82358a
a14581
c05678
df666f
ff7766

Older Entries

Follow

Get every new post delivered to your Inbox.