asp.net,ajax,wcf,c#,vb,wwf

Monday, February 15, 2010

Protection against message reply attack in WCF

Reply attach occurs when attacker copies a stream of message from 2 parties. To avoid this we need to use CustomBinding.



I hope you people like this article.

Sunday, February 14, 2010

Ajax Enabled WCF Service

Introduction

        In this article, we are going to see how to use Ajax Enabled WCF Service in a website. Let us go through this application Step by Step.


Step1:


       Open VS2008->create new website->name it->Right click on the website->Add new item ->Select Ajax Enabled WCF Service->name it as Service.svc which is by default at the first instance.



 


Step2:


     Now lets write simple lines of code in service.cs class which is located in App_code folder.




using System;


using System.Linq;


using System.Runtime.Serialization;


using System.ServiceModel;


using System.ServiceModel.Activation;


using System.ServiceModel.Web;


[ServiceContract(Namespace = "")]


[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]


public class Service


{


// Add [WebGet] attribute to use HTTP GET


[OperationContract]


public string HelloWorld()


{


// Add your operation implementation here


return "Hello World";


}


// Add more operations here and mark them with [OperationContract]


}


This HelloWorld method just returns simple string value as HelloWorld.


 


Step3:


       Now lets go to Default.aspx->Add new ScriptManger->give service reference to Service.svc


      


Here we added html button and a span. Click on the html button automatically it will script tag.


<script language="javascript" type="text/javascript">


function Button1_onclick() {


}


</script>


Within the Button1_onclick function writes these lines


<script language="javascript" type="text/javascript">


// <!CDATA[


function Button1_onclick() {


Service.HelloWorld(onsuccess,onfailed,"Hello world example");


}


function onsuccess(results)


{


message.innerHTML=results;


}


function onfailed(results)


{


message.innerHTML=results;


}


// ]]>


</script>


 


Step4:


       Now lets go to the Web.config file. By default only WebHttpBinding has been created.so We are suppose to add metadata, in this case it is mexHttpBinding.


  


 


I hope you people like this article.




 

Thursday, February 11, 2010

Creating Multiple Channels in Channel factory in WCF

Introduction

     The channelFactory class is useful when you want share a common service contract dll between the client and the server. In this post I will show how to create a ChannelFactory implementation with message header using WCF.


     Let us go through this application step by step


 


Step1:


        Create a new class Library project->give the name as Interface


 


Step2:


        In this class library project give the reference to System.ServiceModel.


Step3:


      


     Its a simple peace of code which consists of Service contract and operation contract.


 


Step4:


        Now create a console application->name it as service->create a class called EchoService.cs-> give a reference to System.ServiceModel and Interface Class Library.


 


Step5:


      


We get the Guid value in the message header. It takes 2 paramater one as LocalName of the XML header and another as a namespace of the XML.


 


Step6:


      Now lets go to our Program.cs file and write the service hosting.


     


Here we are using binding as WSHttpBinding and the endpoint address as http://localhost:8080/Echo.


Just build the application and see if there are any errors.


 


Step7:


    Now create one more Console app->name it as client->give the reference to System.ServiceModel and Interface Class Library.


   


 


In this interface we have given reference to IEchoService and IClientChannel.


 IClientChannel->It defines the behaviour of oubound request and reply channel used by client app.



 


Here we are creating the object for channel factory using wshttp binding. After that we are creating the channel using endpoint address http://localhost:8080/Echo. After that we are creating the Guid and then the Guid value has been added in MessageHeader.


 


Step8:


    Lets run the application and see the result.


 


     I hope you people like this article.

Wednesday, February 10, 2010

List of my articles

I have written these articles in dotnetfunda website. Go through these
http://www.dotnetfunda.com/profile/Anup1252000.aspx

Sunday, December 6, 2009

Getting the users login date and time in forms authentication

In this article we are going to see how to get the users login date and time. Go through these methods

Method 1: Through user ticket



Method 2: Membership Provider


Wednesday, November 18, 2009

Ajax is slow in Production server


We need to add these lines in Production Server

Monday, July 27, 2009

Check whether the user exist or not in webservice

In this article we are going to see if the user exist or not in webservices. There are many approach to do so.. we can create this by using XMLHTTP request or callback event handler and so on.. As you people know webservices are the most familiar approach to do so.. In this application we are going to check whether this user exist in asp.net builtin membership.. First you need to add some users in order to check this application..

Let us start by building this application..

Step1: open vs>File>New Website>give the name and click ok..

Step2: Right click on your website and click on webservices and give its name..

Step3: In the webservices uncomment this line
[System.Web.Script.Services.ScriptService]..
we need to uncomment this line in order to use ajax application on your page..

Step4:
Now give the webservice method name as usernameexist.. Write these lines of code


In this we are passing username.. As you might guess from the code that we are returning MembershipUser..

Step5:
Now open the Default.aspx page and add the ScriptManager on to the page and give the service reference to your web service.. write these lines of code..



In my case webservice name is WebService3.asmx and it will be differnt in your code..

Step6:
Now add the asp.net TextBox and the Html button on to your page.. And one more thing place the paragraph in order to store our message..



And double click on to the button..

Step7:
After double clicking We need to call the Webservice.. We need to write these lines of code



In this case first we are giving reference to Textbox by using a variable called text.. Then we need to call the webservice by adding the [classname].[webmethodname] and need to pass the parameters.. We are using onsuccess when that webservice got successed, onfailed for failure and the usercontext as "user exist".. We gave the reference to the paragraphid user by using a variable called span.. Now its a time to test your application..

I hope you like this Article..