Tuesday, October 18, 2011

PowerShell: Script to Create a Website

//enable run script in PowerShell
Set-ExecutionPolicy RemoteSigned

//import module
Import-Module WebAdministration

//create a application pool
New-WebAppPool testpool
Set-ItemProperty iis:\AppPools\testpool -name processModel -value @{username="administrator";password="password";identitytype=3}
Set-ItemProperty iis:\AppPools\testpool -name managedRuntimeVersion -value v4.0

//create a web site
New-Item iis:\sites\testSite -physicalpath "C:\Users\WebSite" -bindings @{protocol="http";bindingInformation=":8083:"} -ApplicationPool testPool
$website = get-item iis:\sites\testSite
$website.virtualDirectoryDefaults.userName="administrator"
$website.virtualDirectoryDefaults.password="password"
$website | set-item 

Monday, October 17, 2011

PowerShell: Get-Service -Name "MSSQL$SQLEXPRESS"

You can use "get-service" command to get current status of the service.

But, when I execute the following command in PowerShell:

   Get-Service -Name "MSSQL$SQLEXPRESS"

There is an error found below:

  Get-Service : Cannot find any service with service name 'MSSQL'.
  At line:1 char:12
  + Get-Service <<<< -Name "MSSQL$SQLEXPRESS"

The solution is: using "*" instead of "$"

Tuesday, September 20, 2011

WCF: enable rest operation

I need to call a WCF service through Get, Put and Post operation. And there are some settings needed  in the service contract and web.config.

Methods can be called  through the following URL:

http://ip/sitename/Service1.svc/user/post/{value}

For service contract:
 [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        [WebGet(UriTemplate = "?value={value}")]
        string GetData(int value);
        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "post/{value}")]
        string PostData(String value);
        [OperationContract]
        [WebInvoke(Method = "PUT", UriTemplate = "put/{value}")]
        string PutData(string value);
    }
For web.config:

      
          
              
              
              
          
      
     
        
            
                
            
        
        
        
          
          
        
      
    
    
  

SSH SCP put command workflow: unable to put file

I run the default SCP put command workflow in the orchestrator and the workflow finishes without any error code. But I cannot find the file in the destination.

In the API Explorer, I do some searching. I discover the description of SSHSession which is used to replace SSHCommand.



//original code
var sshCmd = new SSHCommand(ip,username,password) ;
sshCmd.putFile("C:\\orchestrator\\hoho", "//") + "||");
var error = sshCmd.getError() ;
sshCmd.disconnect();


//updated code
var sshSession = new SSHSession(ip,username);
sshSession.connectWithPassword(password);
sshSession.putFile("C:\\orchestrator\\hoho", "hoho");
sshSession.disconnect();

Saturday, July 16, 2011

Linux: loopback address

I run a java application under Linux environment and it throw an exception.

"Server failed to start: java.rmi.RemoteException: Cannot start. localhost.localdomain is a loopback address"

The problem seems related to the host file (\etc\hosts) and its content is shown below:

127.0.0.1 localhost.localdomain localhost
::1 localhost






After the configuration, everything works fine.

Thursday, July 14, 2011

OleDbConnection: insert a parameter into a query

I want to create a OleDbConnection to a excel file and create a parameterized query. An example from msdn is shown below:

string queryString = "SELECT * FROM Table1 WHERE Field1 LIKE ?";
OleDbCommand command = new OleDbCommand(queryString, connection);
command.Parameters.Add("@p1", OleDbType.Char, 3).Value = "a";
OleDbDataReader reader = command.ExecuteReader();

For your reference:
http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbparameter.aspx
http://blogs.msdn.com/b/wriju/archive/2008/01/24/ado-net-oledbcommand-parameterized-query-sequence-rule.aspx

Wednesday, June 29, 2011

JMeter: Distributed Test

I want to set up a distributed testing in my network. Then, I prepare a new vm and configure the settings. You can follow the instruction in the link below:



After the configuration, I run the ApacheJMeter.jar as normal. The next step, I click Run=>Remote Start=>127.0.0.1 and an error message is popped up: 

"Connection refused to host: 127.0.0.1;nested exception is: java.net.ConnectException: Connection refused: connect"


After my investigation, I discover something which can explain above message. If you clcik Run=>Start, the application functions fine. If you click Run=>Remote Start=>127.0.0.1, please run jmeter-server.bat. It is because the application treat the localhost as one of the slaves. 

Everything works fine when I run this bat file.