WCF not running under IIS 6.0

前端 未结 6 2049
夕颜
夕颜 2021-02-04 03:20

Trying to get my WCF service running under IIS 6.

I have created the .svc and aspnet_isapi.dll mapping according to: http://msdn.microsoft.com/

相关标签:
6条回答
  • 2021-02-04 03:32

    There are two things I can think of:

    The .svc extension is not correctly set up (least probable according to your description). You can check this post for more details.

    Or your web site has multiple host headers. To resolve this issue, you must have a single host header or use a factory. Here’s an example:

    namespace MyNamespace
    {
        public class MultipleHostServiceFactory : ServiceHostFactory
        {
            protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
            {
                List<Uri> addresses = new List<Uri>();
                addresses.Add(baseAddresses[0]);
                return base.CreateServiceHost(serviceType, addresses.ToArray());
            }
        }
    }
    

    Next, you need to set the factory in the markup of your .svc file:

    <%@ ServiceHost Language="C#" 
                    Debug="false" 
                    Factory="MyNamespace.MultipleHostServiceFactory" 
                    Service="MyNamespace.MyService" 
                    CodeBehind="MyService.svc.cs" %>
    
    0 讨论(0)
  • 2021-02-04 03:38

    I battled for hours with this until I finally used this example and it worked first go: http://www.codeproject.com/Articles/105273/Create-RESTful-WCF-Service-API-Step-By-Step-Guide

    I know link only answers aren't good and others have used this CP link to solve this type of problem here at Stackoverflow so here are the basic steps if the article ever goes down:

    STEP 1

    First of all launch Visual Studio 2010. Click FILE->NEW->PROJECT. Create new "WCF Service Application".

    STEP 2

    Once you create the project, you can see in solution that By Default WCF service and interface file are already created (Service1.cs & IService.cs). Delete these two files and we will create our own interface and WCF service file.

    STEP 3

    Now right click on solution and create one new WCF service file. I have given name to the service file as “RestServiceImpl.svc”.

    STEP 4

    As I explained at the start of the article that we will be writing an API which can return data in XML and JSON format, here is the interface for that. In IRestServiceImpl, add the following code

    In the above code, you can see two different methods of IRestService which are XMLData and JSONData. XMLData returns result in XML whereas JSONData in JSON.

    [ServiceContract]
    public interface IRestServiceImpl
    {
        [OperationContract]
        [WebInvoke(Method = "GET",
            ResponseFormat = WebMessageFormat.Xml,
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "xml/{id}")]
        string XMLData(string id);
    
        [OperationContract]
        [WebInvoke(Method = "GET",
            ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "json/{id}")]
        string JSONData(string id);
    }
    

    STEP 5

    Open the file RestServiceImpl.svc.cs and write the following code over there:

    public class RestServiceImpl : IRestServiceImpl
    {
        public string XMLData(string id)
        {
            return "You requested product " + id;
        }
    
        public string JSONData(string id)
        {
            return "You requested product " + id;
        }
    }
    

    STEP 6

    Web.Config

    <?xml version="1.0"?>
    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
      </system.web>
      <system.serviceModel>
        <services>
          <service name="RestService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour">
            <!-- Service Endpoints -->
            <!-- Unless fully qualified, address is relative to base address supplied above -->
            <endpoint address ="" binding="webHttpBinding" contract="RestService.IRestServiceImpl" behaviorConfiguration="web">
              <!-- 
                  Upon deployment, the following identity element should be removed or replaced to reflect the 
                  identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
                  automatically.
              -->
            </endpoint>
          </service>
        </services>
    
        <behaviors>
          <serviceBehaviors>
            <behavior name="ServiceBehaviour">
              <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
              <serviceMetadata httpGetEnabled="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>
          <endpointBehaviors>
            <behavior name="web">
              <webHttp/>
            </behavior>
          </endpointBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
      </system.webServer>
    </configuration>
    

    STEP 7

    In IIS:

    0 讨论(0)
  • 2021-02-04 03:39

    Under Internet Information Service (IIS) Manager, open the node called Web Service Extension. Make sure that ASP.NET v2.0.5.0727 is set to Allowed. I spent hours looking for different settings and found it was set to Prohibited. Just click Allow button to enable ASP.NET.

    0 讨论(0)
  • 2021-02-04 03:40

    I had the same issue and solved it by allowing ISAPI extensions. Under Internet Information Service (IIS) Manager, open the node called Web Service Extension. Make sure that "All Unknown ISAPI Extensions" is set to Allowed.

    0 讨论(0)
  • 2021-02-04 03:46

    More than likely the .svc extension is not registered under IIS as being handled by ASP.NET (WCF).

    Try these 2 steps (replace Framework with Framework64 if it's needed):

    Go to:

    C:\Windows\Microsoft.NET\Framework\v2.0.50727\
    

    and then run:

    aspnet_regiis -i
    

    Go to: C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation

    and then run:

    ServiceModelReg.exe -i
    
    0 讨论(0)
  • 2021-02-04 03:55

    I had the same problem. It ended up being I was running a 64-bit version of Windows 2003 Server, and had my assemblies configured for "Any CPU". Once I changed the assemblies over to x86 and uploaded to the server, everything worked.

    I don't know why nobody has mentioned it anywhere else in the 30 threads I read about, but my friend recommended it to me, and it worked like a charm.

    Just throwing it out there just in case someone has the same issue.

    0 讨论(0)
提交回复
热议问题