I followed this to create a json web service in asp.net 3.5:
Creating JSON-enabled WCF services in .NET 3.5 (archive.org)
(Was at: http://www.pluralsight.com/community/blogs/fritz/archive/2008/01/31/50121.aspx )
It works fine if I want to use it internally, but since I want to connect to it externally, I got an error: "Publishing metadata for this service is currently disabled."
So, I tried to enable it, but now I get the error: "It is not possible to add the extension of the" serviceMetadata "behavior to the behavior of the endpoint" MyServiceAspNetAjaxBehavior "because the main type of behavior does not implement the IEndpointBehavior interface."
I know that I am doing something wrong in web.config, just can not understand what I'm doing wrong? Thanks!
This is in the web.config file:
<system.serviceModel> <behaviors> <endpointBehaviors> <behavior name="MyServiceAspNetAjaxBehavior"> <enableWebScript /> <serviceMetadata httpGetEnabled="true" /> </behavior> </endpointBehaviors> </behaviors> //Needed to add this to be able to use the web service on my shared host <serviceHostingEnvironment aspNetCompatibilityEnabled="true"> <baseAddressPrefixFilters> <add prefix="http://www.domain.com"/> </baseAddressPrefixFilters> </serviceHostingEnvironment> <services> <service name="MyService"> <endpoint address="" behaviorConfiguration="MyServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="MyService" /> <endpoint contract="MyService" binding="mexHttpBinding" address="mex" /> </service> </services>
In MyService.cs:
using System; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Activation; using System.ServiceModel.Web; [ServiceContract(Namespace = "")] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class MyService { [OperationContract] public string GetForecast(string str) { return "Hello World"; } }
In MyService.svc
<%@ ServiceHost Language="C#" Debug="true" Service="MyService" CodeBehind="~/App_Code/MyService.cs" %>
Martin
source share