VS self-with WCF Test client introduction

Source: Internet
Author: User

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.