C # Create, deploy, Invoke WebService

Source: Internet
Author: User

WebService can be used for interactions between distributed applications, and for interactions between different programs.

The conceptual stuff doesn't say much, here's an example of creating a simple webservice. Here I am using Visual Studio 2015 development tools.

First, create an empty Web application.

Then right-click on the project and select Add > New Item.

Select Web Service and click Add. A simple webservice is created, and the next two simple methods are written.

PS: If the method needs to be called through the WebService address, it must be labeled on the method [WebMethod], otherwise it cannot be accessed through WebService. Description is a description of the method.

Then run, you can see the method, access to WebService can be based on the Address bar address to call the WebService method.

But how does this make other applications accessible over the network? Then it needs to be deployed to the server.

The following demo I was deployed on this machine, but the same is true for server deployment. Web site deployment requires IIS, which I have opened and, if not, can be turned on by Start menu > Control Panel > Programs > Enable or disable Windows features. Specific can be searched on the Internet, here do not do too much introduction.

After you turn on IIS, post the webservice that you just made, and then open IIS Manager.

Select Custom, enter a profile name, and then click Next.

Then select how you publish and the path to the publication, and then click Next.

Settings do not change, continue to the next step. then click Publish.

This completes the release, now open IIS Manager, then select Web site and click Add Site.

Enter the name of the website, the IP address (the computer can not enter an IP address) and port, select the path of the file, and then click OK, the site is created.

Of course, it is not necessarily immediately available, there will be a lot of errors, here are some of the errors I encountered and some solutions.

This error is due to insufficient access to the file. The workaround is to click Edit Permissions.

Then select the Security bar and click Edit.

Then click Add a user and set the permission to allow. Or use the following method:

Select the website, then check authentication and click Basic Settings.

Select Connect As.

Then select a specific user, click Settings, enter the user name and password of the computer, click OK. You can then click on the test settings to see the effect.

The reason for this error is that after the framework v4.0 is installed, IIS is enabled, causing the framework to not be fully installed.

The workaround is: Start menu > Command Prompt (Administrator), and then enter and execute the%windir%\microsoft.net\framework\v4.0.30319\aspnet_regiis.exe-i command line.

The problem is that because of the application pool settings, the application pool is not selected when the new site is started, the default is v2.0 version, and the Framework 4.5 is not supported.

The workaround is to select the application pool and then change to the v4.0 version, and the pipeline mode is set to integrated.

The reason for this error is because the TEMP directory under the system directory does not have the appropriate permissions.

The workaround is to go to the Temp directory under the C-drive Windows directory, right-click Properties > Security Bar > Edit > Iis_iusrs permissions to Full control.

The reason for this error is that the default document for the Web site is not configured.

The workaround is to select the site, click the default document, and then add a default page, the application's start page.

Then, after dealing with a number of problems, the deployment was finally successful.

Next, you'll get a simple webservice invocation example.

Add a console application first, then right-click Reference, and select Add Service Reference.

Click Advanced, then click Add Web Reference on the pop-up page.

Enter the deployed Web site address in the URL bar, then click Go to see the following method content, then enter the Web reference name and click Add Reference.

When the reference is added, the webservice is called below.

The results are as follows:

Original link: http://www.cnblogs.com/Brambling/p/6815565.html

C # Create, deploy, Invoke WebService

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.