WCF REST 服务不工作

WCF REST service doesnt work

我创建了简单的 WCF Web 服务项目并在其上启用了 soap 和 rest 服务。

肥皂服务工作正常,但我无法使用休息服务和帮助页面。

我是这样做的:

  1. 我的网络服务class:

    [OperationContract]
    [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json,
        UriTemplate = "/InsertWithDate/personTypeName({personTypeName})/accessName({accessName})/firstName({firstName})/lastName({lastName})/nationalID({nationalID})/email({email})/userName({userName})/passwordHash({passwordHash})/genderName({genderName})/statusName({statusName})")]
    [Description("Description for GET /InsertWithDate")]
    string InsertWithDate(string personTypeName, string accessName, string firstName, string lastName, string nationalID, string email, string userName, string passwordHash, string genderName, string statusName);
    
  2. 我的web.config文件:

    <?xml version="1.0"?>
    <configuration>
       <appSettings>
          <add key="aspnet:UseTaskFriendlySynchronizationContext" 
               value="true" />
           <!-- (Log4net diagnostics) -->
           <add key="log4net.Internal.Debug" value="true"/>
       </appSettings>
       <system.web>
          <compilation debug="true" targetFramework="4.5" />
          <httpRuntime targetFramework="4.5"/>
       </system.web>
       <system.serviceModel>
           <!-- Add Rest service -->
           <services>
               <service name="WcfWebService.TestWS" 
                        behaviorConfiguration="ServiceBehavior">
               <!-- Use a bindingNamespace to eliminate tempuri.org. 
               bindingNamespace="http://contoso.com/services" -->
                  <endpoint 
                      address="soap" 
                      binding="basicHttpBinding" 
                      contract="WcfWebService.ITestWS"/>
                  <endpoint 
                      address="rest" 
                      binding="webHttpBinding" 
                      behaviorConfiguration="http" 
                      contract="WcfWebService.ITestWS"/>
                  <endpoint 
                      address="mex" 
                      binding="mexHttpBinding" 
                      contract="IMetadataExchange" />
               </service>
           </services>
           <behaviors>
              <serviceBehaviors>
              <!-- Web service behavior (All kind of web Services hast it) -->
                 <behavior name="ServiceBehavior">
                     <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
                     <serviceDebug includeExceptionDetailInFaults="true"/>
                 </behavior>               
              </serviceBehaviors>
              <!-- Rest service behavier) -->
              <endpointBehaviors>
                 <behavior name="http">
                    <webHttp/>
                 </behavior>
              </endpointBehaviors>
          </behaviors>
          <protocolMapping>
              <add binding="basicHttpsBinding" scheme="https" />
          </protocolMapping>    
          <serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
                         multipleSiteBindingsEnabled="true" />
          <standardEndpoints>
              <webHttpEndpoint>
                  <standardEndpoint name="" helpEnabled="true"  
                           automaticFormatSelectionEnabled="true"/>
              </webHttpEndpoint>
          </standardEndpoints>
      </system.serviceModel>
      <system.webServer>
          <modules runAllManagedModulesForAllRequests="true"/>
          <directoryBrowse enabled="true"/>
       </system.webServer>
    </configuration>
    

现在,当我尝试这些页面时:

  1. localhost:51850/TestWS.svc/help
  2. localhost:51850/TestWS.svc/InsertWithDate/help
  3. localhost:51850/TestWS.svc/InsertWithDate/personTypeName(10)/accessName(10)/firstName(mn)/lastName(mn)/nationalID(12)/email(a@asd.com)/userName(nvcvncm)/passwordHash(123)/genderName(male)/statusName(d)

出现相同的页面:“/”应用程序中的服务器错误。

谢谢。

更新: 没有错误:只有这个页面:

对不起,我的错:我完全忘记了我的 REST 服务地址,它是:rest 并且为了启用帮助页面,我只是将 <webHttp helpEnabled="true"/> 添加到我的 web.conf 文件中。