NEWS

Tuesday, April 30, 2013

SQL SERVER – Get Time in AM/PM Format

Syntax to Get SQL DateTime With Am/Pm Format:


SELECT
GETDATE() AS CurrentDate,
RIGHT(CONVERT(VARCHAR, GETDATE(), 100),7) ASCurrentTime,
CONVERT(VARCHAR(10), GETDATE(), 101) + ' ' +RIGHT(CONVERT(VARCHAR, GETDATE(), 100),7) AS CurrentDateTime

Wednesday, April 24, 2013

Difference between Data Contract and Message Contract in WCF

Data Contracts:

WCF data contracts provide a mapping function between .NET CLR types that are defined in code and XML Schemas Definitions defined by the W3C organization (www.w3c.org/) that are used for communication outside
the service.

Message Contracts:

Message contracts describe the structure of SOAP messages sent to and from a service and enable you to inspect and control most of the details in the SOAP header and body. Whereas data contracts enable interoperability through the XML Schema Definition (XSD) standard, message contracts enable you to interoperate with any system that communicates through SOAP. Using message contracts gives you complete control over the SOAP message sent to and from a service by providing access to the SOAP headers and bodies directly. This allows use of simple or complex types to define the exact content of the SOAP parts.

2. Why is it useful to pass information in SOAP headers with Message contract?

Passing information in SOAP headers is useful if you want to communicate information “out of band” from the operation signature. For instance, session or correlation information can be passed in headers, rather than adding additional parameters to operations or adding this information as fields in the data itself. Another example is security, where you may
want to implement a custom security protocol (bypassing WS-Security) and pass credentials or tokens in custom SOAP headers. A third example, again with security, is signing and encrypting SOAP headers, where you may want to sign and/or encrypt some or all header information. All these cases can be handled with message contracts. The downside with this technique is that the client and service must manually add and retrieve the information from the SOAP header, rather than having the serialization classes associated with data and operation contracts do it for you.

3. Can't mix datacontracts and messagecontracts.

Because message-based programming and parameter-based programming cannot be mixed, so you cannot specify a DataContract as an input argument to an operation and have it return a MessageContract, or specify a MessageContract as the input argument to an operation and have it return a DataContract. You can mix typed and untyped messages, but not messageContracts and DataContracts. Mixing message and data contracts will cause a runtime error when you generate WSDL from the service.