Thursday, July 24, 2025

Contracts in WCF Service

 Contracts in WCF Service 

Contracts are useful for building WCF service applications. They define what the protocol (binding) the service uses, how the communication will be done, what message exchange format to use and so on.
 
The following are the contracts are available in WCF:
  • Service contracts
  • Data Contracts
  • Message contracts
  • Fault Contract
  • Operation Contract

Service contracts

 
Service contracts define the Interface for the service. It can be defined as follows.
 
Syntax
  1. [ServiceContract]  
  2. public interface IService1  
  3. {  
  4.  
  5.     // TODO: Add your service operations here  

Key Points
  • Any WCF service can have more than one service contract.
  • Declare at least one service contract in a service.
  • A service contract can be declared using the [ServiceContract] attribute.
  • It allows defining an Operation Contract under it to expose the service outside the world.
  • It maps the interface and methods of your service to a platform-independent description.
  • It describes message exchange patterns that the service can have with another party. Some service operations might be one-way, others might require a request-reply pattern.
The service contract attribute has the following properties:
  • CallbackContract
  • ConfigurationName
  • HasProtectionLevel
  • Name
  • Namespace
  • ProtectionLevel
  • SessionMode
  • TypeId

Operation Contract

 
An Operation Contract defines the method exposed to the client to exchange the information between the client and server. An Operation Contract describes what functionality is to be given to the client, such as addition, subtraction and so on.
 
It can be defined as in the following:
  1. public interface IService1  
  2. {  
  3.     [OperationContract]  
  4.     string GetData(int value);  
  5.   
  6.     [OperationContract]  
  7.     CompositeType GetDataUsingDataContract(CompositeType composite);  
  8.     

The Operation Contract attribute has the following properties:
  • CallbackContract: Gets or sets the type of callback contract when the contract is a duplex contract.
  • ConfigurationName: Gets or sets the name used to locate the service in an application configuration file.
  • HasProtectionLevel: Gets a value that indicates whether the member has a protection level assigned.
  • Name: Gets or sets the name of the <portType> element in the Web Services Description Language (WSDL).
  • Namespace: Gets or sets the namespace of the <portType> element in the Web Services Description Language (WSDL).
  • ProtectionLevel: Specifies whether the binding for the contract must support the value of the ProtectionLevel property.
  • SessionMode: Gets or sets whether sessions are allowed, not allowed or required.
  • TypeId: When implemented in a derived class, gets a unique identifier for this Attribute.

Data Contract

 
Data Contracts define the data type for variables that are the same as get and set properties but the difference is that a Data Contract in WCF is used to serialize and deserialize the complex data. It defines how data types are serialized and deserialized. Using serialization, you can convert an object into a sequence of bytes that can be transmitted over a network. Using de-serialization, you reassemble an object from a sequence of bytes that you receive from a calling application.
 
It can be defined as follows:
  1. [DataContract]  
  2. public class Student  
  3. {  
  4.     private string _Name;  
  5.   
  6.     private string _City;  
  7.   
  8.   
  9.     [DataMember]  
  10.     public string Name  
  11.     {  
  12.         get { return _Name; }  
  13.         set { _Name = value; }  
  14.     }  

Fault Contract

 
A Fault Contract handles the exception and understands the cause of the error that occurs in the WCF service. When we develop a managed application or service, we will handle the exception using a try- catch block, but these exceptions handlers are technology-specific.
 
The following is the syntax to raise the custom error in WCF:
  1. [ServiceContract]  
  2. public interface IGetDetailsService  
  3. {  
  4.      [OperationContract]  
  5.      [FaultContract(typeof(Student))]  
  6.      Student GetDetails(string Name);  
  7. }  
  8.   
  9. [DataContract]  
  10. public class Student  
  11. {  
  12.      private string _Name;  
  13.   
  14.      private string _City;  
  15.   
  16.      [DataMember]  
  17.      public string Name  
  18.      {  
  19.          get { return _Name; }  
  20.          set { _Name = value; }  
  21.      }  
  22.   
  23.      [DataMember]  
  24.      public string City  
  25.      {  
  26.          get { return _City; }  
  27.          set { _City = value; }  
  28.      }  

Message contracts

 
The default SOAP message format is provided by the WCF runtime for communication between the client and the service. If it does not meet your requirements then we can create our own message format. This can be done using the Message Contract attribute.
 
It can be defined as:
  1. [MessageContract]  
  2. public class Person  
  3. {  
  4.    [MessageHeader] public Operation Name;  
  5.    [MessageHeader] public string city;  
  6.    [MessageBodyMember] private Home Address;  
  7.    [MessageBodyMember] private Home Streat;  
  8.    [MessageBodyMember] public int age;  

Note
 
 
I hope this article is useful for all students and beginners. Happy Learning , i have refer this Article from Mr Vithal Wadje


Monday, July 7, 2025

The Angular CLI requires a minimum Node.js version of either

 

The Angular CLI requires a minimum Node.js version of either

The error "The Angular CLI requires a minimum Node.js version of either" occurs when your Node.js version is not supported by the Angular CLI.

To solve the error, install the long-term supported version of Node.

You can use the node -v command to check your version of Node.js.
if you saw in error it is indicate current node version is 20.15 but it is not supporting so we have to upgrade Node version -
So we have to upgrade node-v22.17.0-x64 ( You can use node version according to you angular version ).

Thank you when you update the version this issue is fixed.


Thank you Hope it is help you !  


Thursday, July 3, 2025

How to connect Source control in Visual studio code

Dear Developer,

When starting a new project in Visual Studio and you want to connect it to source control, here’s what you need to do:

Take a look at the window below:

1st you have to download and install the Gits for window(I am using window os you can manage according to your OS) the URL is https://git-scm.com/downloads/win

Then, refer to the first screen and click the Reload link. You should see a screen like the one below:
Thank you! I hope this was helpful to you.







Unable to find packages "PackageName". No packages exist with this id in source(s): C:\Program Files\dotnet\library-packs, Microsoft Visual Studio Offline Packages

 Hello Everyone,

Sometimes, when you clone your code to a new location and try to run it, you might encounter an error like:

Unable to find package "PackageName". No packages exist with this ID in source(s): C:\Program Files\dotnet\library-packs, Microsoft Visual Studio Offline Packages

Don’t worry — this is a common issue, and the solution is simple. Just follow the steps below to resolve it.

✅ Here's how to fix it:

1. Add nuget.org as a Package Source

Visual Studio might not be configured to look at the official NuGet repository. To fix this:

  1. Go to Tools > Options.
  2. Navigate to NuGet Package Manager > Package Sources.
  3. Click the "+" button to add a new source.
  4. Set:
    • Namenuget.org
    • Sourcehttps://api.nuget.org/v3/index.json
  5. Click Update or OK to save.

Make sure nuget.org is checked and at the top of the list 

your setting look like as below screen.

Rebuild your solution ! Hope it help you 
Thank you!





Wednesday, December 4, 2024

How to set Custom Filter Menu Components in angular 17 with Kendo UI

 Dear Reader, 

if you want to set menu filter Kendo UI with angular then it very useful tips.

 for example when you are using  <kendo-grid></kendo-grid> so you have to follow below steps for filter the menu.



on UI Component

<kendo-grid
[data]="gridDataSource$ | async"
filterable="menu"
(dataStateChange)="dataStateChange($event)">  
<kendo-grid-column field="productName" title="Product Name" width="150">
</kendo-grid-column>
</kendo-grid>



and My TS code are as below
import { process, State } from '@progress/kendo-data-query';

export class DataComponent implements OnInit {
  skip = 0;
  public state: State = {
    skip: 0,
    take: 10,
    filter: {
      logic: 'and',
      filters: []
    }
  };
dataStateChange(state: DataStateChangeEvent): void {
    this.state = state;
    this.loadData();
  }

  private loadData(): void {
    this.gridDataSource$ = this.gridDataSubject.asObservable().pipe(
      map(gridDataResult => process(gridDataResult.data, this.state))
    );
  }

}

Thank you Hope it is helpful to you ! Happy learning.

Wednesday, November 20, 2024

Upgrade braces from 3.0.2 to 3.0.3 to fix the vulnerability.

if you are working in angular with good MNC company so you have audit issue , how to fix the audit issue regarding the below issue.

Recommendation

Upgrade braces from 3.0.2 to 3.0.3 to fix the vulnerability.


Description

The NPM package braces fails to limit the number of characters it can handle, which could lead to Memory Exhaustion. In lib/parse.js, if a malicious user sends "imbalanced braces" as input, the parsing will enter a loop, which will cause the program to start allocating heap memory without freeing it at any moment of the loop. Eventually, the JavaScript heap limit is reached, and the program will crash.


How to Fix it , it is very simple :-

If you are using NPM 6 or above, you can run npm audit fix on your local machine to fix vulnerabilities. For more info, please visit https://docs.npmjs.com/cli/audit


Hope it is help you, Happy Learning! ....

Monday, October 7, 2024

How to change datetime2 data type to INT

 Dear Friend,

i am come with new solution if you stuck some place your are not able to  ALTER COLUMN the column if column data type is datetime2  so without delayed below is solution.

if you tried with normal query just like ALTER TABLE table ALTER COLUMN [Period] int; 

The Error is :- Operand type clash: datetime2 is incompatible with int?

The error you’re encountering indicates that the Period column currently has a datetime2 data type, and you’re trying to change it to int. Directly changing the data type from datetime2 to int is not allowed because they are incompatible types.

To resolve this, you need to follow these steps:

  1. Create a New Column:

    • Add a new column with the desired data type (int).-- Step 1: Add a new column with the desired data type
    • ALTER TABLE tableName ADD PeriodInt INT;
  2. Update the New Column:

    • Populate the new column with the converted values from the existing column.
    • -- Step 2: Update the new column with converted values
      UPDATE tableName 
      SET PeriodInt
      = YEAR(Period) * 100 + MONTH(Period);
  3. Drop the Old Column:

    • Remove the old column.
    • -- Step 3: Drop the old column
      ALTER TABLE tableName 
      DROP COLUMN Period;
  4. Rename the New Column:

    • Rename the new column to the original column name.
    •  Step 4: Rename the new column to the original column name
      EXEC sp_rename 'tableName 
      .PeriodInt', 'Period', 'COLUMN';



Thank you for your Time Hope it will help you