Saturday, May 28, 2011

Can we static methods/class can implement Interface

No, Method of interface cannot be implemented as a static methods because Methods specified on an interface should be there to specify the contract for interacting with an object. Static methods do not allow you to interact with an object - if you find yourself in the position where your implementation could be made static, you may need to ask yourself if that method really belongs in the interface.

The core design principle of static methods, the principle that gives them their name...[is]...it can always be determined exactly, at compile time, what method will be called. That is, the method can be resolved solely by static analysis of the code

Interfaces specify behavior of an object.

Static methods do not specify a behavior of an object, but behavior that affects an object in some way.

Compiled By: Rajesh Rolen

Read More

Thursday, May 26, 2011

Setup .NET Framework 4.0 on IIS 6

Steps to setup .NET Framework 4.0 on IIS 6 without effecting any existing website of lower version.


- Install framework asp.net 4.0 and restart [Web Platform Installer does it just fine]

- IIS 6.0 console should now display ASP.NET 4.0 under tab “ASP.NET” [It was again done if #1 above is right]

- Under Web Services Extensions (in IIS console) .NET 4.0 framework might be set as: prohibited. This must be ALLOWED otherwise a browser might just return the error 404 page not found which is not very descriptive

- ASP.NET 4.0 applications must be run in a separate process (Application Pool) otherwise you’ll get the error ‘Server Application Unavailable’.

Steps to setup separate application pool for .NET Framework 4.0
- First of all setup website/virtual directory for your website
- Under IIS right click on “Application Pools” and select new -> application pool
- It will open a dialog box. Enter application pool id in it and click ok.
- Now Right click on website/virtual directory and select properties
- Go to “asp.net” tab and select asp.net version to 4.0
- Now go to “Home Directory” tab and select your newly created application pool in application pool dropdown.
- Click on apply and OK.
- New reset IIS and its done.

If you still getting error then try this:
- Open command prompt
- Go to c:\windows\Microsoft.net\Framework\v4.0.30319
- Run command: aspnet_regiis –i

If you encounter any error related to missing of any namespace or dll then copy desired dll in “Bin” folder of you application.
If you are not able to download/find that particular dll then follow below steps to get.
- Open you project in visual studio
- In “solution explorer” go to “references” folder
- Here you can see all namespaces/dlls which your project is referring.
- Select the desired namespace/dll and press “F4” or go to its properties
- Set its property “Local Copy” to True and rebuild project.
- And its done. Now the copy of that namespace/dll will be copied to “Bin” folder of project.
-

Compiled By: Rajesh Rolen

Read More

Tuesday, May 24, 2011

Bind TreeView in Asp.NET

Using below code you can bind/show treeview in asp.net

for stored procedure: http://dotnetacademy.blogspot.com/2011/05/get-all-child-nodes-of-parent-in-self.html


 private void buildTree()
        {
            List cml;
            cml = cmf.GetAll();
            TVcategory.Nodes.Clear();
            AddNodes(0, TVcategory.Nodes, cml);
        }
        void AddNodes(int id, TreeNodeCollection tn, List cml)
        {

            foreach (Categorymaster cm in cml.Where(s => s.Parentid == id))
            {
                //TreeNode sub = new TreeNode("" + cm.Category_name + "", cm.Category_id.ToString());
                TreeNode sub = createTree(cm);
                tn.Add(sub);
                AddNodes(Convert.ToInt32(sub.Value), sub.ChildNodes, cml);
            }
        }
        private TreeNode createTree(Categorymaster cm)
        {


            TreeNode tn = new TreeNode("" + cm.Category_name + "", cm.Category_id.ToString());

            if (catid > 0)
            {
                if (cm.Category_id == catid)
                {
                    tn.Selected = true;
                }

            }

            return tn;

        }

Read More

Tuesday, May 17, 2011

Test Your webservice/WCF service in Network


Today i found a interesting solution for an interesting problem.

i have created a WCF service in .NET Framework 3.5 to be used by PHP developers.
We have decided to test the service before going forward, for that we have planned to launch it on web servers but, i found there was 2.0 framework installed on my web server and my service is built on framework 3.5 (it was not good time to play with web server). So i decided to expose my WCF service from my system only. To do so i setup it on my local server on port 70. but it was not available from other computers on network. So i got a trick to solved this problem.

Solution:
- I downloaded Microsoft SOAP Toolkit version 3 and started MSSoapT (Trace Utility),
then i created a formatted trace listening on port 8080
to do so, i gone throw these steps:
-- File->New->Formatted Trace. it opened a dialog box and i filled the following values in it.
-- Local port= 8080
-- in forward to section, Destination Host= 127.0.0.1 (remove text localhost)
-- port = 70 (my WCF service port number).

Now click ok and its DONE... :)
now every one from my LAN can use this service by url like http://MySystemIP:8080/myservicename.svc

So what we have done is we have used port forwarding technique to expose our WCF services in network. so when user will access port 8080, the request will be forwarded to my service's port 70.


Compiled By: Rajesh Rolen

Read More

Monday, May 16, 2011

Setup WCF services on IIS

To setup WCF services on IIS, Please follow below steps:

- If you have not registered script map then register it
- open command prompt with administrative rights.
- move to folder in command prompt: "%windir%\Microsoft.NET\Framework\v3.0\Windows Communication Foundation"
- run : ServiceModelReg.exe -i

- in RUN type "inetmgr" and press enter to open iis manager.


- now go to sites->default web site.
- Right click on "default web site", click on "add application" and fill required details.
- now right click on your application under "default web site" and click on "edit permission".
- in "edit permission" dialog box go to "security" tab and check that there must exists a user "\IIS_IUSER" with read permission.
- if IIS_USER not exists there then click on "add" and add "\IIS_IUSER" and provide it read permission.

its DONE..

Compiled By: Rajesh Rolen


References:
http://www.geekzone.co.nz/vs2008/4653

http://int.social.msdn.microsoft.com/Forums/en-GB/wcf/thread/e5b30d8b-beec-4ce3-86ee-dc49b715b97d

http://social.msdn.microsoft.com/Forums/en/adodotnetdataservices/thread/f447c6df-6402-4a13-875c-925445fd7be8
Read More

Wednesday, May 11, 2011

Get all child nodes of parent in self join table Tree and vice versa

Lets say we have a table with fileds "category_id, category_name, parentid" now we wants to retrieve all child nodes of specific node then below query will help you.

;WITH Descendants AS (
 SELECT  p.category_name
                , p.category_id
                , 0 AS HLevel
 FROM dbo.categorymaster p  
 WHERE category_id = '7'
 UNION ALL
 SELECT p.category_name
                , p.category_id
                , H.HLevel+1
 FROM dbo.categorymaster p  
 INNER JOIN Descendants H
 ON H.category_id=p.parentid  
)  
SELECT category_id, REPLICATE('     ', Hlevel) + category_name AS category_name
FROM Descendants d



To get all ancestors of a node:

;WITH Ancestors
AS 
( 
 SELECT  p.category_name
  , p.category_id
  , parentid
  , 1 AS HLevel
 FROM dbo.categorymaster p  
 WHERE category_id = 9
 UNION ALL
 SELECT p.category_name
  , p.category_id
  , p.parentid
  , H.HLevel+1
 FROM dbo.categorymaster p  
 INNER JOIN Ancestors H
 ON H.parentid=p.category_id  
)  
SELECT category_name, category_id, HLevel
FROM Ancestors c 

References:

http://jsimonbi.wordpress.com/2011/01/14/sql-hierarchies-parent-child/
http://dev.mysql.com/tech-resources/articles/hierarchical-data.html
Read More

Thursday, May 5, 2011

Write xml text on aspx page

you can use below code to write xml file data (string) on page.

first of all remove all content from aspx page except "page" directive.

 XmlDocument doc = new XmlDocument();
 doc.LoadXml(stringxml);
 Response.Clear(); //optional: if we've sent anything before
Response.ContentType = "text/xml"; //must be 'text/xml'
Response.ContentEncoding = System.Text.Encoding.UTF8; //we'd like UTF-8
doc.Save(Response.Output); //save to the text-writer 
Response.End(); 
Read More

Tuesday, May 3, 2011

Send email outside network/organization through MS-Exchange using asp.net

You can use below code to send email using Microsoft Exchange server outside the organization (email address other then current organization)

private void Page_Load(object sender, System.EventArgs e)
{
 MailMessage mail = new MailMessage();
 mail.To = "me@mycompany.com";
 mail.From = "you@yourcompany.com";
 mail.Subject = "this is a test email.";
 mail.Body = "Some text goes here";
 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "my_username_here"); //set your username here
 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "super_secret"); //set your password here

 SmtpMail.SmtpServer = "mail.mycompany.com";  //your real server goes here
 SmtpMail.Send( mail );
}
Read More
Powered By Blogger · Designed By Seo Blogger Templates