Prasham: What Is Address Header in WCF?
Prasham: What Is Address Header in WCF?
Example :
AddressHeader addressHeader= AddressHeader.CreateAddressHeader("Name of the
header", "Information included in header ");
Once the AddressHeader instance is created, it can be associated with end point instance as
follows :
EndpointAddress endpoint = new EndpointAddress(new
Uri("http://myserver/myservice"), addressHeader);
Thanks
Prasham
1. wsHttpBinding
2. wsDualHttpBinding
3. wsFederationHttpBinding
4. netTcpBinding
Thanks
Prasham
1. We are not only limited to HTTP protocol. We can also use supported protocols like TCP,
named pipes and MSMQ
2. No need to completely install IIS. We can only install WAS component and keep away the
WebServer.
Thanks
Prasham
2. This is useful when we need to implement the event handlers for opening and closing the
service.
Thanks
Prasham
1. basicHttpBinding
2. netTcpBinding
3. netNamedPipeBinding
Thanks
Prasham
a. LightWeight
b. OLE Transactions
c. WS-Atomic Transactions
Thanks
Prasham
The concurrency mode is specified using the ServiceBehavior attribute on the class that
implements the service.
Ex.
[ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Single)]
Public class ServiceClass : IServiceInterface{
//Implementation Code
}
Thanks
Prasham
A - Address (Where): Address tells us where to find the services, like url
B - Bindings (How) : Bindings tells us how to find the services or using which protocols finds
the services (SOAP, HTTP, TCT etc.)
C - Contacts (What): Contracts are an agreement between the consumer and the service
providers that explains what parameters the service expects and what return values it gives.
Hope this will be very helpful to understand three building blocks of WCF, a very frequently
asked interview questions.
Soap faults are not specific to any particular technology and they are based on industry
standards.
To support SOAP Faults WCF provides FaultException class. This class has two forms:
WCF service also provides FaultContract attribute so that developer can specify which fault can
be sent by the operation (method). This attribute can be applied to operations only.
Thanks
Prasham
<system.servicemodel>
<Services>
<service name=”MyService>
<host>
<baseAddresses>
</baseAddresses>
</host>
</service>
<services>
</system.servicemodel>
</configuration>
Thanks
Prasham
Message Contract can be used to add and to get the custom headers in SOAP message
Because of Message Contract we can customize the parameters sent using SOAP message
between the server and client.
Thanks
Prasham
This file contains the details required for WCF service to run it successfully.
We can also write our service code inside but this is not the best practice.
Thanks
Prasham
in WCF, Which contract is used to document the errors occurred in the service to client?
* Only Public fields or Properties of .NET types can be translated into XML.
* Only the classes which implement IEnumerable interface.
* Classes that implement the IDictionary interface, such as Hash table can not be serialized.
PerSession : This is used to create a new instance for a service and the same instance is used for
all method for a particular client. (eg: State can be maintained per session by declaring a
variable)
PerCall : This is used to create a new instance for every call from the client whether same client
or different. (eg: No state can be maintained as every time a new instance of the service is
created)
Single : This is used to create only one instance of the service and the same instance is used for
all the client request. (eg: Global state can be maintained but this will be applicable for all
clients)
What is WCF?
Windows Communication Foundation (WCF) is an SDK for developing and deploying services
on Windows. WCF provides a runtime environment for services, enabling you to expose CLR
types as services, and to consume other services as CLR types.
WCF is part of .NET 3.0 and requires .NET 2.0, so it can only run on systems that support it.
WCF
WCF is flexible because its services can be hosted in different types of applications. The
following lists several common scenarios for hosting WCF services:
IIS
WAS
Self-hosting
Managed Windows Service
Address --- Specifies the location of the service which will be like
http://Myserver/MyService.Clients will use this location to communicate with our service.
Binding --- Specifies how the two paries will communicate in term of transport and encoding
and protocols
Contract --- Specifies the interface between client and the server.It's a simple interface with
some attribute.
Second web services are not flexible. However, WCF Services are flexible. If you make a new
version of the service then you need to just expose a new end. Therefore, services are agile and
which is a very practical approach looking at the current business trends.
We develop WCF as contracts, interface, operations, and data contracts. As the developer we are
more focused on the business logic services and need not worry about channel stack. WCF is a
unified programming API for any kind of services so we create the service and use configuration
information to set up the communication mechanism like HTTP/TCP/MSMQ etc
• Self-hosting the service in his own application domain. This we have already covered in the
first section. The service comes in to existence when you create the object of Service Host class
and the service closes when you call the Close of the Service Host class.
• Host in Application domain and process provided by WAS (Windows Activation Service)
Server.
More details
http://www.dotnetfunda.com/articles/article221.aspx#whatarethevariouswaysofhostingaWCFser
vice
NET remoting
MSMQ
Web services
COM+
1. Service class
2. Hosting environment
3. End point
<endpoint
...
binding = "wsHttpBinding"
bindingConfiguration = "LongTimeout"
...
/>
</client>
<bindings>
<wsHttpBinding>
</wsHttpBinding>
</bindings>
How to deal with operation overloading while exposing the WCF services?
interface ICalculator
[OperationContract(Name = "AddInt")]
Notice that both method name in the above interface is same (Add), however the Name property
of the OperationContract is different. In this case client proxy will have two methods with
different name AddInt and AddDouble.
<services>
<endpoint
address = "net.tcp://localhost:8888/MyService"
binding = "netTcpBinding"
bindingConfiguration = "ReliableCommunication"
contract = "IMyContract"
/>
</service>
</services>
<bindings>
<netTcpBinding>
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
NetTcpBinding
WSHttpBinding
WSFederationHttpBinding
WSDualHttpBinding
Message reliability deals with reliability at the message level independent of how many packets
are required to deliver the message. Message reliability provides for end-to-end guaranteed
delivery and order of messages, regardless of how many intermediaries are involved, and how
many network hops are required to deliver the message from the client to the service.
<client>
address = "http://localhost:8000/MyService/"
binding = "wsHttpBinding"
contract = "IMyContract"
/>
</client>
</system.serviceModel>
The proxy can be generated using Visual Studio by right clicking Reference and clicking on
Add Service Reference. This brings up the Add Service Reference dialog box, where you need to
supply the base address of the service (or a base address and a MEX URI) and the namespace to
contain the proxy.
Proxy can also be generated by using SvcUtil.exe command-line utility. We need to provide
SvcUtil with the HTTP-GET address or the metadata exchange endpoint address and, optionally,
with a proxy filename. The default proxy filename is output.cs but you can also use the /out
switch to indicate a different name.
When we are hosting in IIS and selecting a port other than port 80 (such as port 88), we must
provide that port number as part of the base address:
Service contracts
Describe which operations the client can perform on the service.
There are two types of Service Contracts.
ServiceContract - This attribute is used to define the Interface.
OperationContract - This attribute is used to define the method inside Interface.
[ServiceContract]
interface IMyContract
[OperationContract]
string MyMethod( );
Data contracts
Define which data types are passed to and from the service. WCF defines implicit contracts for
built-in types such as int and string, but we can easily define explicit opt-in data contracts for
custom types.
class Contact
[DataMember]
If DataMember attributes are not specified for a properties in the class, that property can't be
passed to-from web service.
Fault contracts
Define which errors are raised by the service, and how the service handles and propagates errors
to its clients.
Message contracts
Allow the service to interact directly with messages. Message contracts can be typed or untyped,
and are useful in interoperability cases and when there is an existing message format we have to
comply with.
for example:
http://localhost:8888
the way to read the above url is
"Using HTTP, go to the machine called localhost, where on port 8888 someone is waiting"
When the port number is not specified, the default port is 80.
net.tcp://localhost:8888/MyService
When a port number is not specified, the default port is 808:
net.tcp://localhost/MyService
NOTE: Two HTTP and TCP addresses from the same host can share a port, even on the same
machine.
We can only open a named pipe once per machine, and therefore it is not possible for two named
pipe addresses to share a pipe name on the same machine.
interface IStock
[OperationContract]
[WebGet]
By adding the WebGetAttribute, we can define a service as REST based service that can be
accessible using HTTP GET operation.
What is binding and how many types of bindings are there in WCF?
Basic binding
Offered by the BasicHttpBinding class, this is designed to expose a WCF service as a legacy
ASMX web service, so that old clients can work with new services. When used by the client, this
binding enables new WCF clients to work with old ASMX services.
TCP binding
Offered by the NetTcpBinding class, this uses TCP for cross-machine communication on the
intranet. It supports a variety of features, including reliability, transactions, and security, and is
optimized for WCF-to-WCF communication. As a result, it requires both the client and the
service to use WCF.
Offered by the NetPeerTcpBinding class, this uses peer networking as a transport. The peer
network-enabled client and services all subscribe to the same grid and broadcast messages to it.
IPC binding
Offered by the NetNamedPipeBinding class, this uses named pipes as a transport for same-
machine communication. It is the most secure binding since it cannot accept calls from outside
the machine and it supports a variety of features similar to the TCP binding.
Federated WS binding
Duplex WS binding
Offered by the WSDualHttpBinding class, this is similar to the WS binding except it also
supports bidirectional communication from the service to the client.
MSMQ binding
Offered by the NetMsmqBinding class, this uses MSMQ for transport and is designed to offer
support for disconnected queued calls.
Offered by the MsmqIntegrationBinding class, this converts WCF messages to and from MSMQ
messages, and is designed to interoperate with legacy MSMQ clients.
They are
1. IIS
2. Self Hosting
3. WAS (Windows Activation Service)
HTTP
TCP
Peer network
IPC (Inter-Process Communication over named pipes)
MSMQ
The sample address for above transport schema may look like
http://localhost:81
http://localhost:81/MyService
net.tcp://localhost:82/MyService
net.pipe://localhost/MyPipeService
net.msmq://localhost/private/MyMsMqService
net.msmq://localhost/MyMsMqService
What is WCF?
Which namespace provide classes to work with images, sound, video, etc?
Which class is the base class of all the visual elements of WPF?
Which class of the WPF is the base class of all the user-interactive elements?
Example:-
<Button Name="btnClick">Click Me</Button>
Here the <Button> element specifies the use of the Button class.
What is WPF?
Using WPF we can develop GUI for both windows application and web application.
WindowsBase.dll:- It defines the core types constituting the infrastructure of WPF API.
Besides these three libraries WPF also uses an unmanaged binary called milcore.dll which acts
as a bridge between WPF assemblies and DirectX runtime layer.
What is XAML?
Posted by: Blessybaby
XAML (pronounced as Zammel) is a declarative XML-based language by which you can
define object and properties in XML. XAML document is loaded by a XAML parser.
XAML parser instantiates objects and set there properties. XAML describes objects,
properties and there relation in between them. Using XAML you can create any kind of
objects that means graphical or non-graphical. WPF parses the XAML document and
instantiates the objects and creates the relation as defined by XAML.
What is WPF?