Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An item with the same key has already been added. IIS WCF Rest

I am hosting WCF Rest service with my Asp.net Application, and asp.net compatibility mode is on ,it is working fine when I run app from visual studio but when I in IIS7 I get error while accessing the End Point says "An item with the same key has already been added." MY Service Cod is.

  [ServiceContract]
    [AspNetCompatibilityRequirements
    (RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

    public class RestService
    {

        [OperationContract]
        [WebGet(UriTemplate = "Site/{Id}", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)]
        public Site GetSite(string Id)
        {
            return new Site(1);
        }
}

and global ASCX is

   protected void Application_Start ()
        {
            RouteTable.Routes.Add(new ServiceRoute("Rest", new WebServiceHostFactory(), typeof(RestService)));

       }

and web.config

     <system.serviceModel>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>

        <standardEndpoints>
               <webHttpEndpoint>
                    <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="false"/>
               </webHttpEndpoint>


        </standardEndpoints>
      </system.serviceModel>

Note Every things working fine in VS2010 Mode but getting error in while Hosting IIS 7 and accessing http://example.com/rest/site/2 any Suggestion Please ?

like image 998
sm.abdullah Avatar asked Nov 15 '25 09:11

sm.abdullah


1 Answers

In IIS Under Advance Setting then Enabledd Protocols I switched off https and it works fine. enter image description here

like image 73
sm.abdullah Avatar answered Nov 18 '25 19:11

sm.abdullah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!