WCF learning essay 3-first sample-sacrifice ax

Source: Internet
Author: User
Yesterday, I was almost depressed. I closed my blog twice in the last window.
For the first time, it was a mouse problem. When you click and double-click frequently, the tag bar of Maxthon was switched off, and ALT + Z was not recovered.
There is also garbage in the Logitech mouse, and there are more than 300 oceans...
The second time is to check other web pages and click "no" to close Maxthon...
[Conclusion] The world is unknown, unpredictable, and unpredictable.
To do things with one mind, backup is always good.

OK, let's go to the first sample!
It uses iis6.0 as the host and ASP. NET as the client for demonstration.

Server

I. Create a new site in IIS named wcf_ax. Port: 1212.
The website attribute is set to run script, otherwise the service cannot be opened. If ASP. net1.1 is installed, the default website value is 1.1, which must be changed to 2.0.
Ii. Open vs2008 and create a new WCF project named wcfservice_ax
Iii. Right-click Project> Publish in the Solution Explorer window
IV. In the pop-up window, enter target location: http: // localhost: 1212 and click Publish.
V. Open IE and enter http: // localhost: 1212/service1.svc.
If the following information is displayed, the release is successful.

You have created a service.

To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:

 
Svcutil.exeHttp: // ****: 1212/service1.svc? WSDL

 

This will generate a configuration file and a code file that contains the client class. Add the two files to your client application and use the generated client class to call the service. For example:

Don't be surprised. The release was successful.CodeI have never written it, because a service has been automatically created during project creation. I will explain it in detail later.

Client

I. Open vs2008 and create a new website. Name it website_ax
Ii. Right-click Project> Add service reference in the Solution Explorer window.
Iii. Enter http: // localhost: 1212/service1.svc at address and click "go ".
A few seconds later, you will find the service and click OK.
Iv. Enter the following two lines of code in default. aspx. CS. Protected   Void Page_load ( Object Sender, eventargs E)
{
// Create a service1 proxy
Servicereference1.iservice1 Service =   New Servicereference1.service1client ();
// Use proxy
Response. Write (service. getdata ( 1212 ));
}

V. F5 run.
If the page is displayed :【You entered: 1212] Indicates that the service is successfully called!

Blog garden → axe to help Shao Zhu

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.