Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在本地测试REST服务_C#_Wcf_Rest_Iis_Localhost - Fatal编程技术网

C# 如何在本地测试REST服务

C# 如何在本地测试REST服务,c#,wcf,rest,iis,localhost,C#,Wcf,Rest,Iis,Localhost,我刚刚开始了我在一家公司的第一份工作,我的第一项任务是为一个管理大型数据库的C#web应用程序添加一些功能。此应用程序使用WCF REST服务和实体框架将条目存储到数据库中(而不是应用程序设计用于管理的主数据库)。请注意,我对使用REST是完全陌生的 对于我添加的功能,我需要修改REST服务,但根据公司政策,我需要与解决方案设计师、数据库管理员、系统构建者等一起完成完整的代码审查,然后才能将任何内容部署到开发服务器 这意味着我无法部署修改后的REST,以便在本地测试我正在使用的应用程序的新功能是

我刚刚开始了我在一家公司的第一份工作,我的第一项任务是为一个管理大型数据库的C#web应用程序添加一些功能。此应用程序使用WCF REST服务和实体框架将条目存储到数据库中(而不是应用程序设计用于管理的主数据库)。请注意,我对使用REST是完全陌生的

对于我添加的功能,我需要修改REST服务,但根据公司政策,我需要与解决方案设计师、数据库管理员、系统构建者等一起完成完整的代码审查,然后才能将任何内容部署到开发服务器

这意味着我无法部署修改后的REST,以便在本地测试我正在使用的应用程序的新功能是否有效。因此,我一直在尝试使用IIS express在本地部署REST服务,但当我尝试使用REST时,我不断收到一个错误,指出:

错误:System.ServicModel.EndpointNotFoundException:在上没有端点侦听http://localhost:45178/EmailWebServiceRest/EmailBatchManager/SendBatch 可以接受此消息。

用于测试其余部分的解决方案的App.config EmailWebService.Proxy.TestHarness如下所示:

    <?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>

如您所见,我只是在上面的App.config中更改了RestServiceURI。据我所知,REST服务正在IIS中运行。有什么我错过的步骤吗

REST服务解决方案本身的Web.config如下所示:

<?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>

在这种情况下,我将安装IIS,并在默认网站下为我要测试的应用程序配置一个虚拟应用程序。然后您可以直接从
http://localhost/a.n.other.url


但是,作为旁注,通过http访问和测试服务可以被视为一种集成测试,您应该通过不需要通过http调用的单元测试来测试尽可能多的代码。

看起来您正在使用wcf,您应该能够从visual studio内部启动项目。VS可能会为您提供所有的web服务