[Mono-list] Hosting WCF WebHttpBinding in XSP?
Ashley Ee
ee.ashley at gmail.com
Mon Jul 11 19:43:28 UTC 2016
I'm trying to host a WCF service that uses the WebHttpBinding in XSP.
This is based on an adaptation of one of the Mono WCF samples by Atsushi
Eno here:
http://veritas-vos-liberabit.com/monogatari/2009/12/mono-wcf-advent-day-9-restful-webhttpbinding.html
Specifically, my modified code looks like (modified to use a UriTemplate):
// service
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Web;
[ServiceContract]
public interface IMyService
{
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/greet/{input}")]
string Greet (string input);
}
public class MyService : IMyService
{
public string Greet (string input)
{
return "hola, " + input;
}
}
public class Test
{
public static void Main ()
{
string url = "http://localhost:8080/";
WebHttpBinding b = new WebHttpBinding ();
var host = new WebServiceHost (typeof (MyService), new Uri (url));
host.AddServiceEndpoint (typeof (IMyService), b, "");
host.Open ();
Console.WriteLine ("--- type [CR] to quit ---");
Console.ReadLine ();
host.Close ();
}
}
This works great, and I can query the service at this URL:
http://localhost:8080/greet/name, which responds with "hello, name".
Next I built it as a library and created an svc file that contains:
<%@ServiceHost Service="MyService" %>
Then a web.config with:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="WcfServiceLibrary1.Service1">
<endpoint address="" binding="webHttpBinding" contract="IMyService"
/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior>
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
However, when I start xsp and try to query:
http://localhost:8080/service.svc/greet/name, I get back a
System.InvalidOperationException, with the error message
"HttpListenerContext does not match any of the registered channels".
I've been trying a few different things along these lines, but this so far
has been the most simple test code I have yet.
Is this something that should be supported in xsp? It seems to work fine in
a stand-alone Mono executable, but I would like to host this along side
some HTML pages without using IIS (which is why I am starting with xsp,
perhaps later Apache and mod_mono if I could get xsp working first).
I have been trying this both on a Debian host (Mono 4.2.4) and a Windows 7
host (Mono 4.4.1); both yield the same issues (HttpListenerContext does not
match any of the registered channels).
Thanks in advanced for any guidance..
Ash
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-list/attachments/20160711/8d2771f2/attachment.html>
More information about the Mono-list
mailing list