我在_Layout.cshtml中有一个ajax调用。
<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>
基本上,我想单击另一个视图中的按钮来调用此服务。Community.csthml中的按钮为:
<button id="btnSpeak" onclick="ttsFunction();">Speak</button>
当我在浏览器中键入svc路径时,我在IISEXPRESS下的Tracelog文件夹中发现了一个异常。
例外情况是:
[HttpException]: The controller for path &#39;/wscccService.svc/&#39; was not found or does not implement IController.
at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType)
at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName)
at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state)
at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
--></Data>
服务本身很简单:
namespace service
{
[ServiceContract]
public interface Iwservice
{
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "RunTts")]
string RunTts(string text);
}
}
为了节省空间,除非您需要,否则我不会发布web.config。谢谢你的帮助。
发布于 2013-07-16 14:14:29
您的/wscccService.svc
文件似乎驻留在ASP.NET MVC应用程序目录中。MVC的路由将拦截该请求,并开始寻找一个名为wscccService.svc
的控制器,但它找不到这个控制器。
只需通过add an ignore route连接到您的路由配置。
https://stackoverflow.com/questions/17678908
复制