0

I've started learning web services with ASP.NET. When doing a quick search on how to build and use a simple web service, this page seemed nice and simple.

I followed the instruction "copy FirstService.asmx in the IIS virtual directory...[and] open the web service" (actually, it is displayed as FirstService.asmx.cs), but from there on problems started. I got several HTTP Error (as explained here, I gave permissions to both IUSR and IIS_USRS, though the latter is probably irrelevant) and I'm now stuck with Error 404.7.

I tried the suggestions of these two (1, 2) SO posts (so I now have a second file on my folder, a Web.config file, though the site linked above said nothing about Web.config files), nothing helped.

Note that I also followed this page to register the correct version of ASP.NET with IIS.

Is there any other option?

EDIT:

Windows 7 Ultimate (64-bit), IIS 7.5

Full error (pardon the graphics):

Error Summary

HTTP Error 404.7 - Not Found The request filtering module is configured to deny the file extension.

Detailed Error Information

Module: RequestFilteringModule

Notification: BeginRequest

Handler: StaticFile

Error Code: 0x00000000

Requested URL: http://localhost:80/MyWebServices/WebService1.asmx.cs

Physical Path: C:\Users\home\Desktop\MyWebServices\WebService1.asmx.cs

Logon Method: Not yet determined

Logon User: Not yet determined

My Web.config:

<?xml version="1.0" encoding="UTF-8"?>

<configuration>
  <system.webServer>
    <security>
      <requestFiltering>
        <fileExtensions allowUnlisted="true">
          <remove fileExtension="." />
          <add fileExtension="." allowed="true" />
        </fileExtensions>
      </requestFiltering>
    </security>
  </system.webServer>
</configuration>
Community
  • 1
  • 1
OfirD
  • 9,442
  • 5
  • 47
  • 90
  • Please post the actual, full error and your actual configuration (Windows version, IIS version, XML config) in your question. Also, there's a reason there's no date on that tutorial: it's at least 10 years old. Dump ASMX and go for ASP.NET Web API or WCF. – CodeCaster Dec 15 '16 at 16:38
  • Thanks, edit added. I'd certainly move to Web API *and* WCF eventually, but I like to go through the basics and learn about technologies that still being used (in big enterprises, at least), such as ASMX. – OfirD Dec 15 '16 at 19:12

1 Answers1

1

.cs is a code file and by default all .cs files are not allowed to be browsed in browser of course due to security concerns as all code is in there.

Also if you want to browse your webservice you don't need to browse .cs file you need to browse following

http://localhost:80/MyWebServices/WebService1.asmx

If MIME Type for asmx is not added you will need to added MIME Type for asmx.

  • Go to IIS
  • Select Your Website/Webservice on left side.
  • Select MIME Types.
  • Select Add on top right.
  • Add .asmx in File Name extension and text/xml in MIME Tpe
Mairaj Ahmad
  • 14,434
  • 2
  • 26
  • 40
  • Well, the 'asmx.cs' file was created in an "asp.net web application" project in VS, and is displayed there as '.asmx', and then I just took it out of the project folder and put it in 'MyWebServices' folder and the '.cs' suffix was added to it automatically. So it would be strange if that is the problem, but i'll try. – OfirD Dec 16 '16 at 07:13
  • You don't need to took it outside the folder just leave it where it is created by VS. – Mairaj Ahmad Dec 16 '16 at 07:33
  • I know that, but I wanted a more convenient folder to access, and a Desktop folder was the immediate choice – OfirD Dec 16 '16 at 07:38
  • You can directly host the webserivce from VS. Go to project properties select `Web` and Select `Local IIS` and click create `Virtual Directory` you can browse by that address. – Mairaj Ahmad Dec 16 '16 at 07:40
  • Update: It's working! For future reference, here's what I did: Your comment about the `.cs` files made me try doing a little tweak: erasing the `.cs` suffix from the `.asmx.cs` file. I then browsed again with IIS, and got a much more clear error message: That I'm missing a <%@ webservice class="MyNamespace.MyClass" ... %> directive. Then it occured to me that this extension is indeed found in the tutorial I read, but I forgot to add it because VS is dedicating a different `.asmx` file especially for it. So I copied its content to my file, and it worked! BTW, the MIME addition wasn't neccesary. – OfirD Dec 16 '16 at 11:01