Reputation: 17243
Until recently I thought WCF services were .NET only (i.e. meant to be accessible only from .NET applications), because they expose a .NET object on which the consumer invokes methods (which are then of course run on the server).
Then I read that WCF services are cross-platform; i.e., accessible from a variety of platforms, not only .NET.
How is this possible? How can you talk to a WCF service from e.g Java? Do you simply send away SOAP text? Or are you exposed to some Java object? Or something else?
Upvotes: 2
Views: 1654
Reputation: 21661
This is possible through serialization.
When you return a .NET object, it's serialized (usually into XML or possibly JSON, but there could be other possibilities as well). If a .NET client is receiving the message, it will then deserialize it back into a .NET object. For example:
class MyObject
{
int blah;
string blah2;
}
...
return new MyObject() { blah = 0; blah2 = "asdf" };
Might get serialized as:
<ns0:MyOjbect xmlns:ns0="tempuri.org">
<blah>0</blah>
<blah2>asdf</blah2>
</ns0:MyObject>
in XML, or
{
MyOjbect {
"blah":0,"blah2":"asdf"
}
}
in JSON
And then deserialized back into the MyObject
class by the client. Other clients can do this deserialization to their own datatypes as well - or just work directly with he XML or JSON.
There's a little more at play here too, depending on whether you're using a SOAP
or REST
based service; for SOAP
, there'll be a SOAP
envelope around the serialization, and for REST
there'll be some HTTP
status headers and bodies. It also gets more complicated when you're dealing with complex/composed objects, but the basic idea remains the same: break them down into something you can easily and portably send over the wire to be reconstituted by the client.
Upvotes: 0
Reputation: 161821
From my old blog post "Basics: How Web Services Work":
Web Services are all about XML:
- A Web Service is described by a document in XML format, in the XML language known as WSDL (Web Services Description Language). This describes the service in terms of the operations, messages, and bindings that it contains, and may provide a URL at which the service may be called.
- The structure of the messages is described using XML Schema (XSD) which is either contained in, or referred to by, the WSDL
- The messages sent to, and received from, the web service are all in the form of XML that complies to the schema, and which follows the protocols described by the WSDL, using an XML protocol known as SOAP (for Simple Object Access Protocol)
Since the time that I wrote that post, the JSON (JavaScript Object Notation) has become another popular format for data interchange with web services. Typically, services which use JSON do not use the equivalent of a WSDL or XSD, but the other ideas are the same.
The bottom line is that your research has misled you. WCF does not send and receive .NET objects. WCF sends and receives XML (or maybe JSON). The other side also sends XML or JSON. It doesn't matter what platform the "other side" is using.
Upvotes: 2