正常に動作する Web アプリがいくつかありますが、何らかの理由で、サービスで関数を呼び出すたびに 500 エラーが返されます。
web.config ファイルは次のとおりです。
<configuration>
<connectionStrings>
<add name="MyData" connectionString="** Insert Connection String Here **" />
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="1.0.0.0"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="10" />
</authentication>
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="ApplicationServices"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider"
type="System.Web.Profile.SqlProfileProvider"
connectionStringName="ApplicationServices"
applicationName="/" />
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider"
type="System.Web.Security.SqlRoleProvider"
connectionStringName="ApplicationServices"
applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider"
type="System.Web.Security.WindowsTokenRoleProvider"
applicationName="/" />
</providers>
</roleManager>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages"/>
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<!-- system.serviceModel added by developers -->
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="RestJson">
<enableWebScript />
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="WebTestBehavior">
<!-- ** serviceMetadata httpGetEnabled="true" / ** -->
<!-- serviceDebug includeExceptionDetailInFaults="true" / -->
</behavior>
<behavior name="">
<!-- ** serviceMetadata httpGetEnabled="true" / ** -->
<!-- serviceDebug includeExceptionDetailInFaults="false" / -->
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="BasicBinding">
<!-- ** Change from "None" ** -->
<security mode="TransportCredentialOnly" />
</binding>
</webHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="Web_Test.LoginService"
behaviorConfiguration="WebTestBehavior">
<endpoint address=""
binding="webHttpBinding"
bindingConfiguration="BasicBinding"
name="RestJson"
contract="Web_Test.LoginServiceInterface"
behaviorConfiguration="RestJson">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</service>
</services>
</system.serviceModel>
</configuration>
サービスを呼び出すメインの .cshtml の Javascript コードは次のとおりです。 // userUsername と userPassword は文字列変数です。
var TestConnectionParams = [{"username": userUsername, "password": userPassword}];
$.ajax({
type: "POST",
url: "/LoginService.svc/TestConnection",
data: JSON.stringify(TestConnectionParams),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var ReturnString = "Login returned " + data;
$(OutputDiv).html(ReturnString);
},
error: function (HelpRequest, ErrorCode, TheError) {
var ErrorMsg = "Login Failed:<br />" + TheError;
$(OutputDiv).html(ErrorMsg);
},
async:false
});
サービスの .cs ファイルは次のとおりです。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using System.Configuration;
namespace Web_Test
{
[ServiceContract]
public interface LoginServiceInterface
{
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json)]
String TestConnection(String username, String password);
}
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class LoginService : LoginServiceInterface
{
public String TestConnection(String username, String password)
{
String ReturnString = "This didn't do anything";
return ReturnString;
}
}
}
AJAX 呼び出しは、「ログインに失敗しました: 内部サーバー エラー」を返します。
web.config で合理的に明らかな何かが欠けていると確信していますが、それを見ることができません。