I followed this to create a json web service in asp.net 3.5:
http://www.pluralsight.com/community/blogs/fritz/archive/2008/01/31/50121.aspx
It works fine if I want to use it internal but as I want to connect to it external I got an error saying: "Metadata publishing for this service is currently disabled."
So I tried enabling it but now I get the error: "Cannot add the 'serviceMetadata' behavior extension to 'MyServiceAspNetAjaxBehavior' endpoint behavior because the underlying behavior type does not implement the IEndpointBehavior interface.".
I know I'm doing something wrong in web.config, just can't figure it out, what am I doing wrong? Thanks!
This is in web.config:
<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" %>