(This is a repeat post from C# section since I just found this section and thought it might apply.)

Hi guys,

First I want to apologize for such a lengthy post. I'm attempting to give as much information as I can, and I'm sure I'm leaving something important out anyway. Since IIS is brand new to me, I have a hard time telling the difference, though I'm sure a lot of this won't be relevant. I'm also sorry if this is the wrong forum section for this question, but I'm not sure if my issue is with my IIS configuration or the C# code I've written (or both). If there's a more appropriate place for me to ask, please let me know. Anyway, here's my situation. I'm using Windows XP Pro SP2 and I installed the IIS add-on (which I understand is 5.1?), I'm developing in VS2008 (C#), and testing in Firefox.

Here's some background, to give you an idea of what I'm trying to do. I created a WPF Desktop Application that worked great; I decided to convert it into a WPF Browser Application (not because it was functionally necessary, mainly just as an academic exercise to learn something new). The problem I ran into was that I need to make WebRequests, which aren't allowed in the Partial Trust zone of Browser Applications.

After a little digging, I found that the same functionality could be realized by a Web Service so long as it was located on the same site-of-origin (http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/8dbb9beb-7869-4ae0-883a-93de4b7bd9cc). So I created a working Web Service (tested it through VS2008's "Open in Browser" option), and modified my Browser Application to call it instead. Each works fine on its own (though the Browser Application fails during the Web Service call).

So, I installed IIS via the Windows XP Pro SP2 disc, and configured it as found here: http://www.learnthat.com/courses/computer/windowsxp/iis/

At this point, I am unable to access http://localhost/, giving a "Virtual Directory" warning. When I compile the application and attempt to move my xbap, exe, and manifest files into the localhost root directory (which I've configured as "C:\WEB_ROOT\"), I'm unable to access them from the browser (the same goes for the Web Service asmx file). I am, however, able to run the Browser Application when I Publish it, with the URL of http://<my comp name>/WpfBrowserApplicationHome2/WpfBrowserApplicationHome2.xbap/. This results in an error when I attempt to call the Web Service, listing a Security violation in web requests. Replacing that with http://localhost/WpfBrowserApplicationHome2/WpfBrowserApplicationHome2.xbap/ also allows the Browser Application to run, though it also fails when I attempt to call the Web Service, giving a 404 not found.

It is worth mentioning that I'm attempting to call the Web Service from the Browser Application with the following WebRequest URL structure: http://localhost/WebService1.asmx/getPage1Code?tag=tagValue. I've also tried http://localhost/WebService1.asmx/op=getPage1Code?tag=tagValue. Each provides me with a 404 Not Found when I enter it into the browser, and I fear this may be related to the 404 not found I receive when I attempt to call the Published Application via localhost as opposed to using my computer name (see the end of the previous paragraph). If this is the case, then my first need would be to access the Web Service via localhost in the browser, but the two formats listed above were the only results of my previous search.

So to summarize, my main questions are:

1. How do I call the Web Service? Am I doing everything I need to when I just copy the asmx file into the localhost directory, or am I leaving something out? I've confirmed that the Web Service works correctly in stand-alone.

2. How do I access the root of my localhost via browser? This is currently giving me the Virtual Directory error I mentioned. This may be the cause of my inability to reach the Web Service.

Again, sorry in advance. Since this is all new to me, the solution may be obvious and it may only take 30 seconds to Google, but at this point I'm lost and don't even know what to search on.

In the interest of keeping this thread updated with the other thread:

How are you accessing the virtual directory? If you are using anonymous authentication then you will need to grant IUSR_COMPUTERNAME read access to that directory. If you are using integrated auth you will need to give whatever name you are attempting to authenticate against permissions to the directory as well as ensure that you are, in fact, authenticating correctly.

Under "My Web Site Properties", under "Directory Security" tab, I have "Anonymous Access" checked. I'm logged into the computer as administrator, the local directory is "C:\WEB_ROOT\" so I already have read permissions. Is there some other place I need to set it? I would've guessed that my ability to actually run the application after it's published would indicate this is enabled. The behavior is the same regardless of whether "Integrated Windows Authentication" under "Directory Security" tab is checked or unchecked.

Under the "Home Directory" tab, I've selected the "A directory located on this computer" for the content source, Local Path = "c:\WEB_ROOT", and I initially had only "Read", "Log Visits", and "Index this Resource" checkboxes checked, and on typing this I realized I didn't have "Directory Browsing" checked. I checked that box, and can now access http://localhost/ and view my files, which solves that issue from yesterday. I checked the rest of the boxes as well ("Write" and "Script source access") just to be sure.

I found a possible solution to my "How do I call the Web Service" question, which has led to another problem. The suggested solution is found here (see my implementation with a little context below): http://geekswithblogs.net/marcel/archive/2007/03/26/109886.aspx

This error reads: System.Net.WebException: The remote server returned an error: (405) Method Not Allowed.
at System.Net.HttpWebRequest.GetResponse()

I've found a source that says that "A server can refuse to accept a POST request for a certain page, only a GET."

How can I configure my IIS to accept POST messages?

Here's my implementation (Web service function included so you can see the parameters):

// Accessor function of WebService1
[WebMethod(Description = "This method returns page code for any given tag and page number input.")]
public string getAnyPageCode(string tag, int pageNumber)
    page.tag = tag;
    page.pageNumber = pageNumber;
    return page.code;
// End of Accessor function of WebService1

// Experiment from http://geekswithblogs.net/marcel/archive/2007/03/26/109886.aspx
string soap =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" 
    <Register xmlns=""http://tempuri.org/"">
      <tag>" + tag + @"</tag>

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://localhost/WpfBrowserApplicationHome2/WebService1.asmx");
req.Headers.Add("SOAPAction", "\"http://tempuri.org/getAnyPageCode\"");
req.ContentType = "text/xml;charset=\"utf-8\"";
req.Accept = "text/xml";
req.Method = "POST";

using (Stream stm = req.GetRequestStream())
   using (StreamWriter stmw = new StreamWriter(stm))

WebResponse response = req.GetResponse(); // causes the System.Net.WebException: The remote server returned an error: (405) Method Not Allowed. at System.Net.HttpWebRequest.GetResponse()

Stream responseStream = response.GetResponseStream();
StreamReader tempstr = new StreamReader(responseStream);
code = tempstr.ReadToEnd();
// End of Experiment from http://geekswithblogs.net/marcel/archive/2007/03/26/109886.aspx

My error is at line 42:

WebResponse response = req.GetResponse(); // causes the System.Net.WebException: The remote server returned an error: (405) Method Not Allowed. at System.Net.HttpWebRequest.GetResponse()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.