Problem z wywoływaniem biblioteki usług WCF z jQuery

Mam udostępnioną bibliotekę usług WCF w mojej witrynie ASPX w następujący sposób

[System.ServiceModel.OperationContract]
[System.ServiceModel.Web.WebInvoke(
Method= "POST",
RequestFormat=System.ServiceModel.Web. WebMessageFormat .Json,
ResponseFormat=System.ServiceModel.Web.WebMessageFormat .Json)]
LogonResponse Logon(LogonRequest logonRequest);


[System.Runtime.Serialization.DataContract]
[ Serializable()]
public class LogonRequest
{
[System.Runtime.Serialization.DataMember]
public string EMailAddress;
[System.Runtime.Serialization.DataMember]
public string Password;
}

Na mojej stronie testowej mogę zadzwonić przez MS Ajax: -

<asp:ScriptManager ID ="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/testService.svc" />
</Services>
</asp:ScriptManager>
.
.
.
function clsLogonRequest(eMailAddress, password) {
this .EMailAddress = eMailAddress;
this .Password = password;
}

function login(eMailAddress, password) {
var LogonRequest = new clsLogonRequest(eMailAddress, password);
name.API.IAPI.Logon(LogonRequest, onSuccess, onFailure);
}

function onSuccess(result) {
$( "#txtSessionId").val(result.SessionId);
$( "#txtUserName").val(result.Name);
$( "#txtUserId").val(result.UserId);
}

działa dobrze lub za pomocą wywołania jQuery $ .ajax: -

$(document).ready(function() {
$( "#Button1").click(function() {
var LogonRequest = new clsLogonRequest( '*************' , '***********');
$.ajax({
type: "POST",
url: "testService.svc/Logon",
data: "{'logonRequest':" + JSON.stringify(LogonRequest) + "}" ,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert(msg.d);
}
});
});
});

Które nie - pod FireBug widzę komunikat o błędzie 500 wewnętrznych serwerów i zaczyna się wyjątek

{"ExceptionDetail":{"HelpLink":null,"InnerException":null,"Message":"The token '\"' was expected but found '''.","StackTrace":"   at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, String res, String arg1, String arg2, String arg3)\u000d\u000a   at System.Xml.XmlExceptionHelper .ThrowTokenExpected(XmlDictionaryReader reader, String expected, Char found)\u000d\u000a   at System.Runtime...

Dlaczego wydaje się, że wywołanie jQuery przekazuje XML, gdy mówię mu, żeby tego nie robił (i jak mogę go zatrzymać, aby połączenia ze wszystkich źródeł były obsługiwane tak naturalnie, jak to możliwe)?

Z góry dziękuję.

EDYTOWAĆ:

Dzięki za sugestie, przyjrzałem się temu, co powiedziałeś i myślę, że moje wyjaśnienie problemu nie było wystarczająco jasne.

Problem nie polega na tym, że JSON nie jest wysyłany, jest wysyłany i ma poprawny format, widzę to po firebugu. Problem polega na tym, że biblioteka usług WCF wydaje się oczekiwać XML i spada, gdy otrzymuje JSON.

Aby upewnić się, że nie przeoczyłem sugerowanego rozwiązania, oto fragment web.Config - próbowałem usunąć z zachowania i usunąć atrybut behaviorConfiguration z tagu services / service / endpoint, co tylko powoduje, że cała sprawa zawodzi bez wychodzenia ze strony.

<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name ="MyServiceTypeBehaviors ">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name ="AspNetAjaxBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled= "true " />
<services>
<service name ="test.API.API" behaviorConfiguration = " MyServiceTypeBehaviors">
<endpoint behaviorConfiguration="AspNetAjaxBehavior" binding = " webHttpBinding" contract="test.API.IAPI" />
<endpoint contract ="IMetadataExchange" binding= " mexHttpBinding" address="mex" />
</service>
</services>
</system.serviceModel>

Z góry dziękuję

questionAnswers(1)

yourAnswerToTheQuestion