Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF Service in Mono not accessible?

Tags:

c#

wcf

mono

I have tried this both on linux and os x and am having the same issue. This is MonoDevelop 2.6 with the most recent stable version of Mono. On my Mac thats v 2.10.2.

This used to work for me a few days ago. I would point my browser to "http://localhost:8000/number/test" and would get a message that said something like "In the command line, type svcutil http://localhost:8000/number/test[somethingmore]"

Now the message I get on both Linux and Mac in the browser is:

<Fault xmlns="http://schemas.microsoft.com/ws/2005/05/envelope/none">

a:InternalServiceFault The server was unable to process the request due to an internal error. The server may be able to return exception details (it depends on the server settings).

This used to work, so I'm not sure if I'm missing something important or if something is wrong with Mono or what. I hope you have an idea. This is all pretty much straight from the MSDN tutorial (with some changes).

(For those in the know, I am aware that this so far can't save state because it isn't yet set up for sessions, I'm was working to get there when I got this error).

Here are my classes:

using System;
using System.ServiceModel;

namespace NumberService
  {
[ServiceContract]
public interface INumberService
{
    [OperationContract]
    void Add(int val);

    [OperationContract]
    void Subtract(int val);

    [OperationContract]
    int Result();
}
}

using System;

namespace NumberService
{
public class NumberService : INumberService
{
    private int val = 1;


    public NumberService ()
    {
        Console.WriteLine("NumberService created.");
    }

    public void Add(int val)
    {
        this.val += val;    
    }

    public void Subtract(int val)
    {
        this.val -= val;
    }


    public int Result()
    {
        return val;
    }
}
}



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

namespace NumberService
{
class MainClass
{
    public static void Main (string[] args)
    {
        Uri uri = new Uri("http://localhost:8000/number/test");

        ServiceHost selfHost = new ServiceHost(typeof(NumberService), uri);


        try
        {


            // Step 3 of the hosting procedure: Add a service endpoint.
            selfHost.AddServiceEndpoint(
                typeof(INumberService),
                new WSHttpBinding(SecurityMode.None),
                "NumberService");


            // Step 4 of the hosting procedure: Enable metadata exchange.
            ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
            smb.HttpGetEnabled = true;
            selfHost.Description.Behaviors.Add(smb);

            // Step 5 of the hosting procedure: Start (and then stop) the service.
            selfHost.Open();
            Console.WriteLine("The service is ready.");
            Console.WriteLine("Press <ENTER> to terminate service.");
            Console.WriteLine();
            Console.ReadLine();

            // Close the ServiceHostBase to shutdown the service.
            selfHost.Close();
        }
        catch (CommunicationException ce)
        {
            Console.WriteLine("An exception occurred: {0}", ce.Message);
            selfHost.Abort();
        }


    }


}
}
like image 355
Ben B. Avatar asked Nov 13 '22 16:11

Ben B.


1 Answers

Have you tried to access the service when you are debugging? From the InternalServiceFault it seems like something is causing your service to fail.

Nicklas

like image 55
Nicklas Møller Jepsen Avatar answered Dec 22 '22 01:12

Nicklas Møller Jepsen