Wednesday, May 9, 2012

Creating, Deploying and Consuming Basic WCF Service

Creating and Deploying and Consuming a BasicWCF Service
Create:
Open Visual Studio, Go to the following menu, New -> Project -> WCF Service Application
Enter the application name and create the service
Delete the default Service and Interface(Contract)
Right Click the project and Go to Add -> New Item -> WCF Service.
Name the service and you will get a .svc file added along with the Interface file

There are three main things for a webservice as everyone tells,
1.Address
2.Binding
3.Contract
We will look into the Address and Binding laters, first we will discuss about the Contracts used for an WCF application There are types of contracts availables
DataContract
This will be usefult to handle your data, Each DataContract will be having a set of DataMembers

Example:
[DataContract]
Public class StudentContract
{
[DataMember]
public int StudentId {get; set;}
[DataMember]
public string StudentNamae {get; set;}
[DataMember]
public string CGPA {get; set;}
[DataMember]
public int Age {get; set;}
}

In this case we have defined Student as a Contract which is used to hold Student Data
Service Contract and OperationContract
This will define the operations or otherwise functionalities performed by that Webservice. This will be an Interface with method declarations, Interface is implied as Service Contract and methods/properties are implied as Operation Contracts.

Example:

[ServiceContract]
public interface IStudentService
{
[OperationContract]
StudentContract GetMarks(int studentId);

[OperationContract]
StudentContract GetStudent(int studentId);
}


Fault Contract and Message Contract

Fault Contract is used for error handling and defining custom errors. Message Contract is used for communicating directly with messages, they can be typed or untyped.

Writing the Service:
Once you finish defining Service Contract and DataContract, you can write your service in the .svc file
Service Class has to inherit from the SERVICE CONTRACT(in our case "IStudentService")
public class StudentService : IStudentService
{
public StudentContract GetMarks(int studentId);
{
//Your code to get Marks of the student by using StudentId
}
public StudentContract GetStudent(int studentId);
{
//Your code to get Student from StudentId
}
}

EndPoint:

After complete writing the service, we need to define the END POINT ( Where the service is going to be residing) For doing this, we need to change the web.config file and add the following values, Add the following Configuration settings to your web.config

" "

This will act as service endpoint, there three main things you have to consider ServiceName -> You should give the name of the service with complete namespace

Contract -> You should give the name of the service contract with complete namespace

binding -> There are totally 9 different binding WCF Supports that includes WS Binding - wsHTTPBinding, BASIC Binding - basicHTTPBinding, TCP Binding, MSMQ Binding, IPC Binding and so on.

After completing the endpoint definitino, build the WCF Project and make sure that there is no build errors. AFter that WCF Service has to be hosted to use/consume it, there are three ways to host a WCF Service
1. IIS Hosted
2. Self Hosted
3. WAS(Windows Activation Service)
4. Windows Service Hosted
There is a clear information on hosting and consuming webservice is given in MSDN

CONSUMING WCF Services

You can create a Web/Windows/Console application to consume a WCF - webservice
1. Add the Service reference to the application by identifying the webservice using "Discover" in "Add Service Reference" dialog
2. This will automatically add the client service model entries in web.config/app.config,
make sure that you get something like this after adding the Service reference to the application.
Example:
"
"

this tag will be added under the hierarchy in and one more entry called will be added as below,
If these entries are placed correctly in your web.config/app.config then you can go ahead use your service reference in code by adding "Using"
//Using entry for Service Reference using ServiceReference1;
//Instantiating the type from WCF Service and using it ServiceReference1.StudentServiceClient reference = new StudentServiceClient();

Sunday, April 22, 2012

Setup PDF Printer in Windows 7 - Cute PDF and Adobe PDF Printer

IF you want to use Adobe PDF Printer then you have to buy a Professional version of Adobe. Printing to PDF as an option is available from Adobe 7 Pro, Adobe 8 Pro and Adobe 9 Pro. It works like a virtual printing device, once you install this driver(Adobe Printing to PDF driver) You will get an option to print to PDF automatically in the Print Dialog If you don’t want to go and buy a Adobe Professional, then you can use some of the available free tools One such example is Cute PDF - http://www.cutepdf.com/Products/CutePDF/writer.asp This works great, This needs two basic requirements to work, Installation Requirements Supports Microsoft Windows 98/ME/2000/XP/2003/Vista/7 (x86/x64). Requires PS2PDF converter such as Ghostscript (recommended). You can get the free GPL Ghostscript 8.15  here. Once you download and install the CutePDF software, While installing if you don’t have as PS2PDF Converter, during the installation CutePDF will itself ask for an auto download and install. This requires an internet connection, so that it can download and install PS2PDF converter from internet. After the installation you don need to restart the computer, all you need to do is open any document or any file and try printing, when you try printing you will be able to see the option of "Write to Cute PDF", this will give you the option of Saving the document to PDF format.
After selecting the option you will get a save as dialog
This works great! Preserves the color, format, size and everything else you need.

Thursday, April 12, 2012

Culture Codes for Localization Implementation




Here are some of the most used culture codes for Globalization implementation.

Code Language – Country/Region Code Language – Country/Region


af Afrikaans hu-HU Hungarian – Hungary
af-ZA Afrikaans – South Africa is Icelandic
sq Albanian is-IS Icelandic – Iceland
sq-AL Albanian – Albania id Indonesian
ar Arabic id-ID Indonesian – Indonesia
ar-DZ Arabic – Algeria it Italian
ar-BH Arabic – Bahrain it-IT Italian – Italy
ar-EG Arabic – Egypt it-CH Italian – Switzerland
ar-IQ Arabic – Iraq ja Japanese
ar-JO Arabic – Jordan ja-JP Japanese – Japan
ar-KW Arabic – Kuwait kn Kannada
ar-LB Arabic – Lebanon kn-IN Kannada – India
ar-LY Arabic – Libya kk Kazakh
ar-MA Arabic – Morocco kk-KZ Kazakh – Kazakhstan
ar-OM Arabic – Oman kok Konkani
ar-QA Arabic – Qatar kok-IN Konkani – India
ar-SA Arabic – Saudi Arabia ko Korean
ar-SY Arabic – Syria ko-KR Korean – Korea
ar-TN Arabic – Tunisia ky Kyrgyz
ar-AE Arabic – United Arab Emirates ky-KG Kyrgyz – Kyrgyzstan
ar-YE Arabic – Yemen lv Latvian
hy Armenian lv-LV Latvian – Latvia
hy-AM Armenian – Armenia lt Lithuanian
az Azeri lt-LT Lithuanian – Lithuania
az-AZ-Cyrl Azeri (Cyrillic) – Azerbaijan mk Macedonian
az-AZ-Latn Azeri (Latin) – Azerbaijan mk-MK Macedonian – Former Yugoslav Republic of Macedonia
eu Basque ms Malay
eu-ES Basque – Basque ms-BN Malay – Brunei
be Belarusian ms-MY Malay – Malaysia
be-BY Belarusian – Belarus mr Marathi
bg Bulgarian mr-IN Marathi – India
bg-BG Bulgarian – Bulgaria mn Mongolian
ca Catalan mn-MN Mongolian – Mongolia
ca-ES Catalan – Catalan no Norwegian
zh-HK Chinese – Hong Kong SAR nb-NO Norwegian (Bokm?l) – Norway
zh-MO Chinese – Macao SAR nn-NO Norwegian (Nynorsk) – Norway
zh-CN Chinese – China pl Polish
zh-CHS Chinese (Simplified) pl-PL Polish – Poland
zh-SG Chinese – Singapore pt Portuguese
zh-TW Chinese – Taiwan pt-BR Portuguese – Brazil
zh-CHT Chinese (Traditional) pt-PT Portuguese – Portugal
hr Croatian pa Punjabi
hr-HR Croatian – Croatia pa-IN Punjabi – India
cs Czech ro Romanian
cs-CZ Czech – Czech Republic ro-RO Romanian – Romania
da Danish ru Russian
da-DK Danish – Denmark ru-RU Russian – Russia
div Dhivehi sa Sanskrit
div-MV Dhivehi – Maldives sa-IN Sanskrit – India
nl Dutch sr-SP-Cyrl Serbian (Cyrillic) – Serbia
nl-BE Dutch – Belgium sr-SP-Latn Serbian (Latin) – Serbia
nl-NL Dutch – The Netherlands sk Slovak
en English sk-SK Slovak – Slovakia
en-AU English – Australia sl Slovenian
en-BZ English – Belize sl-SI Slovenian – Slovenia
en-CA English – Canada es Spanish
en-CB English – Caribbean es-AR Spanish – Argentina
en-IE English – Ireland es-BO Spanish – Bolivia
en-JM English – Jamaica es-CL Spanish – Chile
en-NZ English – New Zealand es-CO Spanish – Colombia
en-PH English – Philippines es-CR Spanish – Costa Rica
en-ZA English – South Africa es-DO Spanish – Dominican Republic
en-TT English – Trinidad and Tobago es-EC Spanish – Ecuador
en-GB English – United Kingdom es-SV Spanish – El Salvador
en-US English – United States es-GT Spanish – Guatemala
en-ZW English – Zimbabwe es-HN Spanish – Honduras
et Estonian es-MX Spanish – Mexico
et-EE Estonian – Estonia es-NI Spanish – Nicaragua
fo Faroese es-PA Spanish – Panama
fo-FO Faroese – Faroe Islands es-PY Spanish – Paraguay
fa Farsi es-PE Spanish – Peru
fa-IR Farsi – Iran es-PR Spanish – Puerto Rico
fi Finnish es-ES Spanish – Spain
fi-FI Finnish – Finland es-UY Spanish – Uruguay
fr French es-VE Spanish – Venezuela
fr-BE French – Belgium sw Swahili
fr-CA French – Canada sw-KE Swahili – Kenya
fr-FR French – France sv Swedish
fr-LU French – Luxembourg sv-FI Swedish – Finland
fr-MC French – Monaco sv-SE Swedish – Sweden
fr-CH French – Switzerland syr Syriac
gl Galician syr-SY Syriac – Syria
gl-ES Galician – Galician ta Tamil
ka Georgian ta-IN Tamil – India
ka-GE Georgian – Georgia tt Tatar
de German tt-RU Tatar – Russia
de-AT German – Austria te Telugu
de-DE German – Germany te-IN Telugu – India
de-LI German – Liechtenstein th Thai
de-LU German – Luxembourg th-TH Thai – Thailand
de-CH German – Switzerland tr Turkish
el Greek tr-TR Turkish – Turkey
el-GR Greek – Greece uk Ukrainian
gu Gujarati uk-UA Ukrainian – Ukraine
gu-IN Gujarati – India ur Urdu
he Hebrew ur-PK Urdu – Pakistan
he-IL Hebrew – Israel uz Uzbek
hi Hindi uz-UZ-Cyrl Uzbek (Cyrillic) – Uzbekistan
hi-IN Hindi – India uz-UZ-Latn Uzbek (Latin) – Uzbekistan
hu Hungarian vi Vietnamese

Wednesday, April 11, 2012

How to check whether port is open or not in windows 7

Assuming that it's a TCP (rather than UDP) port that you're trying to use:
1. On the server itself, use "netstat -an" to check to see which ports are listening
2. From outside, just "telnet host port" to see if the connection is refused, accepted, or timeouts

When using the second way:
• If connection refused then there is nothing running
• If connection is accepted then port is listening
• If connection timeout means then firewall is blocking access

In Windows OS,

• Execute the following command and look for a ":1521" listener (you did not mention UDP/TCP). This will confirm there is something running on the port.
netstat -a -n
• After this, if you are expecting incoming connections on this port and feel that the firewall may be blocking them, you could start windows firewall logging and check the logs for dropped connections
○ Go to the Windows Firewall, Advanced settings
○ Click on the Settings button next to "Local Area Connection"
○ Select "Log dropped packets"
○ Look at the log file location (if not present define one)
○ Click OK
○ Now, when the connection attempt is made (assuming you know when this is done), look at the log file for a drop on port 3306.
○ If this is seen, you will want to add an exception for this port.
• This command will dump the Windows firewall configuration detail
netsh firewall show config


Few more commands for communicating between hosts and identify ports,

To Turn Off the Firewall
Netsh advfirewall set allprofiles state off

To Turn On the firewall
Netsh advfirewall set allprofiles state on


To Check Firewall status
Netsh advfirewall show

To Ping your machine from your machine
Ping localhost

To find whether a port is open or not in a host machine
Telnet

To get the complete IP Address related details of a machine
IPCONFIG /ALL

To identify what Ports are listening in your machine, from your machine command prompt type the following
netstat -a -n



http://www.canyouseeme.org/ This site will tell you whether port is open or not, but it will look for your domain IP Address, if you are in a Domain or Intranet connected machine then this site is not useful. If you are working on your laptop in your home or in ur private isp then this will be useful


If none of this work then make sure that your machine/laptop is having a static IP address and you should either add port to Firewall Open Ports of Switch off the firewall).

Tuesday, April 10, 2012

Resetting Password SYS and SYSTEM ACCOUNTS in ORACLE 11g

User Accounts/ Passwords

To Connect to Database using "/" account
> Connect / as SYSDBA

To Connect to a user account,
> Connect {UserId}
> Password: {Password}

To reset password of a user account,
> Alter User {UserId} identified by (New Password);

To create a new user
> Create User {UserId} Identified by (Password);

To Grant Revoke Permissions to Users
> Grant (Permissions) On (Object Name) to (UserId)
> Revoke (Permissions) On (Object Name) from (UserId)

Example :
Grant CONNECT, RESOURCE to dbaUser 1;
Grant Execute on usp_Abc to dbaUser1;

Listeners and ORA Files in ORACLE

In Oracle 11g Express Edition if "Get Started" is not working;

There could be many problems one of them can be,

LISTENER SERVICE

Make Sure that you Listener Service is started by going to "services.msc"




LISTENER CONTROL

Or type "LSNRCTL" in command Prompt, it will open Listener shell,
You can check the status, start and stop listener using this utility



Status




TNSPINGING

Try Pinging to the ORACLE Host using TNSPING command




ORA FILES

May be your TSNAMES.ORA is not pointing to the correct HOST NAME

ORA Files can be seen in the following path, (In My Case its C: Drive)

C:\oraclexe\app\oracle\product\11.2.0\server\network\ADMIN

Listener.ora
Sqlnet.ora
Tnsnames.ora

These 3 ORA Files has to point to a proper HOST NAME.
Example :

In LISTENER.ORA

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
(ADDRESS = (PROTOCOL = TCP)(HOST = SGBLS044.xyz.com)(PORT = 1521))
)
)


In TNSNAMES.ORA

XE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = SGBLS044.xyz.com)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = XE)
)
)

SQLNET ORA Entry

And in SQLNET.ORA, there should be one entry for NAMES.DIRECTORY_PATH =
In our above case,
It will be, NAMES.DIRECTORY_PATH = XE, since XE is our TNSNAMES Directory Path Alias

If all of the above are correct, then please forgive me :) : ) Post your problem in comment section, let me try what ever is possible with that :)

Error because of Adding Service Reference - SVCUTIL re uses all referenced libraries in the Project

Its common to come across the below error when adding WCF service reference,

Warning 1 Custom tool warning: Cannot import wsdl:portType Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter Error: List of referenced types contains more than one type with data contract name '' in namespace 'http://'. Need to exclude all but one of the following types. Only matching types can be valid references: "Company.Depart.Proj.dll", Company.Depart.Proj, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" (not matching) "
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://schemas..org/2012/04/service/user']/wsdl:portType[@name='IUserService'].

This happens because ServiceUtil is by default re uses all referenced assemblies in the project. And if any of the referenced assembly is not serializable or unable to reference then it will throw the above error.

To avoid this we can follow one of the below approaches,

Approach 1

Make sure that when using a service reference of a web service to a web application/any application , you follow below steps,

1. After adding the service reference OR while adding the service reference , In Service Reference Settings Dialogue , check the Data Type section,

To Go to Service Reference Settings Dialog, Right click the service , Select "Configure Service Reference"



That will open the Service Reference Settings Dialog,



In this, Make sure that you have selected the option "Reuse types in referenced assemblies" -> "Reuse types in specified referenced assemblies".

By Default it will be "Reuse types in all referenced assemblies". It will look for all references you have added in the project, this is what causing error.

Approach 2

Another approach is to uncheck "Reuse types in all referenced assemblies" but when you are unchecking this option, you may get compilation error as you might have references some dll's in Project. So before doing this you should be extra careful.