Thursday, July 14, 2011

A WCF Binding Table (Reference, ZZ)

This is posted by Dan Rigsby, http://www.danrigsby.com/blog/index.php/2008/01/19/wcf-binding-comparision-list-and-supported-features-reference/


Name (Config Name) [Schemas]TransportMessage EncodingMessage VersionInteropSecuritySessionTx FlowDuplex
BasicHttpBinding
(basicHttpBinding)
[http, https]
HTTP/HTTPS

Text

SOAP 1.1

Basic Profile 1.1None, Transport, Message, MixedN
A binding that is suitable for communicating with WS-Basic Profile conformant Web services like ASP.NET Web services (ASMX)-based services.
WSHttpBinding
(wsHttpBinding,
webHttpBinding)
[http, https]
HTTP/HTTPSText, MTOM

SOAP 1.2, WS-A 1.0

WSNone, Transport,Message, MixedNone, Transport, Reliable SessionNo, Yes(WS-AT)N
A secure and interoperable binding that is suitable for non-duplex service contracts.
WS2007HttpBinding
(ws2007HttpBinding)
[http, https]
HTTP/HTTPSText, MTOMSOAP 1.2, WS-A 1.0WS-Security,WS-Trust,WS-SC, WS-SPNone, Transport,Message, MixedNone, Transport, Reliable SessionNo, Yes(WS-AT)N
WSDualHttpBinding
(wsDualHttpBinding)
[http]
HTTPText, MTOM

SOAP 1.2, WS-A 1.0

WSNone,MessageReliable SessionNo, Yes(WS-AT)Y
A secure and interoperable binding that is suitable for duplex service contracts or communication through SOAP intermediaries.
WSFederationHttpBinding
(wsFederationHttpBinding)
[http, https]
HTTP/HTTPSText, MTOM

SOAP 1.2, WS-A 1.0

WS-FederationNone,Message, MixedNone, Reliable SessionNo, Yes(WS-AT)N
A secure and interoperable binding that supports the WS-Federation protocol, enabling organizations that are in a federation to efficiently authenticate and authorize users.
WS2007FederationHttpBinding
(ws2007FederationHttpBinding)
[http, https]
HTTP/HTTPSText, MTOM

SOAP 1.2, WS-A 1.0

WS-FederationNone,Message, MixedNone, Reliable SessionNo, Yes(WS-AT)N
A secure and interoperable binding that derives from WS2007HttpBinding and supports federated security.
NetTcpBinding
(netTcpBinding)
[net.tcp]
TCPBinary

SOAP 1.2

.NetNone,Transport, Message, MixedTransport, Reliable SessionNo, Yes(OleTx)Y
A secure and optimized binding suitable for cross-machine communication between WCF applications.
NetPeerTcpBinding
(netPeerTcpBinding)
[net.p2p]
P2PBinary

SOAP 1.2

PeerNone,Transport, Message, MixedY
A binding that enables secure, multi-machine communication.
NetNamedPipeBinding
(netNamedPipeBinding)
[net.pipe]
Named Pipe (IPC)Binary

SOAP 1.2

.NetNone,TransportNone,TransportNo, Yes(OleTx)Y
A secure, reliable, optimized binding that is suitable for on-machine communication between WCF applications.
NetMsmqBinding
(netMsmqBinding)
[net.msmq]
MSMQBinary

SOAP 1.2

.NetNone,Transport, Message, BothNo, Yes(OleTx)N
A queued binding that is suitable for cross-machine communication between WCF applications.
MsmqIntegrationBinding
(msmqIntegrationBinding)
MSMQ*MSMQNone,TransportNo, YesN
A binding that is suitable for cross-machine communication between a WCF application and existing MSMQ applications.

*Doesn’t use a WCF message encoding – instead it lets you choose a pre-WCF serialization format
Notes: Items in bold are the defaults for features that have multiple values. “–“ = No Support
Abbreviations: WS-SC = WS-SecureConversation, WS-SP = WS-SecurityPolicy, WS-A = WS-Addressing, WS-AT = WS-AtomicTransaction, OleTx = OleTransactions

FeatureDescription
NameThe name of the binding.
Config NameThe name of the binding used in configuration such as app.config or web.config.
SchemeThe supported Uri schemes.
TransportThe supported types of message transport (similar to Providers in Remoting).
Message EncodingThe supported types of message encoding.
Message VersionThe supported message versions.
InteropNames the protocol or technology with which the binding ensures interoperation.
SecuritySpecifies how the channel is secured:

  • None: The SOAP message is not secured and the client is not authenticated.
  • Transport: Security requirements are satisfied at the transport layer.
  • Message: Security requirements are satisfied at the message layer.
  • Mixed: This security mode is known as TransportWithMessageCredentials. It handles credentials at the message level, and integrity and confidentiality requirements are satisfied by the transport layer.
  • Both: Both message level and transport level security are used. This ability is unique to the NetMsmqBinding.
SessionSpecifies whether this binding supports session contracts.
Transaction FlowSpecifies whether transactions are enabled and the transaction flow type in ().
DuplexSpecifies whether duplex contracts are supported. Note this feature requires support for Sessions in the binding.

Tuesday, July 12, 2011

WCF service throw custom details using FaultException < T >

For example, on the server side, there is code like

if(i>array.Lenght)
{
throw new FaultException< IndexOutOfBoundException >("Index Out Of Bound");
}

We can throw any custom class:

throw new FaultException < MyClass >();

Then on the client side call, we can

try , catch and extract the Custom Class information out.

Thursday, June 30, 2011

Xml Serialization of Readonly Collection Property

I have a class:

public class AccountManagement {

public AccountManagement ()
{
this.Accounts=new Collection< Account>;
}
public Collection< Account> Accounts {get; private set}

}

When use a XML Serializer to serialize this class, there comes out an exception:

Unable to generate a temporary class (result=1). error CS0200: Property or indexer '' cannot be assigned to -- it is read only.

By Microsoft explanation, even we use private set, the Collection property is still writable inside the class, in order to do xml serialization, we need to write the class like:


public class AccountManagement {

private readonly Collection < Account> accounts;

public AccountManagement ()
{
this.accounts=new Collection< Accout>;
}
public Collection< Account> Accounts
{

get {return accounts;}

}

}

Monday, May 9, 2011

Some NuGet Command

install-package nunit.sample -project MyProject
get-package -remote -filter WPF
use Tab for intelligence.

Monday, April 11, 2011

FallbackValue vs. TargetNullValue

FallbackValue: Gets or sets the value when the binding is unable to return a value.
TargetNullValue: Gets or sets the value when the value of the source is null.

For instance, we have a label:

< Label Name="Label" Content="Value1" />

And a TextBox:
< TextBlock Text="{Binding ElementName=Label,Path=Content,FallbackValue=Value2,TargetNullValue=Value3}" />

We can test by doing the following operations respectively:

1.Do nothing,
2.Remove the Content="Value1"
3.Change Path=Content to Path=Content2

the text show in the Textbox will be:
Value1
Value3
Value2

Wednesday, April 6, 2011

Event in WinForm and WPF

Event is a member that enables a class to provide notification.

I. Review event in WinForm


Let's review event concept WinForm(or console, or Asp.net or any application which doesn't reference Presentation.Core assembly to support the concept of routed event) first:

1. EventHandler is a predefined delegate, it is the same as we define a delegate:

public delegate void Del(object,EventArgs);

It is also the same as Action< object, EventArgs>

EventHandler requires an object and an EventArgs as parameter.

2. We can define a custom event use any delegate type:

for example,we created a class called ExtendedButton:

public delegate void Del(int i);
public class ExtendedButton:System.Windows.Forms.Button
{
public event Del ValueSetted;
public event EventHandler Pushed;
public event Action MyMouseEntered;
}
3. Subscribe to the EventHandler Can also use Lambda Expression

for example:


ExtensionButton extbtn=new ExtensionButton();
extbtn.Pushed+=new EventHandler(myMethod);

public void myMethod(object s, EventArgs e)
{
//...Some code
}

We can also write:
extbtn.Pushed+=(s,e)=>//...Some code

4. Is event keyword optional?

The keyword event is important. Without event keyword, the member in the class will be treated as a field which is delegate type. for example the above code, we get the event keyword off:

public delegate void Del(int i);
public class ExtendedButton:System.Windows.Forms.Button
{
public Del ValueSetted;
public EventHandler Pushed;
public Action MyMouseEntered;
}

Then we can write code like this way:

ExtensionButton extbtn=new ExtensionButton();
extbtn.ValueSetted(5);
extbtn.Pushed(s,e);
extbtn.MyMousedEventered();

But when we add the keyword event, this make sure the event cannot be called outside of the owner class. Then this kind of call like extbtn.ValueSetted(5) will have compile error. The error message will be like:
"The event '' can only appear on the left side of += or -= (excepted used within the class '')"

5. How to invoke event outside of the Owner class?

We can add a method to the ExtensionButton class, for instance:
public class ExtendedButton:System.Windows.Forms.Button
{
public EventHandler Pushed;

public void RaisePushed()
{
if (Pushed != null)
Pushed(this, EventArgs.Empty);
}
}

Now we can invoke the event by:

ExtensionButton extbtn=new ExtensionButton();
extbtn.RaisePushed();

I have written the sample code here.

For C# 4.0, event mechanism for cross thread/synchronization is re written, see this
Link.



II. Event in WPF


WPF introduced routed events, which can be raised by multiple controls and handled by multiple handlers.

There are three type of routed events:
Direct Event
Bubbling Event
Tunneling Event