Carel
Carel

Reputation: 2143

How to test a REST service locally

I have just started my first job for a company and my first assignment is to add some functionality to a C# web application that manages a sizable database. This application makes use of a WCF REST service and entity framework to store entries into a database (not the main database the application is designed to manage). Let it be noted that I'm completely new to using REST.

For my added functionality I needed to modify the REST service, but according to company policy I need to complete a full code review with the solution designer, database administrators, system builders etc. before I can deploy anything to the dev server.

This means I cannot deploy my modified REST in order to just test locally if my new functionality of the application I'm working on works. Hence, I've been trying to deploy the REST service locally with IIS express, but when I use attempt to use the REST I keep getting an error stating:

Error: System.ServicModel.EndpointNotFoundException: There was no endpoint listening at http://localhost:45178/EmailWebServiceRest/EmailBatchManager/SendBatch that could accept the message.

The App.config of the solution that is to test the REST, EmailWebService.Proxy.TestHarness, is as follows;

    <?xml version="1.0"?>
<configuration>
  <appSettings>
    <!--<add key="EmailWebService.RestServiceURI" value="http://webservices.capetown.gov.za/EmailWebServiceRest/EmailBatchManager"/>-->
    <add key="EmailWebService.RestServiceURI" value="http://localhost:45178/EmailWebServiceRest/EmailBatchManager"/>
    <add key="EmailWebService.ApplicationName" value="COD"/>
    <add key="EmailWebService.ApplicationLicenseKey" value="b24968d3-7011-4dab-abba-f513a430b91f"/>
  </appSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

As you can see, I simply changed the RestServiceURI in the App.config above. As far as I can tell, the REST service is running in IIS. Is there some step I'm missing?

The Web.config of the REST service solution itself is as follows:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>    
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  </configSections>
  <appSettings>
    <add key="ApplicationName" value="EmailWebService" />
  </appSettings>
  <connectionStrings>
    <add name="EmailWebService"
         connectionString="integrated security=SSPI;
                           data source=cbd-civic-dqc03;
                           persist security info=False;
                           initial catalog=EmailWebService"
         providerName="System.Data.SqlClient" />    
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <httpRuntime maxRequestLength="2147483647" />
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </modules>
  </system.webServer>
  <system.serviceModel>
    <bindings>      
      <webHttpBinding>        
        <binding maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
          <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647" maxDepth="2147483647" />
        </binding>
      </webHttpBinding>
    </bindings>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <standardEndpoints>
      <webHttpEndpoint>        
        <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" />
      </webHttpEndpoint>
    </standardEndpoints>
  </system.serviceModel>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="Data Source=.\SQLEXPRESS; Integrated Security=True; MultipleActiveResultSets=True" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
</configuration>

Upvotes: 1

Views: 3672

Answers (1)

Kinexus
Kinexus

Reputation: 12904

In this scenario, I would have IIS installed and configure a virtual application under the default website for the application I am looking to test. You will then be able to access it directly from http://localhost/a.n.other.url

However, as a side-note, accessing and testing the service via http could be considered an integration test and you should be looking to test as much code as possible via unit tests which do not need to be called over http.

Upvotes: 1

Related Questions