I do not know what category my question falls in: programming error (on my part), or IIS error.
I have created a very simple Ajax-Enabled WCF Service from the visual studio 2010 template. Here is the code:
The CS file:
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;
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class EmployeeServices
{
[OperationContract]
public int DoWork()
{
return 1;
}
}
开发者_开发百科
The WEB.CONFIG (as relates to WCF)
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="EmployeeServicesAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service name="EmployeeServices">
<endpoint address="" behaviorConfiguration="EmployeeServicesAspNetAjaxBehavior" binding="webHttpBinding" contract="EmployeeServices" />
</service>
</services>
</system.serviceModel>
And .SVC File:
<%@ ServiceHost Language="C#" Debug="true" Service="EmployeeServices" CodeBehind="~/App_Code/EmployeeServices.cs" %>
Now the problem: When I test this on my local machine in a web page with javascript that looks like this:
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="EmployeeServices.svc" />
</Services>
</asp:ScriptManager>
<div>
<script type="text/javascript">
function pass(result) {
alert(result);
}
function fail(result) {
alert(result);
}
$(document).ready(function () {
var service = new EmployeeServices();
service.DoWork(pass, fail, null);
});
</script>
</div>
</form>
It works fine, until I publish it to the web server. Then I get a "EmployeeServices not defined" error.
How do I troubleshoot this issue? I appreciate your help, sincerely.
provide a namespace for your svc file like [ServiceContract(Namespace = "namespacw")]
and the ncall service in jquery with this namespace like <yournamespace>.service.DoWork(pass, fail, null)
.
精彩评论