Wcf Learning Program

Source: Internet
Author: User

Wcf Learning Program
(1) create a WCF Service

(1) create a WCF Service Class Library

 

Create a project of Class Library:

namespace HelloService{    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IHelloService" in both code and config file together.    [ServiceContract]    public interface IHelloService    {        [OperationContract]        string GetMessage(string name);    }}

 

HelloService. cs:

 

namespace HelloService{    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "HelloService" in both code and config file together.    public class HelloService : IHelloService    {        public string GetMessage(string name)        {            return "Hello " + name;        }    }}

 

(2) create a Host for WCF

Add a new ASP. NET Empty Web Application:

<% @ ServiceHost Language = "C #" Debug = "true" Service = "HelloService. HelloService" %>

Web. config:

 

<?xml version="1.0" encoding="utf-8" ?><configuration>  <system.serviceModel>    <services>      <service name="HelloService.HelloService" behaviorConfiguration="metaBehavior">        <endpoint address="HelloService" binding="basicHttpBinding" contract="HelloService.IHelloService"></endpoint>        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>        

 

Specifically, service name = "namespace. Class name" and behaviorConfiguration are used to associate the definition of behavior below.

The endpoint address defines the relative address, which is the complete address combined with baseAddress.

Endpoint contract = "namespace. Interface Name"

Two endpoints. the first binding is basicHttpBinding for HTTP. The second endpoint is used to exchange metadata, and the binding is mexHttpBinding.

Behavior is defined to allow the exchange of metadata.

 

Build solution. If there are no errors, proceed to the next step and deploy the WCF Service to IIS

 

(2) deploying a WCF Service to IIS

(1) Publish HelloServiceIISHost Project

Private void button#click (object sender, EventArgs e) {HelloService. HelloServiceClient client = new HelloService. HelloServiceClient (); label1.Text = client. GetMessage (textBox1.Text );}

 

Run the Code as follows:

<% @ ServiceHost Language = "C #" Debug = "true" Service = "HelloService. HelloService" %>

 

Service code can be found in

(1) file XXX. svc. cs

(2) An independent Assembly (as in this article)

(3) Under the App_Code folder


What is the learning path of WCF?

When I saw your post, I had a strong resonance, and I also wanted to cry, because I had the same confusion as you, 555 ~ As a post-90 "quasi-programmer", I am most afraid that the wrong direction will delay the future. In the end, after careful consideration, I chose the local code (C/C ++/Win32SDK/MFC) as the main route, supplemented by the managed code (all learning is certainly no harm ). I have little business experience. I 'd like to talk about my own opinions below.

In fact, the biggest conflict with. NET is CLR. Because. NET code must be compiled into an MSIL intermediate language, the JIT real-time compiler in CLR maps the code to machine code during execution. At first glance, it does solve the unified problem of the platform, but it is obviously necessary to reduce the execution efficiency. However, with the role of Moore's Law, the computer performance is greatly improved, which is complementary.

In addition, when a program written in. NET is released, a Runtime Library of several hundred MB is required, which is difficult for users to package in the installation file or download by themselves. To put it bluntly, it will reduce the market competition rate. Unless you have a monopoly on the technology, your software has an irreplaceable position in that field.

The most failed part of. NET is that it cannot run in the core State, at least currently. Although. NET has a "powerful to abnormal class library", the local code has many unique places and the managed code cannot be involved, such as Hook API, process injection, driver development, etc ......

Creating a window with the SDK is complicated. You need to register window classes, message loops, callback functions, and so on. NET. These are transparent and completely ignored.

Objectively speaking,. NET is promising and will become more and more powerful, but there is no hope for. NET in terms of Kernel. Because Windows is not Based on. NET. There are N posts on the Internet that tell me whether C ++/MFC is out of date. To eliminate the cloud, it seems to me that writing programs is not fashionable. As long as Windows is still written using the local code, the local code is "holy ".

To tell the truth, I can't see how good. NET is, but I still have to learn it with my head. It's no harm to both hosting and local learning! It's so painful. As a programmer, It is software. From a layman's point of view, you should understand everything, or even install or pinch a network cable!

By the way, have you read crazy programmers? After reading it, I have had a lot of feelings. Although there are some exaggerated elements, they are difficult in reality ...... Alas ~

I was so excited that I spoke nonsense and didn't even know what I was trying to say! Let me help you, and wait for the experts to eliminate the "Bug" in my mind "~

In fact, I feel that this post will be more suitable for the. NET Development Section sent to the Microsoft Chinese technology forum.

What do I need to learn before learning wcf?

Master the basic C # syntax and understand the architecture and basic principles of wcf, such as the binding endpoint protocol. Based on the online example, let's take a look at it and learn how to develop the http and tcp Protocols in depth.

Related Article

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.