Wednesday 23 January 2013

Minimal web.config for WCF web service in .Net 4.0

Getting correct configuration for running WCF is important, and I am used to mess with ABCs of WCF web service.
I struggled a lot to get this minimal configuration for web.config and finally I got a working solution. Hope this works for everyone.

<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <!--
            The <authentication> section enables configuration 
            of the security authentication mode used by 
            ASP.NET to identify an incoming user. 
        -->
    <authentication mode="Windows"/>
  </system.web>
  <system.serviceModel>
    <bindings>
    </bindings>
    <services>
      <service name="MyProject.Service">
        <endpoint address="" behaviorConfiguration="webHttp" binding="webHttpBinding"
          contract="MyProject.IService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="webHttp">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

Tuesday 15 January 2013

Upload file from device to server using PhoneGap

I have implemented this in Android and it works really well. You may need to customize client side implementation little as per you requirement and it should work fine.
Since we dont have file structure in iPhone, I am not sure how to implement it in iPhone.

 1. Client(device) side implementation
PhoneGap provides file transfer API to transfer file to server, PHP is recommended for server implementation.

function uploadFile() {
   window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) {
   var directoryReader = fs.root.createReader();
   directoryReader.readEntries(function(entries) {
   imageURI=entries[0].toURI(); // Selected File path
   var options = new FileUploadOptions();
   options.chunkedMode = false;
   options.fileKey="file";
   options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
   alert(options.fileName);
   options.mimeType="text/plain";
   var params = new Object();
   params.value1 = "test";
   params.value2 = "param";
   options.params = params;
   var ft = new FileTransfer();
   ft.upload(imageURI, "ServerIP/Upload.php", win, fail, options,true);
   }, function (error) {
      alert(error.code);
   })}, function (error) {
      alert(error.code);
   });
}

function win(r) {
   alert("success");
   alert("Sent = " + r.bytesSent);
}

function fail(error) {
   alert("error");
   switch (error.code) {
     case FileTransferError.FILE_NOT_FOUND_ERR:
        alert("Photo file not found");
        break;
     case FileTransferError.INVALID_URL_ERR:
       alert("Bad Photo URL");
       break;
     case FileTransferError.CONNECTION_ERR:
       alert("Connection error");
       break;
   }
   alert("An error has occurred: Code = " + error.code);
}

2. Server side implementation
Create a php page(Upload.php) and host it in IIS

<?php
if ($_FILES["file"]["error"] > 0) {
  echo "Return Code: " . $_FILES["file"]["error"] . "";
} else {
  echo "Upload: " . $_FILES["file"]["name"] . "";
  echo "Type: " . $_FILES["file"]["type"] . "";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb";
  echo "Temp file: " . $_FILES["file"]["tmp_name"] . "";
  if (file_exists("D:/PHPUPLOAD/" . $_FILES["file"]["name"])) {
    echo $_FILES["file"]["name"] . " already exists. ";
  } else {
    move_uploaded_file($_FILES["file"]["tmp_name"], "C:/PHPUPLOAD/" . $_FILES["file"]["name"]); //Save location
    echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
  }
}
?>
For example: Create a php file(Upload.php) at – C:\inetpub\wwwroot

Saturday 5 January 2013

THE RIGHT TO INFORMATION ACT, 2005

Today, I am fed up of BSNL service(I am receiving phone bills from past five months without having a connection ) and I am going to file a RTI for it, and therefor thought that it will be useful for others if I document the procedure of filing RTI. Simply because the more people know about RTI and actively use it, the more each one of us are doing our bit to curb corruption and wrong practices in Government Department. 
In simple words, the Right to Information Act or RTI is an act that practically supports and enables citizens to claim their right to information which is guaranteed by the constitution of India.

Below is the step by step systematic procedure to file RTI application correctly -

1. First you need to get the Information about the concerned public authority who is known as PIO (Public Information Officer ), every organization has a PIO and their address can be found on their website.If you do not get details of PIO at their website or PORTAL just visit the nearest office of the relevant organization or public authority and get the address of PIO.

2. Write an application with “Subject: Application under the RTI Act, 2005” . Mention your query point-wise. Find sample RTI Applications for various problems here.

3. There is a nominal fees of Rs 10 for filing RTI which can be through Postal Order/ CRF or by Bank Draft. It should be in favor of Accounts Officer of particular organization. For example, if RTI for SBI Bank, it should be Accounts Officer, SBI payable at location of concerned department of PIO. For my case, it was BSNL. I paid the fees through postal order which can be easily purchased from any post office. It should look something like below -


4. You may send it by any mean like post, speed post etc. but not by courier. I prefer registered post.

5. You must sign the application form.

6. Finally Acknowledgement: All RTI applications have to be answered in 30 days by respected PIO or Organization.One need to preserve the application number and date of filing or photocopies for future reference.

Get you basic questions answered here. For more information refer RTI GUIDE / HANDBOOKS.

Exercise your Right to Information now!