In the current two development projects, some information is placed in the customer, only to give you a service address, do not know what the specific method, each time you want to call a service does not know whether to achieve the current needs, can only test. Write a test program is really not, take up time not to say, and you have been busy all morning, found that the service, is not what you want. Only the white is busy ... Here's a quick overview of how to use the VS self Test client from your co-workers. The operation is very simple, but very practical. Know this, needless to say, this article is to help those who do not know the small partner ...
A simple WCF service-side:
Contract:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using System.ServiceModel;
Namespace Wolfy.contract
{
[ServiceContract (namespace= "http://www.wolfy.com")] public
interface ICalculator
{
[OperationContract]
double Add (double x,double y);
}
Service:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using Wolfy.contract;
Namespace Wolfy.service
{public
class Calculatorservice:icalculator
{
#region ICalculator member Public
Double Add (double x, double y)
{return
x + y;
}
#endregion
}
}
The console is used to host the service.
Console Code Open Service:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using Wolfy.contract;
Using Wolfy.service;
Using System.ServiceModel;
Namespace Wolfy.server
{
class program
{
static void Main (string[] args)
{
using ( ServiceHost host = new ServiceHost (typeof (CalculatorService)))
{
host. Opened + + = Delegate
{
Console.WriteLine ("CalculatorService has started, press any key to stop service");
Host. Open ();
Console.read ();}}}
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/net/