Reputation: 1009
I've followed the instructions on MSDN : Exposing WCF Services to Client Script (http://msdn.microsoft.com/en-us/library/bb514961.aspx), however the example does not show how to actually consume the service in javascript, which is where I am getting stuck.
I've created a very simple WCF service :
using System.ServiceModel; using System.Text; using System.ServiceModel.Activation;
namespace MyNamespace {
[ServiceContract(Namespace = "MyDomain.com")]
public interface IMyService
{
[OperationContract]
void DoWork();
}
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "McCormickProdService" in code, svc and config file together.
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MyService : IMyService
{
public void DoWork()
{
}
}
}
I've also updated by web.config :
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="default"/>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="webScriptEnablingBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="MyNamespace.MyService"
behaviorConfiguration="">
<endpoint address="" binding="webHttpBinding"
bindingConfiguration="default"
contract="MyNamespace.IMyService"
behaviorConfiguration="webScriptEnablingBehavior"/>
</service>
</services>
</system.serviceModel>
And here is the code that I have cobbled together in ASP.NET / javascript :
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="false" EnableCdn="true" AjaxFrameworkMode="Explicit">
<Scripts>
<asp:ScriptReference Path="http://ajax.aspnetcdn.com/ajax/act/40412/start.js" />
</Scripts>
<Services>
<asp:ServiceReference Path="~/Services/MyService.svc"/>
</Services>
</asp:ScriptManager>
<asp:ContentPlaceHolder ID="endbody" runat="server" />
<script type="text/javascript">
Sys.loader.defineScripts(null, [{ name: "jQueryUI", releaseUrl: "http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.min.js", dependencies: ["jQuery"], isLoaded: !!(window.jQuery && jQuery.ui)}]);
Sys.loader.defineScripts(null, [{ name: "jQueryUIdatepickerfr", releaseUrl: "http://jquery-ui.googlecode.com/svn/trunk/ui/i18n/jquery.ui.datepicker-fr.js", dependencies: ["jQueryUI"], isLoaded: !!(window.jQuery && jQuery.ui)}]);
Sys.require([
Sys.scripts.ApplicationServices,
Sys.scripts.Templates,
Sys.scripts.DataContext,
Sys.scripts.WebServices,
Sys.scripts.jQuery,
Sys.scripts.jQueryUI,
Sys.scripts.jQueryUIdatepickerfr], function () {
MyDomain.com.IMyService.DoWork(function () { alert('success') }, function () { alert('failure') }, null);
});
</script>
When I load my page, I am receiving the following errors :
Error: 'Sys.Net.WebServiceProxy' is null or not an object Error: Object doesn't support this property or method
Remarks :
Hope someone brilliant out there can give a dog a bone, because I'm lost!
Thanks,
Patrick
Upvotes: 0
Views: 1096
Reputation: 1009
Figured out a bunch of things, perhaps this will be useful to others:
All that is required in the web.config is:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" /> (or true for testing)
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
Voilà!
Upvotes: 1