Custom Search

Friday, August 15, 2008

Create WCF Service with TCP Binding

Hey guys,
Lets start with creating a simple WCF(Windows Communication Foundation) Service with TCP binding.

Environment i'm using:
>Windows server 2008
>Visual Studio 2008
>> Language: C#
>IIS 7.0

Lets start with small application using Service, Client & Library projects under single solution.
Putting stuff in library project just because of broad understanding of WCF & its features. So, lets have little idea about what/how we are gonna do this task.

Start with project 'Library', which will have all the contracts & business logic. Project 'Service' will have services(.svc) & configuration files which will points to library for consuming contracts.

Project 'Client' is the consumer, who will consume the WAS hosted services.
Project 'Provider' is the service provider, eventually a WAS hosted service using IIS 7.0. Later on, we will discuss self hosted WAS services in detail.

So Lets begin with Contracts & business logic under Library project [C#>Windows>Class Library]:

> Rename Class1.cs as SampleService.cs
> Add new item as ISampleContract.cs
> Add new item as Customer.cs
> Add reference of System.Runtime.Serialization.Dll
> Add reference of System.ServiceModel

Lets take a look towards Customer.cs code which, we will use for DataMember & DataContract declaration

Customer.cs:

using System;
using System.Runtime.Serialization;
using System.ServiceModel;

namespace Library
{
[Serializable]
[DataContract]
public class Customer
{
public Customer() { }

[DataMember]
public int CutomerID;

[DataMember]
public string CustomerName;

[DataMember]
public string CustomerAddress;


public int GetCustomerID(string customerName)
{
//Code snippet which get data from database
CutomerID = 10;
return CutomerID;
}

public string GetCustomerName(string custromerID)
{
//Code snippet which get data from database
CustomerName = "Hello Customer";
CustomerAddress = "Customer Address";

return CustomerName;
}
}
}



I declared class as 'Serializable' which, we will discuss later.

ISampleService.cs:
SampleService.cs

to be Continued....







Wednesday, August 13, 2008

Enable Java Script in IE

Hey Guys, here is the simple solution to enable the java script in IE (Internet Explorer) when your IE's Internet Option > Security > Custom Level is grayed out [Disabled].

I tried it on Windows Server 2008, it may work for Vista

> Open 'Run' window.
> Type 'gpedit.msc' [Hit Enter]
> It will open an editor to configure Local Group Policy
> Now out of two categories [Computer Configuration & User Configuration], Click on User
Configuration
> Click on 'Windows Settings' > 'Internet Explorer Maintenance' > 'Security'
> Under 'Security', Right click on 'Security Zones and Content Ratings' & click on 'Properties'
> It will open a new window, where select 'Import the current security zones and privacy
settings' under 'security zones and privacy'.
> It will open a new window called 'Internet Explorer Enhanced Security Configuration' > Click
on 'Continue' button
> Click on 'Apply' > 'OK'

You are done!!!
Suggestions are always welcome...No need to login :)

Tuesday, August 12, 2008

WAS Hosting with TCP Binding

Hello Everybody,
Today, i'm trying my hands on hosting services on WAS(Windows Activation Services) using TCP binding.

Environment
i am using:

>
Windows Server 2008 [you can use Vista]
>
IIS 7.0
>
Visual Studio 2008

Let's start with very first step, load environment with some ammunition to make services run under WAS.

1. Run window > "inetmgr" [Open IIS 7.0]
2. Under localhost
2.1 Sites> Default Web Site.
2.2 Right Click on 'Default Web Site', Select Edit Binding.
2.3 Click on 'Add' button, Select Type = 'net.tcp' & Binding Information = 808:*

{{{

There is an alternative way to update Bindings on 'Default Web Site' under IIS. i.e.,
Open Adminstrator command prompt & Run following command to add:

a.
%windir%\system32\inetsrv\appcmd.exe set site "Default Web Site" -+bindings.[protocol='net.tcp',bindingInformation='808:*']

b.
%windir%\system32\inetsrv\appcmd.exe set app "Default Web Site/servicemodelsamples" /enabledProtocols:http,net.tcp

You can remove using following command:

a.
%windir%\system32\inetsrv\appcmd.exe set app "Default Web Site/servicemodelsamples" /enabledProtocols:http

b.
%windir%\system32\inetsrv\appcmd.exe set site "Default Web Site" --bindings.[protocol='net.tcp',bindingInformation='808:*']

}}}

[Back to hosting sequence]
2.4 Make sure that [windows] user, who is gonna use service has got enough permission
to access it. Right Click on 'Default Web Site' >> Click on 'Edit Permissions...' >> Select
'Security' tab >> choose appropriate user & set[Edit] his/her permission.

Now, host your service on WAS....

3.
Right Click on 'Default Web Site' >> Click on 'Add Application...' >> Write proper name for
'Alias' field [typically it should be the name of service] >> give proper 'Physical path:' of
service.
3.1 Before pressing 'OK' button, Test the setting by 'Test Settings..' button. It will show you the
'Authorization' & 'Authentication' test result. If anything fails, it must be because of not
enough permission to current user. In that case, try to connect with different user using
'Connect as..' option in 'Add Application window'.

This process will create one new virtual folder under 'Sites' >>'Default Web Site' & that will be the Alias name you provided before.
now,
4. Right click on that newly created folder, & set the permission using 'Edit Permission' if in case
required.
5. Right Click on same newly created folder & select 'Manage Application' >> 'Advance Settings..'
Set Enable Protocol value = net.tcp,http [you can add more endpoint using comma (,)]

You are done with hosting service on WAS with TCP binding!!!










Monday, August 11, 2008

Due to an unidentified problem, Windows can not display windows firewall settings.

I don't know why, Microsoft has some weird policy's, but that's true...you can't get rid of that. Today, I encountered with a very weird problem for changing[disable] Firewall settings in Windows Server 2008.
I tried my hands on firewall settings by FirewallSettings.exe [C:\Windows\System32] [Run as Administrator] but it was giving an error message as 'Due to an unidentified problem, Windows can not display windows firewall settings.'

To resolve this issue:
1. Run command prompt as Administrator
2. Go to C:\Windows\System32
3. execute command >> Netsh.exe firewall set opmode DISABLE
3.1
Netsh.exe firewall set opmode /?

And you are done!!!

It's weird because, if you don't have permission to change some settings than how come a console let you allow to do that?? but not allowed in case of UI interface.
Its a big question whether it was because of some ACL's or bug.

Resource:
http://www.techspot.com/vb/all/windows/t-18437-Due-to-an-unidentified-problem-windows-cannot-display-the-windows-firewall-settings.html

Sunday, August 10, 2008

System.Configuration.ConfigurationSettings.AppSettings' is obsolete

As usual, Microsoft has changed number of namespace/class & methods in successive higher versions of Visual Studio. If you are migrating from older version to 2.0 or higher you will encounter with errors such as System.Configuration.ConfigurationSettings.AppSettings' is obsolete.
To resolve this issue:
[I tested it in .Net Framework 3.5 & VS 2008]
you need to replace it by
'System.Configuration!System.Configuration.ConfigurationManager.AppSettings'.
If you don't find 'ConfigurationManager' add a reference of 'System.Configuration.dll. Rebuild your application...

And you are done!!!
Suggestions are always welcome...No need to login :)

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]

Watch the latest videos on YouTube.com