繁体   English   中英

Mono中的WCF服务无法访问?

[英]WCF Service in Mono not accessible?

我在linux和os x上都尝试过这个问题并且遇到了同样的问题。 这是具有最新稳定版Mono的MonoDevelop 2.6。 在我的Mac上,即2.10.2。

这几天前曾经对我有用。 我会将我的浏览器指向“http:// localhost:8000 / number / test”并收到一条消息,上面写着“在命令行中输入svcutil http:// localhost:8000 / number / test [somethingmore] “

现在我在浏览器中看到Linux和Mac上的消息是:

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

a:InternalServiceFault由于内部错误,服务器无法处理请求。 服务器可能能够返回异常详细信息(这取决于服务器设置)。

这曾经有用,所以我不确定我是否遗漏了一些重要的东西,或者Mono或者是什么问题。 我希望你有个主意。 这一切都非常直接来自MSDN教程(有一些更改)。

(对于那些知道的人,我知道到目前为止这还不能保存状态,因为它尚未设置会话,当我收到此错误时,我正努力到达那里)。

这是我的课程:

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();
        }


    }


}
}

您在调试时是否尝试访问该服务? InternalServiceFault ,似乎有些事情导致您的服务失败。

尼克拉斯

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM