Link to home
Start Free TrialLog in
Avatar of XTO
XTO

asked on

Adding a WCF web service to an ASP.NET project from IIS causes error downloading metadata unauthorized with Anonymous authentication

I added a WCF Service Project (I've also tried this with a WCF Service web site) to my Visual Studio solution that contained an ASP.NET project.
I was able to build the WCF Service and add it as a reference to the ASP.NET project just fine. It ran just fine within Visual Studio and retrieved the results that I wanted.

What do I do next ?

I wasn't sure what to do next since I haven't worked with WCF in a long time and I don't remember much. I figured that the next thing that I was supposed to do was to publish the WCF Service to IIS. It published to the local IIS just fine.

Then I removed the service reference from the ASP.NET project (because the was the reference to the WCF Service in Visual Studio).
I then tried to add a reference to the WCF Service that I had published to IIS.

This is the error that I got:

There was an error downloading 'http://localhost/$metadata'.
The request failed with HTTP status 404: Not Found.
Metadata contains a reference that cannot be resolved: 'http://localhost/'.
The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate,NTLM'.
The remote server returned an error: (401) Unauthorized.
If the service is defined in the current solution, try building the solution and adding the service reference again.

I looked in the IIS web site authorization and I set the Anonymous authentication from Disabled to Enabled.
I also removed the WCF Service project (and/or web site) from Visual Studio and I tried again. I got the same error.
Avatar of Dan McFadden
Dan McFadden
Flag of United States of America image

Can you post your web.config?

Dan
Avatar of XTO
XTO

ASKER

Hi Dan,

   This web service is in response to the Python error message you were helping me with last week. I've decided to call the Python through a WCF Service instead of directly through the ASP.NET application.

   The error message I posted above no longer occurs because I kept the WCF Service application in the solution and set it to run as IIS Express. I am able to run the ASP.NET application project through Local IIS within Visual Studio.

    My biggest point of confusion now is that I don't know if I'm supposed to publish the WCF Service application.
   Maybe I should be working with a WCF Service library instead of a WCF service application and just include the WCF Service library .dll as a reference within the ASP.NET application.

   So, to reiterate, the point that I need the most help is understanding what to do after I get the WCF Service and ASP.NET application working properly within Visual Studio.

Here is the web.config file.

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.2"/>
  </system.web>
  
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding openTimeout="00:10:00"
         closeTimeout="00:10:00"
         sendTimeout="00:10:00"
         receiveTimeout="00:10:00">
        </binding>
      </wsHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>    
    <protocolMapping>
      <add binding="wsHttpBinding" scheme="http" />
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>      
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Dan McFadden
Dan McFadden
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of XTO

ASKER

In this help page there is a section called, "Create an .svc File for the WCF Service."
https://msdn.microsoft.com/en-us/library/aa751792%28v=vs.110%29.aspx

It talks about the syntax for the .svc file.
However, in my Visual Studio's WCF Service project the .SVC file shown in the Solution Explorer has a "svc.cs" file located as a sub-branch.
When I click on the .svc file in solution explorer, it opens the .cs file.
I'm unable to get the sort of page that would allow me to add configure something like the example,

<% @ServiceHost Service="MyNamespace.MyServiceImplementationTypeName" %>

Open in new window


Maybe that's just for the WCF Service web site and instead of have the WCF Service application project. I don't know. Is there something different that I'm supposed to do here?
Avatar of XTO

ASKER

The link I mentioned above also has a section on "Endpoint Addresses for IIS-Hosted Services."

I infer that this is supposed to be configured in the web.config; but my mine doesn't have any <endpoint . . . /> element.
Do I need to go ahead and add that?

How do I know what the endpoint should be?
In my case it looks like it should just be:
<endpoint address="" ... />

Is that right?
Avatar of XTO

ASKER

I found the answer to the endpoint question above.

"If you do not add any endpoints to the service, the runtime adds default endpoints for you. "
https://msdn.microsoft.com/en-us/library/ms733766(v=vs.110).aspx