Search code examples
asp.netwcfwcf-data-serviceswcf-rest

Restful WCF can't reach operationcontract


I created a RESFTful WCF web service and i installed it in IIS as a new web application. The WCF has some actions like: Login, getEmployees ...etc. and it works fine when i publish and run it from vs, so i can reach from browser links like:

http://myserver/service.svc
http://myserver/service.svc?wsdl
http://myserver/Login?user=sample&password=paswd
http://myserver/getEmployees?name=dada

and with the action links i get the exact needed data as a response.

however it works only when i run the web service from vs, but when i try to reach the links from browser and the web service is NOT running in VS i can reach only links like:

http://myserver/service.svc
http://myserver/service.svc?wsdl

but not the operational links like:

http://myserver/Login?user=sample&password=paswd
http://myserver/getEmployees?name=dada

Endpoints configurations:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings/>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service name="AXPAYROLL.PayrollActions" behaviorConfiguration="serviceBehavior">
        <endpoint address="http://myserver/" behaviorConfiguration="RESTFriendly" binding="webHttpBinding" contract="AXPAYROLL.IPayrollActions">
          <identity>
            <dns value="myserver" />
          </identity>
        </endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://myserver/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="RESTFriendly">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="serviceBehavior">
          <!-- 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="True" />
          <serviceAuthorization serviceAuthorizationManagerType="AXPAYROLL.DataContractLayer.DistributorValidator, AXPAYROLL" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

I also created a console host application where everything worked just fine like from vs, so the problem in IIS for sure may be in permissions...

I am new in WCF but i believe that it can't be the right way to run vs always to get the wcf deployed!!! i also want to install the wcf on a productive server where no vs is installed, i know that the self hosting could be achieved with the console application but this is again not what i want, i want it torun over normal iis,any idea what is the problem? did i miss something?


Solution

  • When the WCF service on IIS, any base address specified in the <baseAddresses> will be ignored and the base address will be the URL to the .svc file.

    The address attribute in the endpoint element is a relative address and could be like address="rest".

    So in IIS, the url will be http://myserver/service.svc/rest/getEmployees?name=dada

    Update:

    To remove svc extension, have a look at this question