[Mono-list] Mono 2.10.4 and WebServiceHost

bert.moorthaemer at gmail.com bert.moorthaemer at gmail.com
Tue Aug 16 04:03:33 EDT 2011


Hi Atsushi,

Here is the code (from Microsofts site)


using System;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Web;

[ServiceContract]
public interface ICalculator {
    [OperationContract]
    [WebGet(UriTemplate = "add?x={x}&y={y}", BodyStyle =
WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
    long Add(long x, long y);

    [OperationContract]
    [WebGet(UriTemplate = "sub?x={x}&y={y}", BodyStyle =
WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
    long Subtract(long x, long y);

    [OperationContract]
    [WebGet(UriTemplate = "mult?x={x}&y={y}", BodyStyle =
WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
    long Multiply(long x, long y);

    [OperationContract]
    [WebGet(UriTemplate = "div?x={x}&y={y}", BodyStyle =
WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
    long Divide(long x, long y);

    [OperationContract]
    [WebGet(UriTemplate = "hello?name={name}", BodyStyle =
WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
    string SayHello(string name);

    [OperationContract]
    [WebGet(UriTemplate = "now", BodyStyle = WebMessageBodyStyle.Wrapped,
ResponseFormat = WebMessageFormat.Json)]
    DateTime Now();
}

public class CalcService: ICalculator {
    public long Add(long x, long y) {
        return x + y;
    }

    public long Subtract(long x, long y) {
        return x - y;
    }

    public long Multiply(long x, long y) {
        return x * y;
    }

    public long Divide(long x, long y) {
        return x / y;
    }

    public string SayHello(string name) {
        return "Hello " + name;
    }

    public DateTime Now() {
        return DateTime.Now;
    }
}

class Program {

    static void Main(string[] args) {
        Uri baseAddress = new Uri("http://192.168.11.5:8080/");

        WebServiceHost svcHost = new WebServiceHost(typeof(CalcService),
baseAddress);

        try {
            svcHost.AddServiceEndpoint(typeof(ICalculator), new
WebHttpBinding(), "calc");
            svcHost.Open();

            Console.WriteLine("Service is running");
            Console.WriteLine("Press enter to quit...");
            Console.ReadLine();

            svcHost.Close();
        } catch (CommunicationException cex) {
            Console.WriteLine("An exception occurred: {0}", cex.Message);
            svcHost.Abort();
        }
    }
}


Pretty straightforward ... I investigated the library code and found the
Console.Write's in the following files ...

mcs/class/System.ServiceModel/System.ServiceModel/ServiceHostBase.cs (line
558)
mcs/class/System.ServiceModel.Dispatcher/BaseRequestProcessor.cs (line 34)

BTW using the mono-2.10 branch from git

TIA

Bert



--
View this message in context: http://mono.1490590.n4.nabble.com/Mono-2-10-4-and-WebServiceHost-tp3744197p3746596.html
Sent from the Mono - General mailing list archive at Nabble.com.


More information about the Mono-list mailing list