My understanding is that WCF decouples the service contract from the transport protocol to allow com开发者_JS百科munication between disparate systems. My question is, how does WCF determine/help with the higher level communication protocol, (application level not transport level)?
So, in a TCP WCF scenerio where one end is not WCF, does WCF just assume SOAP? Or, can we override and specify a custom XSD with an [Attribute]
?
Do the proxy classes still function with disparate systems? So the other end is still aware of types in the contract?
Sounds like by application level protocol you mean the way how data are serialized / encoded. You can create your own encoder. But usually encoding is considered as part of transport protocol.
Awareness of types in contract is done through WSDL. If you want to describe your new protocol (transport / encoding) as part of WSDL you must create some custom extensions for WSDL and custom exporter / importer extension for WCF. Also in case of WCF both service and client need access to assembly with new transport / encoding.
Custom XSD can be used if you swap default DataContractSerializer
with standard XmlSerializer
(by using XmlSerializerFormatAttribute
) where you have full control over XML serialization and you can force your class to serialize to any XSD you need by standard XML serialization tools offered in .NET Framework (attributes, IXmlSerializable
)
Separate area is REST but rest is not described by WSDL (at least not in WCF because it doesn't support WSDL 2.0) and proxies are not generated for REST services.
Btw. default WCF TCP is only WCF to WCF - it has its own message format and encoding.
Yes, out of the box WCF assumes you're using SOAP.
You can modify the result of a method call from XML to JSON using the WebGet attribute, as in:
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
public string MyMethod() { ... }
You can also use OData, by using the WCF Data Services library and project type: http://msdn.microsoft.com/en-us/library/cc668792.aspx
Or if you don't want that, you can use the REST Starter Kit for WCF, which implements REST instead of SOAP/WSDL: http://www.asp.net/downloads/starter-kits/wcf-rest
精彩评论