Tuesday, February 18, 2014

Enable copy & right -click in a webpage that is copy protected.

Many a times when we visit a webpage and try to copy some content from the page ,we are unable to copy that content. There are two possibilities that you are unable to copy.
1)Webpage has disabled the right click of the webpage.
2)The webpage has disabled select of the webpage.
Now here is the solution to these scripts .

For enabling right click just copy the below script and paste it in browser url of the same page

javascript:void(document.oncontextmenu=null)

For enabling copy just copy the below script and paste in browser url of same page


javascript:void(document.onselectstart=true)

Monday, February 17, 2014

WCF Web HTTP Service Help Page and Show Exception Detail when calling methods of WCF Service

WCF Help Page:

This functionality is turned off by default. When a user browses to a WCF WEB HTTP service and appends "/Help" on to the end of the a help page like the following is displayed.
The user can then click any method listed in the help page and detailed page for that operation is displayed showing more information about the method, including message formats and example responses. To enable the WCF WEB HTTP Help age in configuration, add an endpoint behavior with a <webhttp>  element, set enableHelp to true.


      <endpointBehaviors>

        <behavior name="Jsonbehavior">

          <webHttp helpEnabled="true" />

        </behavior>

      </endpointBehaviors>


Show Errors in WCF:

To show exact error in WCF Hosted on IIS we need to set service debug includeExceptionDetailInFaults attribute to true.
    <behavior name="Service1">

                    <dataContractSerializer maxItemsInObjectGraph="2147483646" />

          <serviceMetadata httpGetEnabled="true" />

          <serviceDebug includeExceptionDetailInFaults="true" />



        </behavior>


Friday, February 14, 2014

Working with JSON in c# using using Newtonsoft.Json

JSON stands for "Java Script Object Notation".
JSON you need a lightweight, open, text-based platform independent data exchange format for transferring data back and forth between the client and server. Although XML works well for many application scenarios but it has an extra payload that is XML tags.So to overcome this drawback ,JSON was introduced.
 In this example i will be using a library to access a WCF Rest Service using Newtonsoft.json.dll.
Here is the simple code to access a JSON array Response in c#
Just include Newtonsoft.Json and Newtonsoft.Json.Linq namespaces

Code:


 
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Net;

using System.Web.Script.Serialization;

using System.Net.Json;

using System.IO;

using Newtonsoft.Json;

using Newtonsoft.Json.Linq;

using Jsonparse;

 namespace Jsonparse

 {

 class Program

 {

 static void Main(string[] args)

 {

 WebClient c = new WebClient();

var data=c.DownloadString("http://localhost:50766/Service1.svc/json/GetDispatchOrders");

//ordtrnh is my custom class declared in Jsonparse namespace

 List

myDeserializedObjList = (List)Newtonsoft.Json.JsonConvert.DeserializeObject(data, typeof(List));

 foreach(ordtrnh o in myDeserializedObjList) 

 { 

 Console.WriteLine("Customer Id is {0}",o.custid); 

 Console.WriteLine("Order Date is {0}", o.orddate);

 Console.WriteLine("Customer Area is {0}", o.parea); 

Console.WriteLine("----------------------------------------------");

 } 

 Console.ReadLine(); 

 } 

 } 

}
Output:
You can download newtonsoft.json.dll from   Here

Wednesday, February 12, 2014

The maximum message size quota for incoming messages (65536) has been exceeded.(Error in WCF Test Client)

Sometimes when we invoke a method in WCF Test Client we get an error even though same restfull service when invoked in browser works fine.In WCF Test Client we are likely to get an error

"The maximum message size quota for incoming messages (65536) has been exceeded" after using the WCF Test Client utility to invoke a method on my service." 

There is nothing wrong with the service this is just the configuration change in WCF Test Client. In the wcf test client, after you add the service, you can notice there is a "config file" node at the end of the service tree: right click it and select "edit with SvcConfigEditor". You will get the exact configuration editor for the service side - just go to the binding settings and change the MaxReceivedMessageSize and save the changes.

Just put these values

maxBufferSize=”2147483647″
maxReceivedMessageSize=”2147483647″

Authentication issues in WCF(IntegratedWindowsAuthentication, Anonymous', but the binding only supports specification of exactly one authentication scheme. Valid authentication schemes are Digest, Negotiate, NTLM, Basic, or Anonymous.) on remote server

While hosting your Restful WCF Service on shared hosting you are more likely to get the error

IIS specified authentication schemes 'IntegratedWindowsAuthentication, Anonymous', but the binding only supports specification of exactly one authentication scheme. Valid authentication schemes are Digest, Negotiate, NTLM, Basic, or Anonymous. Change the IIS settings so that only a single authentication scheme is used.

To overcome this error we have to make a small change in our web.config file as
<system.servicemodel="">
    <bindings>
      <webhttpbinding>
        <binding>
          <security mode="None">
            <transport clientcredentialtype="Windows">
          </transport></security>
        </binding>
      </webhttpbinding>
    </bindings>
  </system>



This will disable security of your service & your service doesn't need authentication

Thursday, February 6, 2014

Difference between dll and exe

One of the most common interview questions asked by a window developer is

Difference between exe and dll

1.EXE is an extension used for executable files while DLL is the extension for a dynamic link library. 2.An EXE file can be run independently while a DLL is used by other applications. 3.An EXE file defines an entry point while a DLL does not. 4.A DLL file can be reused by other applications while an EXE cannot. 5.A DLL would share the same process and memory space of the calling application while an EXE creates its separate process and memory space. (The DLL is an inprocess component but exe is outprocess component. When system launches an exe, a new process is created , for DLL a new process is not created).