Wednesday, July 26, 2017

Conduent

1. What are the roles in Agile?
2. If you have come an issue in previous version during sprint than who will decide in agile what should be done.
3. What  will print in stored procedure

if(Null=Null)
print("if")
else
print("else")

Ans : if

4. If we have to copy one table data into another with identity column. How will you do that?
Ans :  You can on the insert into identity first than you can insert data in identity column

Set IDENTITY_INSERT ON

by default it is off means you can not insert data in identity column.

5. Why MVC is fast?
6. What is the wild card character used in jquery instead of # while selecting id.

7. If we have two variable with same name in two java script file. What will happen?
Ans : Will overwrite second variable value, we use closure for that.

8.   Jquery is browser independent or not? What is the solution to make it?
9.   Why we use Lambda expression?
10. What is WPF architecture?
11. What is MVVM?
12.  What are different type of  resources in WPF?
And dynamic and static

13 . Why we use WPF?
14.  What is entity framework? How will we use entity framework?
15.  Have you worked on ASP .Net Core?
16.  Write a program for sorting an array?
17 What will be the output?

x=5;
while(x<6 p="">print(x)

18. Why we use JQuery?
19. What we can't do in google analytics?

Monday, July 17, 2017

Instance Mode in WCF

When a client make a request to WCF, WCF service creates an instance of service to service the client request. After the request completion what will happen of that object we will see here.

Instance Context Mode dictates how long the service instance remain on the server.


There are three instancing modes

Per Call :-  

A new instance of service object is created for every request, whether the request is coming from same client or different client. It means service object is destroyed after the completion of request i.e after the response sent to the client. 

In this state is not maintained between request.

Per Session :-  

A new instance of service object is created for every new client session and that service object maintained during that session.

Per Session :-  

A single object serves all request whether they are coming from same client or different client during the lifetime of application.

It can be set using InstancContextMode in service behavior.


[ServiceBehaior(InstanceContextMode = InstanceContextMode.PerCall]
public class LoadService: ISService
{

}


Implications of Per Call

1. Better memory usage as object is freed immediately.
2. No Concurrency
3. No State maintained between call.
4. Performance could be an issue as object is created for every method call
5. Application scalability is better because it service does not hold any resources.

[ServiceBehavior (InstanceContextMode = InstanceContextMode.PerCall)]
public class MathService :IMatchServie
{
 int _iVal;
 public int IncreamentVal()
{
  _iVal =_iVal+1;
   return _iVal;
}
}

Client Code

static void main(string[] args)
{
MatchService.MathServiceClient client = new MatchServiceClient()

int iVal = client.IncreamentVal();
Console.WriteLine("Vale after first call "+ iVal);

int iVal = client.IncreamentVal();
Console.WriteLine("Vale after Second call "+ iVal);
}

Output

Value after First call 1
Value after Second call 1

Implications of Per Session

1. State maintained between calls for same client.
2. More memory consumption as service objects  remain in memory until the client session timeout. On the other this affect application scalability negatively.
3. Concurrency is an issue multi threaded client.
4. The default session time out is 10 minutes.




[ServiceBehavior (InstanceContextMode = InstanceContextMode.PerSession]

public class MathService :IMatchServie

{

 int _iVal;
 public int IncreamentVal()
{
  _iVal =_iVal+1;
   return _iVal;
}
}

Client Code

static void main(string[] args)
{
MatchService.MathServiceClient client = new MatchServiceClient()

int iVal = client.IncreamentVal();
Console.WriteLine("Vale after first call "+ iVal);

int iVal = client.IncreamentVal();
Console.WriteLine("Vale after Second call "+ iVal);
}

Output

Value after First call 1
Value after Second call 2

State is maintained for same client means if you create another client like second console application and call increment method it will give you fresh value.

Which is better Per Call or Per Session


1. Both have different strength and weakness
2.If you prefer object oriented style than persession is better, if you prefer SOA (Service Oriented Architecture Style) than percall is better.
3. Per Session is better for performance and Per is better for scalability.

Does all binding support session?

No, All binding does not support session like basichttp binding does not support session. If a binding does not support session than service behaves like per call. netTcpbinding support session.

How to control the WCF service time out?

You can set the receivetimeout attribute in binding tag. and reset it. by default it is 10 minutes.

What happens when the session timeout reached?

When the session timeout reached the connection to the WCF service closed. And communication channel gets faulted and the client can no longer use the same proxy instance to call method. And on calling an exception throws by WCf service. And the data in service object lost.

How to fix the communication channel  in case of faulted state exception?

Using try catch block  at client side and re- create the proxy object in catch block in case of Communication exception.

Session Id

To send message from a particular client to a particular service instance on the server, WCF uses session id.

At client side to retrieve session id we use

client = new MathServiceClient()

client.InnerChannel.SessionId

At WCF service to retrieve session id we use

OperationContext.Current.SessionId

client side and WCF server side session id are co related using the reliable session setting at WCF service host, it is defined in binding tag

If reliableSession is disable than both session id will be different otherwise same. By default it is disabled.

<bindings>
<netTcpBinding>
<binding name="netTcpBinding" receiveTimeout="00:00:10">
<reliableSession enabled="true"/>
<binding>
<netTcpBinding>
<binding>

If binding s wsHttpBinding than session id will be same irrespective of relaibleSession means session id will be same even relaibaleSession if disable.

Single :-  

In single instance context mode only one object created for all client and for all request.Service object is not destroyed after request completed it remains in memory.

In single context mode session id will be same for a client for all request. session id will be different for two different client.

State is maintained and shared between different request and from different client.

Concurrency can be an issue.

To resolve concurrency we can configure the service to allow a single thread at time.

SessionMode Enumeration 

Session mode enumeration is used in service contract to specify whether session is allowed or not not in service

There are three value of session mode

Allowed :-

By default session is allowed in service contract

Not Allowed :- 

In this case session is not allowed so service does not support binding that initiate session

Required :-

In this case service contract require a binding that support session.


If session mode is allowed and Instance Context is Single than what will happen?

In that case we use basicHttpBinding that does not support session than service will work as Single ton but without session but session id will be null.

If we use netTcpBinding that support session than service still work as Singleton but with session.

If session mode is required and Instance Context is Single than what will happen?


In that case if we use basicHttpBinding than service will throw error because basicHttpBinding does not support session.

And netTctBinding will work fine with session.

part-42 

MTOM in WCF - Message Transmission Optimization Mechanism

Default message encoding in WCF is Text which is base64 encodes data.
It has two disadvantages

1. Base 64 encoding (bloats)increase the message size by 33%
2. It evolves extra processing overhead to encode and decode base64.

The best approach to send large data is MTOM. It does not base64 encode data. It is fast and does not have overhead of encode and decode.

With MTOM binary data is included as a MIME (Multipurpose Mail Extension)

Wednesday, July 12, 2017

Hosting WCF in IIS with WAS enabled

By default IIS  support only http protocol, To support non http protocol we have to install Windows Communication Foundation Non-HTTP Activation and WAS(Windows Process Activation). Windows 7 and above version of Windows along with IIS7 support WAS.

After installing you need to enable net.tcp protocol for WCF application hosted in IIS and now you will be able to use nettcp binding.

Message Exchange Pattern in WCF


1. Request-Reply
2. One Way
3. Duplex


Request-Reply

Request-Reply is the default pattern. In this pattern client send a message to WCF service and then wait for a reply even return type is void. Client wait to complete the WCF operation.

Except MSMQ all binding support this pattern.

In this pattern fault and exception get reported to client immediately.
If IsOneWay=false than it is Request-Reply.

One Way

In one way client does not except any response nor WCF send any reply to client. And exception also don't get reported to client. return type should be void in one way call.not out,ref param allowed.

If service has received a call when it was serving other request than the current request is queue but it it does not block the client.

One way call is different form asynchronous call.  In WCF there is a server queue limit if number of waiting  one way call is exceeded the limit than client wait for that.


Duplex

Duplex can be implemented using Request-Reply or One Way operation.

If we want to send some message from WCF service between processing in a long function than we use duplex. We use CallbackContract delegate for this.

Syntax is 

[ServiceContract (CallbackContract= typeof(IReportServiceCallback)]
public interface IReportService
{

  void DoProcessReport();
}

public interface IReportServiceCallback
{

  void Progress(int percentage);

}

Method can be called using OperationContext.

[ServiceBehavior(ConcurrencyMode = ConcuurencyMode.reentrant)]
public ReportService : IReportService
{

public void ProcessReport()
{

OperationContext.Current.GetCallbackChannel().Progress(iValue);

}
}

If we want to use Dupex  with Request Reply operation than we need to set attribute ConcurrencyMode = ConcurrencyMode.Reentrant in service and at client we have to use CallbackBehaior(UseSynchronizationContext = false)

To implement Duplex wiht One Way operation we haven't need any attribute.

Tuesday, July 4, 2017

WCF 30

Advantage WCF hosting in IIS

1. No code required to host the service, All we need ServiceHost.svc file and ServiceHost directive is responsible for creating an object of Service Host and started it when required.
2. Automatic message based activation i.e No need to run the host every time WCF reuired.
Means whenever message arrives at service it launches itself. In case of self hosting it should be always running.
3 Automatic recycling - IIs provide automatic process recycling if process is taking too much time



Followers

Link