WCF not running under IIS 6.0

前端 未结 6 2200
夕颜
夕颜 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: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

    
    
      
        
      
      
        
          
            
            
            
              
            
          
        
    
        
          
            
              
              
              
              
            
          
          
            
              
            
          
        
        
      
      
        
      
    
    

    STEP 7

    In IIS:

提交回复
热议问题