To friends who are new to Web Services

Source: Internet
Author: User

V.After a break, the csdnTechnical CommunityThere is a long post (The author is the legendary Chinese ID that post address http://community.csdn.net/Expert/topic/3683/3683411.xml? Temp =. 369076) came first. Let's take a look at the topic about flash interception of Web Service exception messages. Turn around to see a URL (http://www.blueidea.com/tech/multimedia/2003/1216.asp), open to see, is about how Flash web service application. I was interested in interaction, so I started learning about my web service.

In the course of study, I had the following gains: although they are all small and small problems, I just got in touch with it and no guidance was given, so I felt a sense of accomplishment. (PS: Who threw the dish ?) Pai_^

1. Services are stored in the site root directory

Start to write an asmx file in the sub-folder under the root directory of the default site, however, when you open the test in a browser, the word "compile start" appears in the footer of the page. An error occurred while viewing the WSDL:

The XML page cannot be displayed.

You cannot view XML input using a style sheet. Correct the error and click Refresh or try again later.

--------------------------------------------------------------------------------

The top-level of the document is invalid. Processing resource 'HTTP: // localhost/WebService/test. asmx? Error in WSDL. Row 1st, Location: 1

Compilation starts... <br> <? XML version = "1.0" encoding = "UTF-8"?>

^

At first, I thought that the file was not compiled. It may need to be processed by the WSDL tool, so I went to the WSDL tool. (I found that there was no place on the Internet to download the WSDL tool, which caused me to download the SDK toolkit, 555...) the same error occurred when using the WSDL to process it. It was very depressing !!! Why? Looking for csdn is fruitless. When there is no clue, it seems that you should remember that there is a place where services are best to be called by others. Of course, it is best to be the root directory. Try it. There is no solution anyway. First, set the service folder as the site root directory. After all the settings are completed, it is an exciting time to ask for access. Haha, the words "compilation starts and ends" are missing. Is it successful? Check the WSDL. It is also displayed normally. Come on, use flash to call it. Try it. It's successful, yeah! A sense of accomplishment! Pai_^

2. Make good use of namespaces

There is an Access database access action in that service, and the server is written according to the previously used action. mappath. After the test is completed, an error is found. "The server class is not declared." In this service, only the following references are provided: Imports systemimports system. web. servicesimports system. dataimports system. data. oledbcsdn is good. After searching for half a day, I finally found the server namespace and added it: Imports system. web. why can't httpcontext work? I found msdn and found that it should be system. web. httpcontext. current. server. mappath puts server. change mappath to current. server. mappath, hey, fix it ^_^

3. Disable http get and http post by default

Upload the locally debugged service to the web space and try it. You can access and debug it. Why? "The test form is only available for requests from the local machine". Look for this: the Web service connected to. Net supports http get, http post, and soap. In. NET Framework 1.0, all three protocols are enabled by default. However, in. NET Framework 1.1, both http get and http post are disabled by default. This is for security considerations. After the Web Service is upgraded to. NET Framework 1.1 Program When you use http get or http post to call the web service, it will fail. These applications receive an error message system. net. webexception indicating that the request format cannot be recognized. Note that http post is used for HTML-based test forms. Therefore, HTML-based test forms are not applicable in. NET Framework 1.1. This is the case unless the form is on the local host mentioned below .. Net Framework 1.1 defines a new protocol named httppostlocalhost. By default, this new protocol is enabled. This protocol allows applications on the same computer as the Web service that uses the http post request to call this service. The precondition is that the Post URL uses http: // localhost instead of http: // hostname. This allows web service developers to use HTML-based test forms to call the Web service from the same computer where the Web Service is located. When you try to access the Web service from a remote computer, the "call" button is not displayed. In addition, you will receive the following error message: the test form is only available for requests from the Local Machine

Alternative Method

You can enable http get and http post by editing the Web. config file of the vroot of the web service. The following configurations enable both http get and http post:

<Configuration>

<System. Web>

<WebServices>

<Protocols>

<Add name = "httpget"/>

<Add name = "httppost"/>

</Protocols>

</WebServices>

</System. Web>

</Configuration>

Alternatively, you can enable these protocols for all web services on the computer by editing the <protocols> section in machine. config. In the following example, http get, http post, and soap are enabled, and http post is also enabled from the local host:

<Protocols>

<Add name = "httpsoap"/>

<Add name = "httppost"/>

<Add name = "httpget"/>

<Add name = "httppostlocalhost"/>

<! -- Documentation enables the documentation/test pages -->

<Add name = "documentation"/>

</Protocols>

Add the Web. config and machine. config files. Upload, refresh, And you can debug them.

The above points are some of my first contact with Web Service, which is quite impressive. I hope it will be helpful to my friends who just came into contact with it!


Author's blog:Http://blog.csdn.net/dh20156/

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.