Thursday, September 19, 2013

Self Hosting WCF Service

For WCF Self hosting we need to do the following things
1>Create a WCF Service Library
2>Delete the service class and service interface[IService.cs,Service.cs]
3>Delete the service tag from the App.config file.
4>Right click on ServiceApp=>Add New Item=>From the item panel choose Wcf Service
5>Now run the services
5>Create a Console Application to Host the services
6>Add the following code for hosting the services
7>Add the references as service project and System.Servicemodel.
8>Now set the Host application as "Set As Start Up Project".
9>Now create a client to consume the services
10>Add the Service References
11>Now run the client application

How to check Session in WCF
To check the session in WCF we need to do the following things
1>Add the following line in the service class
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
2>Expose a method which increment a value to check the session
3>Now consume the expose method from client

Generated Output

Conclusion
Here for different client proxy instances, value is incremented by one.So from output we can understand at service end for different client proxy new service instance is created but for same client proxy the same service instance is used.

Note:If service is not running properly then we can do one thing. First we need to open the project in two visual studio. In one editor set the Host application as Start Up Project and run it, in other editor set client as Set Up Project and run it.

How to implement Fault Exception in WCF
To implement Fault Exception in WCF we need to first define the fault contract in service contract
Secondly define the service class with Fault Exception

Sunday, January 6, 2013

Create And test WCF Service

1>Create a simple WCF service

 
2>Now Change the service name to the desired service name[Find and replace old service Name with new one]

3>Add the Endpoint of REST & SOAP like following

4>Add the host address.
Host address should be=> http://Domain Name/Service Virtual Directory\n EX:http://localhost/MyService

5>Now addd the EndPoint behaviors for webHttp

6>Now add a Service Method in the interface
Note:Add the "System.ServiceModel.Web" As reference

7>Inherit the service method and defined it in the following way


8>Create a virtual directory say "MyService" and specify the virtual directory path to the WCF Service path

9>Right Click on the WCF Service and Click on Properties. Here Start URL Should be :
http://domain name/Service Virtual Directory/SVC file name/EndPoint Name/URITemplate Name
EX:http://localhost/MyService/MyService.svc/REST/MyAction

9>Specify IIS Home directory path to the WCF Service path

10>So WCF service is now hosted in IIS


11>Now to test the service we need to create a console application
We can call the service asynchronously as well as synchronously
To call the service Synchronously we need to do the following things

To Call the service Asynchronously we need to do the following things

How to Host A WCF Service in IIS server
1>Create A WCF service and set the IIS home directory as the service path

2>Specify the start up url in the IIS location as
http://domain name/Service Virtual Directory/SVC file name/EndPoint Name/URITemplate Name
EX:http://localhost/MyService/MyService.svc/REST/MyAction

3>Create virtual directory and specify the service path as it's path

4>Add the host location in the config file
Note:Here MyService is the created service virtual directory

Service Tag Under <system.serviceModel>

Behavior Tag Under <system.serviceModel>

REST SERVICE ERROR
1>The remote server return an error method not allowed
Sol:This error is generated because of wrong way of method request.Suppose WCF service accept POST request but client request the service method with GET
2>The remote server returned an error: (400) Bad Request
Sol:This error is generated because of wrong type/parameter request.Also if from service end if any error occur then also we get this type of error

How to debugg WCF Service
i)TO debug the WCF service first, we need to host it in IIS
ii)Run the application from where WCF service is consumed.
iii)From Editor navigate to Debugg=>Attach The Process=>Attach the WCF service Process or attach the aspnet_wp.exe
iv)Keep the break point in appropriate position and to go throught the break point press F5

Saturday, May 12, 2012

ORACLE

Optimize Oracle Query
We can optimized/tune a query by following way
EXPLAIN PLAN FOR
SELECT * FROM emp e, dept d WHERE e.deptno = d.deptno AND e.ename = 'SMITH';
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);
The DBMS_XPLAN.DISPLAY function can accept 3 optional parameters
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY('PLAN_TABLE','TSH','BASIC'));
SELECT /*+ FIRST_ROWS(10) */ * FROM employees;=>First 10 rows in employee table

How to bind array in oracle

Oracle Procedure contain Associative Array Call from Dot Net

Looping Associative array In Oracle
******************************************************
    How to Defined an array IN Oracle    ==>
******************************************************

 DECLARE
       TYPE prod_name IS RECORD(product_id varchar2(500),product_desc varchar2(500),product_brand varchar2(500));
type prod_prod_grp_1_assoc is table of prod_name index by binary_integer;
type prod_prod_grp_2_assoc is table of prod_name index by binary_integer;

prod_product_group_1 prod_prod_grp_1_assoc;

BEGIN
   prod_product_group_1(1).product_id := 'ProductID1';
   prod_product_group_1(1).product_desc := 'Product Description';
   prod_product_group_1(1).product_brand := 'Product Brand'; 
   prod_product_group_1(2).product_id := 'ProductID2';
   . . . . . . . . . . . . . . .   
   prod_product_group_1(3).product_id := 'ProductID3';
   . . . . . . . . . . . . . . .
   prod_product_group_1(4).product_id := 'ProductID4';
   . . . . . . . . . . . . . . .
   prod_product_group_1(5).product_id := 'ProductID5';
    . . . . . . . . . . . . . . .
   prod_product_group_1(6).product_id := 'ProductID6';
    . . . . . . . . . . . . . . .

   for i in 1 .. 6 LOOP
       dbms_output.put_line (prod_product_group_1(i).product_id);
       dbms_output.put_line (prod_product_group_1(i).product_desc);
       dbms_output.put_line (prod_product_group_1(i).product_brand);
  END LOOP;
END;

*************************************************
How to defiend procedure in oracle.==>
*************************************************

In the scope of the package defined the t_associative_id

type t_associative_id is table of VARCHAR2(4000) index by binary_integer;

NOTE: Here one thing we need to remember that if we pass associative array as VARCHAR2[i.e => t_associative_id .OracleDbType = OracleDbType.Varchar2;] from .net code then we need to defiened the associative array type as above but if we pass associative array as Number[i.e:=> t_associative_id.OracleDbType = OracleDbType.Int64/Int32;] then we need to defiend the associative array type as following
type t_associative_id is table of Number index by binary_integer;


PART 1:Signature of the procedure
PROCEDURE testExample(v_id IN v_table.v_id%type, v_age IN NUMBER, v_name IN VARCHAR2, v_array_id IN t_associative_id, v_retcode OUT NUMBER, v_reterror OUT VARCHAR2) AS

PART2:Defined variable of the procedure

v_var1 VARCHAR2(50); =>Defiend a varchar type variable. v_var2 NUMBER(5);=>Defiend a number type variable. v_tmp_id v_table.v_id%type;=>Defiened a type which are equivalent to the type of v_id field of v_table table. c_select SYS_REFCURSOR;=>Defiend a cursor. v_query VARCHAR2(1000);
Begin

PART3:Body of the procedure

v_retcode :=0; v_reterror :=NULL;

--Now looping through associative array

FOR I in .. t_associative_id LOOP=>Looping through the associative array.
v_query:=”SELECT fieldval1,filedval2,filedval3 FROM v_table WHERE v_id=”|| t_associative_id (i);

OPEN c_select FOR v_query;=>Looping through the cursor.
LOOP
FETCH c_select
INTO fieldval1,fieldval2,fieldval3;
EXIT WHEN c_select%NOTFOUND;
INSERT INTO t_table(field1,field2,field3)
VALUES(fieldval1,fieldval2,fieldval3);
END LOOP;
END LOOP;
CLOSE c_select;=>Close the cursor.
EXCEPTION
WHEN OTHERS THEN
v_retcode :=SQLCODE;=>Return the exception sql code.
V_reterror :=SQLERRM;=>Return the exception sql message.
ROLLBACK;=>Rollback the transaction.
END testExample=>End the procedure.


How to test the ORACLE PROCEDURE
To test the oracle procedure we need to right click on the procedure and click on the test link. Now we need to pass the parameter value which is required to call the procedure.

We can pass the associative array value in the following way :

t_associative_id (1):='12';=>First array element .
t_associative_id (2) :='23';=>Second array element.
Timestamp Conversion In oracle

1>For converting timezone format
SELECT TO_TIMESTAMP_TZ('2012-02-25 03:15:04.062827 +00:00', 'yyyy-mm-dd HH24:MI:SS.FF6 TZH:TZM') FROM dual;

2>For converting millisecond format SELECT To_timestamp('2012-02-25 03:15:04.062827', 'yyyy-mm-dd HH24:MI:SS.FF6') FROM dual;


For Converting milliseconds format

Oracle Troubleshooting
ora-01031 insufficient privileges while creating a view
1>Open the command prompt and type=>sqlplus / as sysdba
3>grant create view to scott;

ORA-28000: the account is locked
After oracle installation we may get the account locked error.TO resolve this error we need to logging as database administrator and unlock the user account.
1>Open the command prompt and type=>sqlplus / as sysdba
2>alter user scott account unlock;
3>grant connect,resource to scott;
ORACLE Few Required query
select * from dba_all_tables
select * from dba_users
select * from all_objects
select * from V$DATAFILE
select * from V$session
select * from v$
select * from gv$session s
select * from gv$process

How to Use Telerik Control

Telerik control are very useful in web application to make the application more pleasant and good look and feel.To use Telerik control we need to do the following things..

1>First open the visual studio and create a Web Application
2>Now choose the ASP.NET Web Application
3>Now reference the telerik related dll
4>Now register the telerik control
5>Added the script manager right way.Here FIG 1 is the right way and FIG 2 is wrong way..
FIG1

  FIG2  
6>Now check the script manager.
7>Now Add smart tag.
8>Now add the telerik web resource
9>When the telerik web resource is added succefully then we get the following message
10>When telerik web resources added successfully then config file also will be updated.
Telerik Error
If we not provide the design file in web.config then ti will return error.
Solution
We need to add the design file into web.config file.

Error2
Solution
Version Information for ScriptReferenceBase: "Supported in: 3.5 SP1". It's a new class for Service Pack 1. It doesn't exist in .NET 3.5 and the documentation for ScriptReference.So we need to install 2008 Service pack 1 and the problem will be solved.

Saturday, February 25, 2012

How to create windows service & Setup file

Windows service is a service which enable us to create a long running executable application.Sometimes it is needed that one process will be executed in daily basis in that situation we can use windows service.To create a windows service we need to follow the following steps..
1>Create a windows service application by navigating ..
File->New->Project[See FIG-1]
FIG-1

2>Rename the service1 to appropiate service name.

3>Now open the service in design view.
4>Click on properties window.
5>Change the Name and service name property with the desired name.

6>Now open the service in design mode.
7>Right click on the design mode and click on Add Installer.

8>Two file[serviceProcessInstaller1,serviceInstaller] will be created.

9>Right click on serviceProcessInstaller and click on properties and change the account to LocalSysytem.

10>Now right click on serviceInstaller and change the SratType Property to Automatic and DisplayName to Service name

Now to create the setup file we need to follow the following steps..
1>Create a setup project in the same solution.

2>We can see Output file system structure by navigating the steps
Right CLick on Setup Project->View->File Sysytem

3>From the File system structure right click on the Application Folder->
Add->Project Output-Select Primary output->OK

4>Rightclick on set up project->View->Custom Action

5>In custom action interface Right click on Install->Add Custom Action
->Double click on application folder->Select The Primary output file

6>DO the step 5 for Uninstall
In custom action interface Right click on Uninstall->Add Custom Action
->Double click on application folder->Select The Primary output file
7>Open the ProjectInstaller.cs and add following line

8>Now build the project and build the set up project
Now Add code to test the service.
1>Open the service by right click on it and select view code.

2>Add the following code to test the service.
3>Right click on setup->Install->Specify Install Directory->Next->Service will be install into the windows service
4>To view the service RUN->Type->Services.msc
we can find our service

Saturday, November 5, 2011

SSIS Lookup Control Implementation

SSIS CONTROL EXPLANATION
SSIS[SQL Server Integration Services] Brief:
To work with SSIS we need to install SQL Server Business Intelligence Development studio.
When we open a package in the BIDS tool we get 3 tabs.
i)Control Flow.ii)Data Flow.iii)Event Handler.
In Control Flow section we do some control operation like Execute Task,Data Flow task,Foreachloop Container and so on and In Data Flow control we do data conversion,data transformation,data manipulation .

Here in the following I have demonstrate how to use Lookup control.
1>First take a Execute SQL Task in Control Flow tab.
2>Right click on the interface to add variable.

3>Right click on the Execute SQL Task. Select the connection. Select the source type. Here we can Put direct input as well as variable .In case of variable point the variable from the drop down.

4>Take a Data Flow task. Double click on it Data Flow control tab open.
5>In Data Flow control take a Excell Source. Right click on it and add the connection manager.

6> Select Colum from the left navigation. Select those column which we want to pass.

7>Now take a Data Conversion control. Right click on it and specify the destination data type.If Destination data type is varchar then it will be string[DT_STR]]
8>Now take a Lookup control select General. Specify Cache Mode as No Cache and Redirects Rows to match output.

9>Select Connection tab from left navigation. Specify the connection manager and chose the table on which the lookup will be perform.
10>Select Columns from the left navigation and specify which field are taken place for lookup comparison.

11>Now from the lookup control one destination is taken for match rows and another destination is Taken for unmatched rows.

12>In the above picture two derived column is taken. One derived column is taken to specify data conversion error and another is taken to specify data conversion error. One Union ALL control is taken Which accumulate all the error and sent to a flat file destination .

Saturday, September 10, 2011

Page Life Cycle

Here I have listed how the event is fire in page life cycle
OnInit Event Fire On a Page Life Cycle
i) Master Page User Control-init
ii) Page User COntrol-init
iii)Master Page -init
iv) Page - init

Page Load Event Fire On A Page life Cycle.
i) Page -Load
ii) Master Page-Load
iii)Page User Control - Load
iv) Master page User COntrol - Load

Data Binding Event Fire On A Page Life Cycle
i) Page - DataBinding
ii) Master Page - DataBinding
iii)Page User Control - Data Binding
iv) Master Page User COntrol - DataBinding

Unload Event Fire On A Page life Cycle
i) Master Page User Control-Unload
ii) Page User Control-Unload
iii)Master Page -Unload
iv) Page - Unload

A pictorial Presentation Of page life Cycle