Using WCF Services from 2.0 programs


G

GaryDean

Exercises in the WCF book I'm going through (Essential WCF) 1st has you
create a WCF Service
(pasted first below) then a WCF client (pasted second below). These both
work fine with no
surprises.

As you can see, the signature of the method is : public double
GetPrice(string ticker)


Outside the exercises in the book I wanted to see how .net 2.0 clients would
work
with the WCF service so I created a windows forms program (pasted third
below) in VS2005
and added a "web reference" to the WCF Service. However, in that wsdl the
signature of
the method was :
public void GetPrice(string ticker, out double GetPriceResult, out bool
GetResultPriceSpecified)

My question is : Why is the signature changed when the web reference is
added by a 2.0 program?
Thanks,
Gary


WCF
SERVICE ------------------------------------------------------------------------

using System;
using System.ServiceModel;

namespace EssentialWCF
{

[ServiceContract]
public interface IStockService
{
[OperationContract]
double GetPrice(string ticker); // C, the contract
}
public class StockService : IStockService
{
public double GetPrice(string ticker)
{
return 94.85;
}
}

public class service
{
public static void Main()
{
ServiceHost serviceHost = new ServiceHost(typeof(StockService));
serviceHost.Open();
Console.WriteLine("Press <ENTER> to terminate.\n\n");
Console.ReadLine();
serviceHost.Close();
}
}
}

END WCF
SERVICE---------------------------------------------------------------------

WCF
CLIENT--------------------------------------------------------------------------
using System;
using System.ServiceModel;

namespace EssentialWCF
{
class Client
{
static void Main(string[] args)
{

wcf07client.ServiceReference.StockServiceClient proxy = new
wcf07client.ServiceReference.StockServiceClient();
double p = proxy.GetPrice("msft");
Console.WriteLine("Price:{0}", p);
proxy.Close();
Console.ReadLine();
}
}
}
END WCF
CLIENT----------------------------------------------------------------------

2.0 Web Service
Client--------------------------------------------------------------
using System;
using System.Windows.Forms;
namespace client2005
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)
{
localhost.StockService myStockService = new
client2005.localhost.StockService();
bool mybool = false;
double p = 0;
myStockService.GetPrice("msft", out p, out mybool);
<-------------- 3 Args!!
lblPrice.Text = p.ToString("c");
}
}
}
 
Ad

Advertisements

S

Steven Cheng

Hi Gary,

As for the signature of the auto-generated webservice proxy, I've also ever
noticed such behavior as you mentioned. It seems due to some internal
implemetation of the service proxy generator. It will prefer using an
output parameter instead of return value when the service method return a
simple primitive type object. If you return a complex class object(such as
your custom class), it will define it as return value by default. Anyway,
both signature is the same, there is no particular difference. Just like,
if you add reference in other platform/language(such as java or c++), the
behavior might also differ from the .NET client one.

BTW, since .NET 2.0 client proxy is webservice client proxy, you need to
make sure the server-side WCF service use a webservice compatible
binding(with Text encoding message format). Many high performance binding
in WCF use binary format by default(such as NetTcpBinding ...).

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: "GaryDean" <[email protected]>
Subject: Using WCF Services from 2.0 programs
Date: Sun, 21 Sep 2008 16:51:39 -0700
Exercises in the WCF book I'm going through (Essential WCF) 1st has you
create a WCF Service
(pasted first below) then a WCF client (pasted second below). These both
work fine with no
surprises.

As you can see, the signature of the method is : public double
GetPrice(string ticker)


Outside the exercises in the book I wanted to see how .net 2.0 clients would
work
with the WCF service so I created a windows forms program (pasted third
below) in VS2005
and added a "web reference" to the WCF Service. However, in that wsdl the
signature of
the method was :
public void GetPrice(string ticker, out double GetPriceResult, out bool
GetResultPriceSpecified)

My question is : Why is the signature changed when the web reference is
added by a 2.0 program?
Thanks,
Gary


WCF
SERVICE ------------------------------------------------------------------------

using System;
using System.ServiceModel;

namespace EssentialWCF
{

[ServiceContract]
public interface IStockService
{
[OperationContract]
double GetPrice(string ticker); // C, the contract
}
public class StockService : IStockService
{
public double GetPrice(string ticker)
{
return 94.85;
}
}

public class service
{
public static void Main()
{
ServiceHost serviceHost = new ServiceHost(typeof(StockService));
serviceHost.Open();
Console.WriteLine("Press <ENTER> to terminate.\n\n");
Console.ReadLine();
serviceHost.Close();
}
}
}

END WCF
SERVICE-------------------------------------------------------------------- -
WCF
CLIENT---------------------------------------------------------------------
-----
using System;
using System.ServiceModel;

namespace EssentialWCF
{
class Client
{
static void Main(string[] args)
{

wcf07client.ServiceReference.StockServiceClient proxy = new
wcf07client.ServiceReference.StockServiceClient();
double p = proxy.GetPrice("msft");
Console.WriteLine("Price:{0}", p);
proxy.Close();
Console.ReadLine();
}
}
}
END WCF
CLIENT--------------------------------------------------------------------- -

2.0 Web Service
Client--------------------------------------------------------------
using System;
using System.Windows.Forms;
namespace client2005
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)
{
localhost.StockService myStockService = new
client2005.localhost.StockService();
bool mybool = false;
double p = 0;
myStockService.GetPrice("msft", out p, out mybool);
<-------------- 3 Args!!
lblPrice.Text = p.ToString("c");
}
}
}
--------------------------------------------------------------------------- ------

--
Regards,
Gary Blakely
Dean Blakely & Associates
www.deanblakely.com
 
G

GaryDean

Steven:
I'm using basicHttpBinding. But the signature is not at all the same.
There is another argument added : out boolso I have to understand what is going on here at some point.

--
Regards,
Gary Blakely
Dean Blakely & Associates
www.deanblakely.com
"Steven Cheng" said:
Hi Gary,

As for the signature of the auto-generated webservice proxy, I've also
ever
noticed such behavior as you mentioned. It seems due to some internal
implemetation of the service proxy generator. It will prefer using an
output parameter instead of return value when the service method return a
simple primitive type object. If you return a complex class object(such
as
your custom class), it will define it as return value by default. Anyway,
both signature is the same, there is no particular difference. Just like,
if you add reference in other platform/language(such as java or c++), the
behavior might also differ from the .NET client one.

BTW, since .NET 2.0 client proxy is webservice client proxy, you need to
make sure the server-side WCF service use a webservice compatible
binding(with Text encoding message format). Many high performance binding
in WCF use binary format by default(such as NetTcpBinding ...).

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
--------------------
From: "GaryDean" <[email protected]>
Subject: Using WCF Services from 2.0 programs
Date: Sun, 21 Sep 2008 16:51:39 -0700
Exercises in the WCF book I'm going through (Essential WCF) 1st has you
create a WCF Service
(pasted first below) then a WCF client (pasted second below). These both
work fine with no
surprises.

As you can see, the signature of the method is : public double
GetPrice(string ticker)


Outside the exercises in the book I wanted to see how .net 2.0 clients would
work
with the WCF service so I created a windows forms program (pasted third
below) in VS2005
and added a "web reference" to the WCF Service. However, in that wsdl the
signature of
the method was :
public void GetPrice(string ticker, out double GetPriceResult, out bool
GetResultPriceSpecified)

My question is : Why is the signature changed when the web reference is
added by a 2.0 program?
Thanks,
Gary


WCF
SERVICE ------------------------------------------------------------------------

using System;
using System.ServiceModel;

namespace EssentialWCF
{

[ServiceContract]
public interface IStockService
{
[OperationContract]
double GetPrice(string ticker); // C, the contract
}
public class StockService : IStockService
{
public double GetPrice(string ticker)
{
return 94.85;
}
}

public class service
{
public static void Main()
{
ServiceHost serviceHost = new ServiceHost(typeof(StockService));
serviceHost.Open();
Console.WriteLine("Press <ENTER> to terminate.\n\n");
Console.ReadLine();
serviceHost.Close();
}
}
}

END WCF
SERVICE-------------------------------------------------------------------- -
WCF
CLIENT---------------------------------------------------------------------
-----
using System;
using System.ServiceModel;

namespace EssentialWCF
{
class Client
{
static void Main(string[] args)
{

wcf07client.ServiceReference.StockServiceClient proxy = new
wcf07client.ServiceReference.StockServiceClient();
double p = proxy.GetPrice("msft");
Console.WriteLine("Price:{0}", p);
proxy.Close();
Console.ReadLine();
}
}
}
END WCF
CLIENT--------------------------------------------------------------------- -

2.0 Web Service
Client--------------------------------------------------------------
using System;
using System.Windows.Forms;
namespace client2005
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)
{
localhost.StockService myStockService = new
client2005.localhost.StockService();
bool mybool = false;
double p = 0;
myStockService.GetPrice("msft", out p, out mybool);
<-------------- 3 Args!!
lblPrice.Text = p.ToString("c");
}
}
}
--------------------------------------------------------------------------- ------

--
Regards,
Gary Blakely
Dean Blakely & Associates
www.deanblakely.com
 
S

Steven Cheng

Thanks for your reply Gary,

As for the additional parameter, it is also a particular implementation of
the .NET webservice client proxy. As I've mentioned in previous reply, the
case is that the return object in your webmethod (wcf method) is of
primitive type(a value type instead of a reference type). Thus, the client
cannot determine whether the server-side has set an intial value or not(via
using if(obj == Null)). Therefore, it add an additional parameter like
"xxxSpecified" to indicate this.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
From: "GaryDean" <[email protected]>
References: <[email protected]>
 
G

GaryDean

ok, that makes perfect sense that the bool is needed to tell if the return
is null. Then why isn't this also necessary for the WCF client?
Gary
 
Ad

Advertisements

S

Steven Cheng

WCF make such control(over the generating of client proxy's serializatino
class) up to you. So it will not automatically generate such properties, if
you want to use the same approach, you can manually add such
properties/fields. Anyway, it depends on different developers's
preference, sometimes such automatic field generation is prefered by some
ones while someone elses may not quite like it.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top