473,382 Members | 1,424 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

WCF Advice

Hello cSharpies,

I'm trying to get up to speed with WCF services.

Does a service need to have a ServiceContract/OperationContract to make
use of a DataContract?

I want to have a service that allows a client to create an object in the
service app and have the service app "do something" with the object.
Thanks,

Bill
Nov 7 '08 #1
7 2619
Bill,

A DataContract is simply the way that complex constructs are sent across
the wire to endpoints in WCF. It's used to comprise the payload of the
message.

The service contract and operation contract make up the endpoint, which
every service needs. The endpoint is made up of the address of the service,
the binding (which defines things like expectations, like transactioning,
security, etc, etc, as well as protocol), and the contract, which exposes
the operations.

You need all of these to expose a service through an endpoint in WCF.
DataContract is simply a means to send a message to the endpoint (in both
directions).

You say that you want the service app to "do something" with the object.
That's simple, just define a method on your contract that will do something,
and then pass the object to the service through the proxy.

Mind you, all transfers in WCF are pass-by-value, so if you want to
change the object that is sent, then you will have to pass it by ref (WCF
should handle this for you), or return a copy of the object that you use
once it is modified.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bill McCormick" <wp*********@newsgroup.nospamwrote in message
news:Ow**************@TK2MSFTNGP04.phx.gbl...
Hello cSharpies,

I'm trying to get up to speed with WCF services.

Does a service need to have a ServiceContract/OperationContract to make
use of a DataContract?

I want to have a service that allows a client to create an object in the
service app and have the service app "do something" with the object.
Thanks,

Bill

Nov 7 '08 #2
Nicholas Paldino [.NET/C# MVP] wrote:
Bill,

A DataContract is simply the way that complex constructs are sent across
the wire to endpoints in WCF. It's used to comprise the payload of the
message.

The service contract and operation contract make up the endpoint, which
every service needs. The endpoint is made up of the address of the service,
the binding (which defines things like expectations, like transactioning,
security, etc, etc, as well as protocol), and the contract, which exposes
the operations.

You need all of these to expose a service through an endpoint in WCF.
DataContract is simply a means to send a message to the endpoint (in both
directions).

You say that you want the service app to "do something" with the object.
That's simple, just define a method on your contract that will do something,
and then pass the object to the service through the proxy.

Mind you, all transfers in WCF are pass-by-value, so if you want to
change the object that is sent, then you will have to pass it by ref (WCF
should handle this for you), or return a copy of the object that you use
once it is modified.

Thanks Nicholas,

So which is more efficient: a) to create the object at the client and
then pass the object as a parameter to the service OperationContract? Or
b) call an OperationContract that returns an object (reference) to the
client, fill in the data, then call the "do something" OperationContract?

Thanks,

Bill
Nov 7 '08 #3
Bill,

I would worry more about the design of the service. If the service
creates the object and returns it but the object doesn't need any specific
values set by the service, then this is a bad idea.

If the service doesn't require the values of the object you are passing
to it for the operation you are calling, then that's a bad idea.

Also, you might want to make sure it makes sense to mix your inputs and
outputs like that. It might not make sense from a design standpoint to have
the inputs and outputs mixed on the same object.

Take for example, if you had a method to get the name of the computer
the service is running on. If there is a string parameter that you pass to
it by reference, then that doesn't make sense, since there is no special
initialization of the string that you need to pass to the service.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bill McCormick" <wp*********@newsgroup.nospamwrote in message
news:49************@newsgroup.nospam...
Nicholas Paldino [.NET/C# MVP] wrote:
>Bill,

A DataContract is simply the way that complex constructs are sent
across the wire to endpoints in WCF. It's used to comprise the payload
of the message.

The service contract and operation contract make up the endpoint,
which every service needs. The endpoint is made up of the address of the
service, the binding (which defines things like expectations, like
transactioning, security, etc, etc, as well as protocol), and the
contract, which exposes the operations.

You need all of these to expose a service through an endpoint in WCF.
DataContract is simply a means to send a message to the endpoint (in both
directions).

You say that you want the service app to "do something" with the
object. That's simple, just define a method on your contract that will do
something, and then pass the object to the service through the proxy.

Mind you, all transfers in WCF are pass-by-value, so if you want to
change the object that is sent, then you will have to pass it by ref (WCF
should handle this for you), or return a copy of the object that you use
once it is modified.


Thanks Nicholas,

So which is more efficient: a) to create the object at the client and then
pass the object as a parameter to the service OperationContract? Or b)
call an OperationContract that returns an object (reference) to the
client, fill in the data, then call the "do something" OperationContract?

Thanks,

Bill

Nov 7 '08 #4
Nicholas Paldino [.NET/C# MVP] wrote:
Bill,

I would worry more about the design of the service. If the service
creates the object and returns it but the object doesn't need any specific
values set by the service, then this is a bad idea.

If the service doesn't require the values of the object you are passing
to it for the operation you are calling, then that's a bad idea.

Also, you might want to make sure it makes sense to mix your inputs and
outputs like that. It might not make sense from a design standpoint to have
the inputs and outputs mixed on the same object.

Take for example, if you had a method to get the name of the computer
the service is running on. If there is a string parameter that you pass to
it by reference, then that doesn't make sense, since there is no special
initialization of the string that you need to pass to the service.
Yes, the design is what I'm focusing on at this point (sorry if I didn't
make that clear.) At the risk of appearing slow, I'd like to just follow
up with a sort of confirmation just to make sure that I understand; I
don't want to fly off in the wrong direction. :) Let me provide a little
more background:

A host application will have a number of different WCF services.
ServiceContacts will provide a pair of OperationContracts: one for
sending a collection objects (defined by a CollectionDataContract of
DataContract of class X) and another for retrieving a collection objects
(again, CDC of DC of class X).

So, the design in a nutshell: Both client and host applications will
reference a Service.dll which provides definitions for contracts. When
sending, the client app will create a collection of X, connect to the
service and call OperationContract "A" passing the collection as a
parameter. When receiving, the client app will connect and call an
OperationContract "B" that will return a collection of X.

So, am I starting off in the right direction? Am I missing anything
small or large? Would it be better to split the the Service.dll into
DataContracts.dll and ServiceContracts.dll, where the client app only
uses the DataContracts.dll and the host app uses both?

Thanks,

Bill
Nov 8 '08 #5
Bill,

Well, I would definitely have the data types and the contracts in one
dll. However, by contracts I mean the INTERFACES ONLY. The interface is
the representation of the contract in .NET, not the implementation. That is
separate on your service. The service and the client would share the dll
that has the interfaces and data structures that are passed between client
and service.

However, you don't HAVE to use the same DLL between the client and the
service if you don't want to. If you are publishing your metadata through
Metadata Exchange, then you can have VS.NET connect to your service and
create the proxy and all data types needed automatically. This is the
purpose of DataContract. It allows for objects that are different in the
..NET type system to be equivalent over the wire (this was primarily because
not all communication in WCF is .NET to .NET, so you can't exactly pass an
interface/structure around to a Java client, for example).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bill McCormick" <wp*********@newsgroup.nospamwrote in message
news:up**************@TK2MSFTNGP03.phx.gbl...
Nicholas Paldino [.NET/C# MVP] wrote:
>Bill,

I would worry more about the design of the service. If the service
creates the object and returns it but the object doesn't need any
specific values set by the service, then this is a bad idea.

If the service doesn't require the values of the object you are
passing to it for the operation you are calling, then that's a bad idea.

Also, you might want to make sure it makes sense to mix your inputs
and outputs like that. It might not make sense from a design standpoint
to have the inputs and outputs mixed on the same object.

Take for example, if you had a method to get the name of the computer
the service is running on. If there is a string parameter that you pass
to it by reference, then that doesn't make sense, since there is no
special initialization of the string that you need to pass to the
service.
Yes, the design is what I'm focusing on at this point (sorry if I didn't
make that clear.) At the risk of appearing slow, I'd like to just follow
up with a sort of confirmation just to make sure that I understand; I
don't want to fly off in the wrong direction. :) Let me provide a little
more background:

A host application will have a number of different WCF services.
ServiceContacts will provide a pair of OperationContracts: one for sending
a collection objects (defined by a CollectionDataContract of DataContract
of class X) and another for retrieving a collection objects (again, CDC of
DC of class X).

So, the design in a nutshell: Both client and host applications will
reference a Service.dll which provides definitions for contracts. When
sending, the client app will create a collection of X, connect to the
service and call OperationContract "A" passing the collection as a
parameter. When receiving, the client app will connect and call an
OperationContract "B" that will return a collection of X.

So, am I starting off in the right direction? Am I missing anything small
or large? Would it be better to split the the Service.dll into
DataContracts.dll and ServiceContracts.dll, where the client app only uses
the DataContracts.dll and the host app uses both?

Thanks,

Bill

Nov 11 '08 #6
Nicholas Paldino [.NET/C# MVP] wrote:
Bill,

Well, I would definitely have the data types and the contracts in one
dll. However, by contracts I mean the INTERFACES ONLY. The interface is
the representation of the contract in .NET, not the implementation. That is
separate on your service. The service and the client would share the dll
that has the interfaces and data structures that are passed between client
and service.

However, you don't HAVE to use the same DLL between the client and the
service if you don't want to. If you are publishing your metadata through
Metadata Exchange, then you can have VS.NET connect to your service and
create the proxy and all data types needed automatically. This is the
purpose of DataContract. It allows for objects that are different in the
.NET type system to be equivalent over the wire (this was primarily because
not all communication in WCF is .NET to .NET, so you can't exactly pass an
interface/structure around to a Java client, for example).

OK. Thank you. That is a very clear explanation. I think publishing
Metadata is what I want to do over sharing the class via DLL. I have
been using "Essential WCF" by Steve Resnick et. al. but the section on
Metadata Exchange did not make it very clear how to use it. Juval Löwy's
book "Programming WCF Services" just landed on my desk and seems to have
more/better info; I'll work with that.

Thanks,

Bill
Nov 12 '08 #7


You can see my "separation" technique here:
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!158.entry

.........

Juval's book is one of the best.
My example uses one of his helper libraries.

"Bill McCormick" <wp*********@newsgroup.nospamwrote in message
news:Ow**************@TK2MSFTNGP04.phx.gbl...
Hello cSharpies,

I'm trying to get up to speed with WCF services.

Does a service need to have a ServiceContract/OperationContract to make
use of a DataContract?

I want to have a service that allows a client to create an object in the
service app and have the service app "do something" with the object.
Thanks,

Bill

Nov 12 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

75
by: Howard Nease | last post by:
Hello, everyone. I would appreciate any advice that someone could give me on my future career path. Here is my situation: I am a bright Junior in a very well-respected private high school, taking...
5
by: Martin Piper | last post by:
Hi all. I've recently landed myself the position of trainee C++ programmer which I'm extremely pleased about, but also nervous. According to the feedback from the interview, I have a good...
3
by: Andy Dingley | last post by:
I've just started on a new project and inherited a huge pile of XSLT (and I use the term "pile" advisedly !) It runs at glacial speed, and I need to fix this this. Platform is MSXML 4 / ASP ...
11
by: ma740988 | last post by:
I'm perusing a slide with roughly 12 bullets spread across 3 pages. Each bullet reflects 'advice'. I'm ok with all but 1 bullet, more specifically the bullet that states: " Avoid the STL unless...
6
by: J Rieggle | last post by:
Hi there, I am stuck on a problem that relates to eCommerce sites, but isnt ASP.NET specific (sorry). The ecommerce site is working in the UK, and products will be sold in pounds stirling. ...
13
by: Alan Silver | last post by:
Hello, MSDN (amongst other places) is full of helpful advice on ways to do data access, but they all seem geared to wards enterprise applications. Maybe I'm in a minority, but I don't have those...
7
by: John Paul | last post by:
I'm thinking of building an e-commerce site in php. Anyone got any advice in building one? What is the best way to implement a payment system? Are any legal issues involved? Thanks,
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
3
by: mesut | last post by:
Hi colleagues, I need your advice... I have approx 1,5 years experience with ASP.NET/VB.NET 2005 and I have to switch over into C# 2005 language. I don't have experience with C# 2005...
7
by: SM | last post by:
Hello, I have a index.php template (2 columns). The right columns contains a bunch of links (interviews, poems, etc...) The left columns contains the actual article. So if I click on a link on...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.