473,406 Members | 2,849 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,406 software developers and data experts.

How to determine datatype returned from WCF method.

I am a newbie to WCF so please forgive if this is an obvious question.

I have the following.

(Service contract) IEmployee
[ServiceContract()]
public interface IEmployee
{
[OperationContract]
List<EmployeeGetEmployeeByID(string employeeID);
}

(DataContract) Employee
Basic everyday class with properties and constructor to populate
properties.( nothing special )

I have a service.svc file that implements the IEmployee Contract.
In the GetEmployeeByID method I query the DB and return one or more records
into a Reader.
I loop over the reader populating the Employee object.

List<BasicEmployeeempList = new List<BasicEmployee>();

using (SqlConnection conn = new SqlConnection(this.Con))
{
SqlCommand cmd = new SqlCommand("GetEmployeeByEmployeeID", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@ID", employeeID);

conn.Open();
SqlDataReader reader = cmd.ExecuteReader();

while (reader.Read())
{
empList.Add(new
BasicEmployee(reader["EmployeeID"].ToString(),
reader["FirstName"].ToString(), reader["LastName"].ToString(),
reader["MiddleName"].ToString(),reader["Suffix"].ToString(),
reader["SupervisorID"].ToString(),
reader["Email"].ToString(), reader["Title"].ToString()));
}
conn.Close();
return empList;
}

On the Consumer side I am able to create the proxy and call the method.
However, how does one figure out what the return typ is???. I did not see in
the SWDL file that the return type is a List<[service class].Employee>
object.

In building this I followed one of the WCF labs and modified to meet my
needs.
Is this the correct way to return data?

Other people on my team will be using this and they need to figure out what
is being returned (when I am hit by the preverbial bus and am laying in a
comma  )

Mar 12 '07 #1
4 2960
In this case the type of return will be an array of Emplyee (Employee[]).
"Greg" <Gr**@discussions.microsoft.comwrote in message
news:4B**********************************@microsof t.com...
>I am a newbie to WCF so please forgive if this is an obvious question.

I have the following.

(Service contract) IEmployee
[ServiceContract()]
public interface IEmployee
{
[OperationContract]
List<EmployeeGetEmployeeByID(string employeeID);
}

(DataContract) Employee
Basic everyday class with properties and constructor to populate
properties.( nothing special )

I have a service.svc file that implements the IEmployee Contract.
In the GetEmployeeByID method I query the DB and return one or more
records
into a Reader.
I loop over the reader populating the Employee object.

List<BasicEmployeeempList = new List<BasicEmployee>();

using (SqlConnection conn = new SqlConnection(this.Con))
{
SqlCommand cmd = new SqlCommand("GetEmployeeByEmployeeID",
conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@ID", employeeID);

conn.Open();
SqlDataReader reader = cmd.ExecuteReader();

while (reader.Read())
{
empList.Add(new
BasicEmployee(reader["EmployeeID"].ToString(),
reader["FirstName"].ToString(), reader["LastName"].ToString(),
reader["MiddleName"].ToString(),reader["Suffix"].ToString(),
reader["SupervisorID"].ToString(),
reader["Email"].ToString(), reader["Title"].ToString()));
}
conn.Close();
return empList;
}

On the Consumer side I am able to create the proxy and call the method.
However, how does one figure out what the return typ is???. I did not see
in
the SWDL file that the return type is a List<[service class].Employee>
object.

In building this I followed one of the WCF labs and modified to meet my
needs.
Is this the correct way to return data?

Other people on my team will be using this and they need to figure out
what
is being returned (when I am hit by the preverbial bus and am laying in a
comma  )
Mar 13 '07 #2
Thanks for your quick response. However..... I still don't know how one would
determin that a generic List object was being returned.

Yes it would. to be more specific it would be a 'List<myService.Employee>'

once i implement the service and call the GetEmployeeByID i get the
intellesense stating that the return is an Employee[ ]. To be more specific
it is an myService.Employee [] (myService was the name that i used in the
creation of the proxy) and I am assuming that i would need to cast that to a
List<myService.Employeeobject. At least that is what the hands on lab did.

so my question still stands. how would I as a person who was just told that
there was a web service that was on the company web services server;"Just add
a 'Service Reference' using http:/ourserver/ERPServices/service.svc?wsdl".
there is a method that you can use that will return employee information
based on there employee id.

How would i know that i would need to cast this as a Generic object...... or
would I ??

"Mariano Omar Rodriguez" wrote:
In this case the type of return will be an array of Emplyee (Employee[]).
"Greg" <Gr**@discussions.microsoft.comwrote in message
news:4B**********************************@microsof t.com...
I am a newbie to WCF so please forgive if this is an obvious question.

I have the following.

(Service contract) IEmployee
[ServiceContract()]
public interface IEmployee
{
[OperationContract]
List<EmployeeGetEmployeeByID(string employeeID);
}

(DataContract) Employee
Basic everyday class with properties and constructor to populate
properties.( nothing special )

I have a service.svc file that implements the IEmployee Contract.
In the GetEmployeeByID method I query the DB and return one or more
records
into a Reader.
I loop over the reader populating the Employee object.

List<BasicEmployeeempList = new List<BasicEmployee>();

using (SqlConnection conn = new SqlConnection(this.Con))
{
SqlCommand cmd = new SqlCommand("GetEmployeeByEmployeeID",
conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@ID", employeeID);

conn.Open();
SqlDataReader reader = cmd.ExecuteReader();

while (reader.Read())
{
empList.Add(new
BasicEmployee(reader["EmployeeID"].ToString(),
reader["FirstName"].ToString(), reader["LastName"].ToString(),
reader["MiddleName"].ToString(),reader["Suffix"].ToString(),
reader["SupervisorID"].ToString(),
reader["Email"].ToString(), reader["Title"].ToString()));
}
conn.Close();
return empList;
}

On the Consumer side I am able to create the proxy and call the method.
However, how does one figure out what the return typ is???. I did not see
in
the SWDL file that the return type is a List<[service class].Employee>
object.

In building this I followed one of the WCF labs and modified to meet my
needs.
Is this the correct way to return data?

Other people on my team will be using this and they need to figure out
what
is being returned (when I am hit by the preverbial bus and am laying in a
comma  )
Mar 13 '07 #3
When you generate a proxy with "Add service reference" all types that
implement ICollection a returned as arrays, if the ICollection is one of the
generic type it returns an array of that type, in other hand return an array
of object.

Other types that are decorated with DataContract and DataMember are
regenerated in the proxy (as other class different of the original), the
proxy only generate fields and properties that are decorated with
DataMember.

I hope that your dobts be clarified now.

"Greg" <Gr**@discussions.microsoft.comwrote in message
news:43**********************************@microsof t.com...
Thanks for your quick response. However..... I still don't know how one
would
determin that a generic List object was being returned.

Yes it would. to be more specific it would be a
'List<myService.Employee>'

once i implement the service and call the GetEmployeeByID i get the
intellesense stating that the return is an Employee[ ]. To be more
specific
it is an myService.Employee [] (myService was the name that i used in the
creation of the proxy) and I am assuming that i would need to cast that to
a
List<myService.Employeeobject. At least that is what the hands on lab
did.

so my question still stands. how would I as a person who was just told
that
there was a web service that was on the company web services server;"Just
add
a 'Service Reference' using http:/ourserver/ERPServices/service.svc?wsdl".
there is a method that you can use that will return employee information
based on there employee id.

How would i know that i would need to cast this as a Generic object......
or
would I ??

"Mariano Omar Rodriguez" wrote:
>In this case the type of return will be an array of Emplyee (Employee[]).
"Greg" <Gr**@discussions.microsoft.comwrote in message
news:4B**********************************@microso ft.com...
>I am a newbie to WCF so please forgive if this is an obvious question.

I have the following.

(Service contract) IEmployee
[ServiceContract()]
public interface IEmployee
{
[OperationContract]
List<EmployeeGetEmployeeByID(string employeeID);
}

(DataContract) Employee
Basic everyday class with properties and constructor to populate
properties.( nothing special )

I have a service.svc file that implements the IEmployee Contract.
In the GetEmployeeByID method I query the DB and return one or more
records
into a Reader.
I loop over the reader populating the Employee object.

List<BasicEmployeeempList = new List<BasicEmployee>();

using (SqlConnection conn = new SqlConnection(this.Con))
{
SqlCommand cmd = new SqlCommand("GetEmployeeByEmployeeID",
conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@ID", employeeID);

conn.Open();
SqlDataReader reader = cmd.ExecuteReader();

while (reader.Read())
{
empList.Add(new
BasicEmployee(reader["EmployeeID"].ToString(),
reader["FirstName"].ToString(), reader["LastName"].ToString(),
reader["MiddleName"].ToString(),reader["Suffix"].ToString(),
reader["SupervisorID"].ToString(),
reader["Email"].ToString(), reader["Title"].ToString()));
}
conn.Close();
return empList;
}

On the Consumer side I am able to create the proxy and call the method.
However, how does one figure out what the return typ is???. I did not
see
in
the SWDL file that the return type is a List<[service class].Employee>
object.

In building this I followed one of the WCF labs and modified to meet my
needs.
Is this the correct way to return data?

Other people on my team will be using this and they need to figure out
what
is being returned (when I am hit by the preverbial bus and am laying in
a
comma  )
Mar 13 '07 #4
I understand all that.

So i guess the answer to my questions concerning how would someone know what
is being returned from a Web Service Method would be for users to implement
the web service, call the method and see what is being returned????????

It was my belief that one would be able to view a WSDL file to see all
methods that are exposed AND be able to determine what is being returned.

Seems a waist of time to go through implementing the webservice just to find
out what data structure is being returned, Or am I missing something

"Mariano Omar Rodriguez" wrote:
When you generate a proxy with "Add service reference" all types that
implement ICollection a returned as arrays, if the ICollection is one of the
generic type it returns an array of that type, in other hand return an array
of object.

Other types that are decorated with DataContract and DataMember are
regenerated in the proxy (as other class different of the original), the
proxy only generate fields and properties that are decorated with
DataMember.

I hope that your dobts be clarified now.

"Greg" <Gr**@discussions.microsoft.comwrote in message
news:43**********************************@microsof t.com...
Thanks for your quick response. However..... I still don't know how one
would
determin that a generic List object was being returned.

Yes it would. to be more specific it would be a
'List<myService.Employee>'

once i implement the service and call the GetEmployeeByID i get the
intellesense stating that the return is an Employee[ ]. To be more
specific
it is an myService.Employee [] (myService was the name that i used in the
creation of the proxy) and I am assuming that i would need to cast that to
a
List<myService.Employeeobject. At least that is what the hands on lab
did.

so my question still stands. how would I as a person who was just told
that
there was a web service that was on the company web services server;"Just
add
a 'Service Reference' using http:/ourserver/ERPServices/service.svc?wsdl".
there is a method that you can use that will return employee information
based on there employee id.

How would i know that i would need to cast this as a Generic object......
or
would I ??

"Mariano Omar Rodriguez" wrote:
In this case the type of return will be an array of Emplyee (Employee[]).
"Greg" <Gr**@discussions.microsoft.comwrote in message
news:4B**********************************@microsof t.com...
I am a newbie to WCF so please forgive if this is an obvious question.

I have the following.

(Service contract) IEmployee
[ServiceContract()]
public interface IEmployee
{
[OperationContract]
List<EmployeeGetEmployeeByID(string employeeID);
}

(DataContract) Employee
Basic everyday class with properties and constructor to populate
properties.( nothing special )

I have a service.svc file that implements the IEmployee Contract.
In the GetEmployeeByID method I query the DB and return one or more
records
into a Reader.
I loop over the reader populating the Employee object.

List<BasicEmployeeempList = new List<BasicEmployee>();

using (SqlConnection conn = new SqlConnection(this.Con))
{
SqlCommand cmd = new SqlCommand("GetEmployeeByEmployeeID",
conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@ID", employeeID);

conn.Open();
SqlDataReader reader = cmd.ExecuteReader();

while (reader.Read())
{
empList.Add(new
BasicEmployee(reader["EmployeeID"].ToString(),
reader["FirstName"].ToString(), reader["LastName"].ToString(),
reader["MiddleName"].ToString(),reader["Suffix"].ToString(),
reader["SupervisorID"].ToString(),
reader["Email"].ToString(), reader["Title"].ToString()));
}
conn.Close();
return empList;
}

On the Consumer side I am able to create the proxy and call the method.
However, how does one figure out what the return typ is???. I did not
see
in
the SWDL file that the return type is a List<[service class].Employee>
object.

In building this I followed one of the WCF labs and modified to meet my
needs.
Is this the correct way to return data?

Other people on my team will be using this and they need to figure out
what
is being returned (when I am hit by the preverbial bus and am laying in
a
comma  )

Mar 14 '07 #5

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

Similar topics

17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
8
by: n8wrl | last post by:
Good afternoon! I have a method that adds a SQL parameter with the right SQLtype based on a CLR type: public void AddParam<T>(string name, T value) { ... }
15
by: Bob | last post by:
I'm about to convert to string and use regex, but I thought there must be something I'm missing here that already exists. Bob
1
by: Savas Ates | last post by:
I have a column in my table BizdekiFiyat . The datatype = float length =8 (to save money values).. It is impossible to change these attributes for some reasons. It has records like This ...
2
by: Johannes | last post by:
When you do a webrequest like: Dim objWebRequest As WebRequest = WebRequest.Create(objURI) the returned class can be httpwebrequest, ftpwebrequest or any othe descendant webrequest type that is...
13
by: CJM | last post by:
I have an ASP/ADO application querying an SQL Server DB. I want know the most efficient way to determine if more than one row is returned from a query. If more than one row is returned, the user...
2
by: Ben Joyce | last post by:
Hi all. I'm confused as to what the best or expected approch is to Web Service design under .Net, mainly with regards to Methods and Parameters. This is a bit awkward to explain so please bear...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.