473,624 Members | 2,119 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
{
[OperationContra ct]
List<EmployeeGe tEmployeeByID(s tring 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<BasicEmplo yeeempList = new List<BasicEmplo yee>();

using (SqlConnection conn = new SqlConnection(t his.Con))
{
SqlCommand cmd = new SqlCommand("Get EmployeeByEmplo yeeID", conn);
cmd.CommandType = CommandType.Sto redProcedure;
cmd.Parameters. AddWithValue("@ ID", employeeID);

conn.Open();
SqlDataReader reader = cmd.ExecuteRead er();

while (reader.Read())
{
empList.Add(new
BasicEmployee(r eader["EmployeeID "].ToString(),
reader["FirstName"].ToString(), reader["LastName"].ToString(),
reader["MiddleName "].ToString(),rea der["Suffix"].ToString(),
reader["Supervisor ID"].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 2972
In this case the type of return will be an array of Emplyee (Employee[]).
"Greg" <Gr**@discussio ns.microsoft.co mwrote in message
news:4B******** *************** ***********@mic rosoft.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
{
[OperationContra ct]
List<EmployeeGe tEmployeeByID(s tring 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<BasicEmplo yeeempList = new List<BasicEmplo yee>();

using (SqlConnection conn = new SqlConnection(t his.Con))
{
SqlCommand cmd = new SqlCommand("Get EmployeeByEmplo yeeID",
conn);
cmd.CommandType = CommandType.Sto redProcedure;
cmd.Parameters. AddWithValue("@ ID", employeeID);

conn.Open();
SqlDataReader reader = cmd.ExecuteRead er();

while (reader.Read())
{
empList.Add(new
BasicEmployee(r eader["EmployeeID "].ToString(),
reader["FirstName"].ToString(), reader["LastName"].ToString(),
reader["MiddleName "].ToString(),rea der["Suffix"].ToString(),
reader["Supervisor ID"].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.Emplo yee [] (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?wsd l".
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**@discussio ns.microsoft.co mwrote in message
news:4B******** *************** ***********@mic rosoft.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
{
[OperationContra ct]
List<EmployeeGe tEmployeeByID(s tring 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<BasicEmplo yeeempList = new List<BasicEmplo yee>();

using (SqlConnection conn = new SqlConnection(t his.Con))
{
SqlCommand cmd = new SqlCommand("Get EmployeeByEmplo yeeID",
conn);
cmd.CommandType = CommandType.Sto redProcedure;
cmd.Parameters. AddWithValue("@ ID", employeeID);

conn.Open();
SqlDataReader reader = cmd.ExecuteRead er();

while (reader.Read())
{
empList.Add(new
BasicEmployee(r eader["EmployeeID "].ToString(),
reader["FirstName"].ToString(), reader["LastName"].ToString(),
reader["MiddleName "].ToString(),rea der["Suffix"].ToString(),
reader["Supervisor ID"].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**@discussio ns.microsoft.co mwrote in message
news:43******** *************** ***********@mic rosoft.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.Emplo yee [] (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?wsd l".
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**@discussio ns.microsoft.co mwrote in message
news:4B******* *************** ************@mi crosoft.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
{
[OperationContra ct]
List<EmployeeGe tEmployeeByID(s tring 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<BasicEmplo yeeempList = new List<BasicEmplo yee>();

using (SqlConnection conn = new SqlConnection(t his.Con))
{
SqlCommand cmd = new SqlCommand("Get EmployeeByEmplo yeeID",
conn);
cmd.CommandType = CommandType.Sto redProcedure;
cmd.Parameters. AddWithValue("@ ID", employeeID);

conn.Open();
SqlDataReader reader = cmd.ExecuteRead er();

while (reader.Read())
{
empList.Add(new
BasicEmployee(r eader["EmployeeID "].ToString(),
reader["FirstName"].ToString(), reader["LastName"].ToString(),
reader["MiddleName "].ToString(),rea der["Suffix"].ToString(),
reader["Supervisor ID"].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**@discussio ns.microsoft.co mwrote in message
news:43******** *************** ***********@mic rosoft.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.Emplo yee [] (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?wsd l".
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**@discussio ns.microsoft.co mwrote in message
news:4B******** *************** ***********@mic rosoft.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
{
[OperationContra ct]
List<EmployeeGe tEmployeeByID(s tring 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<BasicEmplo yeeempList = new List<BasicEmplo yee>();

using (SqlConnection conn = new SqlConnection(t his.Con))
{
SqlCommand cmd = new SqlCommand("Get EmployeeByEmplo yeeID",
conn);
cmd.CommandType = CommandType.Sto redProcedure;
cmd.Parameters. AddWithValue("@ ID", employeeID);

conn.Open();
SqlDataReader reader = cmd.ExecuteRead er();

while (reader.Read())
{
empList.Add(new
BasicEmployee(r eader["EmployeeID "].ToString(),
reader["FirstName"].ToString(), reader["LastName"].ToString(),
reader["MiddleName "].ToString(),rea der["Suffix"].ToString(),
reader["Supervisor ID"].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
6134
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. "Decimal Number" sometimes serves to distinguish Base 10 numbers, eg "15", from Base 2 numbers, Eg "1111". At other times "Decimal Number" serves to differentiate a number from an integer. For the rest of this post I shall only use either...
8
1450
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
20086
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
1420
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 BizdekiFiyat 110 24 29.5
2
1708
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 registered on the system. How can I determine which type is returned. I tried if (objWebRequest is System.Net.HttpWebRequest) then ..... But the system says I am not allowed to use types in expressions. --
13
2341
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 will be presented with a choice of which row to process. If only one row is returned, I want to skip this stage, and process that single row immediately. I can think of a number of ways of acheiving this (eg. .recordcount) but I'm looking for the...
2
5629
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 with me. I have a web service that needs to be accessed via GET, POST and SOAP. The method expects an interger, a CustomerId for example, does some processing and returns an error codeor 0 if no errors occurred.
0
8234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8172
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8677
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8620
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7158
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, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6110
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.