3

I am reading so many things to understand various things in WCF.

Very soon, actually, i want to move/convert existing WSE3 web services to WCF. In existing WSE web services, I have some (data) classes that model entities in our environment.

While transforming those classes, should I use Data Contract/Data Member attribute or the MessageContract attribute?

1. How to decide between Message Contract and Data Contract in WCF? 2. Does type of binding (like basicHttpBinding) has any role in this decision? 3. Does proxies created at client side (when we add web reference) change significantly depending on the Data or Message Contract?

(PS: I am trying to find a way so that existing WSE clients should be able to consume the WCF service without much alterations/modifications. Is it possible to use the current proxies generated from ASMX web services, to connect to the new WCF service just by setting URL of the proxy to WCF service?)

Learner
  • 4,661
  • 9
  • 56
  • 102

2 Answers2

3

Here is a quick go at answering your questions:

1) Unless there is a specific reason like tweaking the structure of the soap XML, use DataContract instead of MessageContract.

2 & PS) Since you are currently using soap over HTTP, you'll most likely need the new services to be configured for basicHttpBinding. This will provide the interoperability that you need for the ASMX clients.

3) It shouldn't if the soap structure created by the WCF service matches your current soap.

I vaguely remember that WSE 3.0 supported some of the WS-* standards. If your current code depends on these then you may be able to also expose a wsHttpBinding for these operations but I don't think a default ASMX client works with a wsHttpBinding configured service.

Sixto Saez
  • 12,610
  • 5
  • 43
  • 51
  • @Sixto Saez: Thank you. How to make sure that WCF SOAP message is exactly same as existing WSE3 service SOAP? Does your answer to third question mean, 'Data Contract does not affect the proxies generated at client side' and 'Data Contract has no role in creating SOAP message'? – Learner Mar 18 '11 at 15:44
  • 1
    1: The most basic way of checking soap messages is to capture them when sent to a service. I use Fiddler2 as a HTTP "sniffer". It captures all HTTP request & responses originating on your machine. If you run the service on your machine make sure to use the machine name, not localhost so Fiddler will capture it. With Fiddler, have the WSE client call the WSE service to capture the soap. Next, have the WCF client call the WCF service & get the soap. Compare the results. Differences in soap header section are usually benign. The soap body structure and element names need to match exactly. – Sixto Saez Mar 18 '11 at 17:49
  • 2: Actually the DataContract defines the structure of the operation parameters so it does impact the overall service contract. The simplest way to generate the WCF classes for your existing WSE service is to get the current WSDL file for the service. Next, add a Service Reference in a Visual Studio project using the file path & file name for the "Address". Visual Studio will then create the necessary classes to conform to the WSDL. The Learning WCF book by Michelle Bustamante is a good place to start leaning WCF – Sixto Saez Mar 18 '11 at 17:51
  • @Sixto Saez: Can you please point me to any MSDN article which explains the messaging architecture of the WCF? Which explains how contracts, behaviors etc affect creation of SOAP messages etc? – Learner Mar 21 '11 at 05:41
  • 1
    Sure, below are a couple of URL that may help. http://msdn.microsoft.com/en-us/magazine/cc163647.aspx#S4 http://msdn.microsoft.com/en-us/library/ms730255.aspx – Sixto Saez Mar 21 '11 at 12:30
  • 1
    Also, a single article really won't contain the knowledge you're looking for unfortunately. WCF is very complex so I found the Learning WCF book a very useful guide which is why I recommend it. – Sixto Saez Mar 21 '11 at 12:39
  • @Sixto Saez: Upvoted for your last comments and accepted your reply as answer :) Thank you once again. – Learner Mar 22 '11 at 04:08
2

It depends on control you need over resulting SOAP message. DataContract defines part of message body wrapped by element defined by operation. MessageContract defines a structure of whole message - you can use multiple body members, you don't have to use default wrapper element and you can also place some data into SOAP headers.

In your scenario the most important part is to define WCF to use same SOAP messages as your former WSE3 service. Here the important is how do you currently serialize data? If you use Xml serialization (and attributes) you can use it directly in WCF by switchinig from data contract serialization to xml serialization.

Btw. why did you use WSE3 instead of plain ASMX? Did you use message security? In such case you will need another binding. BasicHttpBinding is not able to do message security.

General answer is yes, you can create service wich your current client proxies will be able to consume. But in reality the effort depends on your current service and current code.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • Thank you. Your answer is helpful. But i would like to know meaning of your second sentence ".... wrapped by element defined by operation". What does it mean? Also, if a class has DataContract attribute and it's instance is used as an argument to one of the web methods (Operation Contract), will it automatically be part of message body? Or do we need MessageContract attribute as well? We currently use XmlSerialzation. How to make sure that WCF SOAP message is exactly same as existing WSE3 service? Sorry for so many questions but all are very important to me. I'm reading too. – Learner Mar 18 '11 at 15:34