I hava a ajax call wcf in asp.net mvc 4 web site. It post the data to the server. However I found the error" Endpoint not found" error. By checking log file. I got.
<failedRequest url="http://localhost:8080/wscccService.svc/" siteId="1" appPoolId="Clr4IntegratedAppPool" processId="8052" verb="GET" remoteUserName="" userName="" tokenUserName="hui-PC\hui" authenticationType="anonymous" activityId="{00000000-0000-0000-3E00-0080000000FD}" failureReason="STATUS_CODE" statusCode="200" triggerStatusCode="404" timeTaken="499" xmlns:freb="http://schemas.microsoft.com/win/2006/06/iis/freb"><Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"><System><Provider Name="WWW Server" Guid="{3A2A4E84-4C21-4981-AE10-3FDA0D9B0F83}"/><EventID>0</EventID><Version>1</Version><Level>5</Level><Opcode>2</Opcode><Keywords>0x100</Keywords><TimeCreated SystemTime="2013-07-16T23:27:11.577Z"/><Correlation ActivityID="{00000000-0000-0000-3E00-0080000000FD}"/><Execution ProcessID="8052" ThreadID="7120"/><Computer>HUI-PC</Computer></System> // many blah blah
I don't understand it at all. The client side code:
<script lang="javascript" type="text/javascript"> function ttsFunction() { serviceUrl = "http://localhost:8080/wscccService.svc/RunTts"; var data = new Object(); data.text = $('#speak').val(); var jsonString = JSON.stringify(data);$.ajax({ type: 'POST', url: serviceUrl, data: jsonString, contentType: 'application/json; charset=utf-8', dataType: 'json', error: function (xhr,status,error) { console.log("Status: " + status); console.log("Error: " + error); console.log("xhr: " + xhr.readyState); }, statusCode: { 404: function() { console.log('page not found'); } } }); }</script>
The service code:
namespace service { [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] [ServiceBehavior(IncludeExceptionDetailInFaults = true)] public class wservice:Iwservice { public string RunTts(string value) { using (SpeechSynthesizer synth = new SpeechSynthesizer()) { // Configure the audio output. synth.SetOutputToDefaultAudioDevice(); synth.Speak(value); return ""; } } } }
Thanks.