C# Mono中的WCF服务不可访问?

C# Mono中的WCF服务不可访问?,c#,wcf,mono,C#,Wcf,Mono,我在linux和os x上都试过,我也遇到了同样的问题。这是MonoDevelop2.6和最新稳定版本的Mono。在我的Mac电脑上是2.10.2版 这几天前对我有用。我会将浏览器指向“http://localhost:8000/number/test然后会得到一条消息,上面写着“在命令行中,键入svcutil”http://localhost:8000/number/test[还有什么]” 现在,我在Linux和Mac上的浏览器中得到的信息是: <Fault xmlns="http://

我在linux和os x上都试过,我也遇到了同样的问题。这是MonoDevelop2.6和最新稳定版本的Mono。在我的Mac电脑上是2.10.2版

这几天前对我有用。我会将浏览器指向“http://localhost:8000/number/test然后会得到一条消息,上面写着“在命令行中,键入svcutil”http://localhost:8000/number/test[还有什么]”

现在,我在Linux和Mac上的浏览器中得到的信息是:

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

调试时是否尝试访问该服务? 从
InternalServiceFault
中,似乎有什么东西导致您的服务失败


Nicklas

Ugh它可以在Windows7-VisualStudio和Mono上运行
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();
        }


    }


}
}