首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NetNamedPipeBinding ActionNotSupportedException

NetNamedPipeBinding ActionNotSupportedException
EN

Stack Overflow用户
提问于 2011-11-01 16:35:18
回答 1查看 599关注 0票数 0

我正在运行一个类似于MS计算器示例的服务。这是ServiceContract合同接口。

代码语言:javascript
复制
[ServiceContract(Namespace = "http://localhost:8000/Calculator")]
public interface ICalculator
{
    [OperationContract]
    double Add(double n1, double n2);
    [OperationContract]
    double Subtract(double n1, double n2);
    [OperationContract]
    double Multiply(double n1, double n2);
    [OperationContract]
    double Divide(double n1, double n2);
}

我将服务设置如下:

代码语言:javascript
复制
public partial class Service1: ServiceBase
{
    private static readonly string sNameOfService = "CalculatorService";
    public static string NameOfService
    {
        get { return sNameOfService; }
    }

    public ServiceHost serviceHost = null;

    public Service1()
    {
        InitializeComponent();

        this.ServiceName = sNameOfService;
        this.CanStop = true;
        this.CanPauseAndContinue = false;
        this.AutoLog = true;
    }

    protected override void OnStart(string[] args)
    {
        if (serviceHost != null)
            serviceHost.Close();

        Uri[] baseAddress = new Uri[]{
      new Uri("net.pipe://localhost")};

        string PipeName = "Calculator";

        serviceHost = new ServiceHost(typeof(CalculatorImplementation), 

        serviceHost.AddServiceEndpoint(typeof(ICalculator), new NetNamedPipeBinding(), PipeName);

        serviceHost.Open();
    }

    protected override void OnStop()
    {
        if (serviceHost != null && serviceHost.State != CommunicationState.Closed)
        {
            serviceHost.Close();
            serviceHost = null;
        }
    }
}

我成功地安装了该服务,并且它正在我的本地机器上运行。下一步是设置一个客户端,访问服务,我用下面的方式做了。

代码语言:javascript
复制
public interface ICalculator
{
    // die einzelnen Teile können auch als Vorgänge bzw. Kanäle verstanden werden
    // öffentliche Teile des Interfaces definieren
    // diese werden durch das OperationContract Attribut identifiziert
    [OperationContract]
    double Add(double n1, double n2);
    [OperationContract]
    double Subtract(double n1, double n2);
    [OperationContract]
    double Multiply(double n1, double n2);
    [OperationContract]
    double Divide(double n1, double n2);
}

class Program
{
    static void Main(string[] args)
    {
        ChannelFactory<ICalculator> pipeFactory = new ChannelFactory<ICalculator>(new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/Calculator"));

        ICalculator pipeProxy = pipeFactory.CreateChannel();

        double erg = pipeProxy.Add(5, 6);

        Console.WriteLine("Ergebnis: {0}", erg.ToString());
        Console.ReadLine();
    }
}

但是当我试图调用"pipeProxy.Add()“时,我得到了一个ActionNotSupportedException,我不知道为什么会发生这种情况。是我的服务器没有正确设置,还是我的客户端出了什么问题,或者我错过了一些需要的属性?我浏览了多个使用命名管道的示例,但我没有找到任何帮助我解决问题的方法。

此外,我问自己,有什么区别,我应该在哪里使用ServiceHost实现和NamedPipeClientStream/NamedPipeServerStream实现?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-11-01 16:59:13

当客户端使用服务器未知的SOAP操作时,会抛出ActionNotSupportedException。缺省情况下,SOAP操作的名称是从服务契约和操作契约的类型中推断出来的。

在您的示例中,我看到该合同定义了两次。这是否意味着服务和客户端都有自己的ICalculator定义?在这种情况下,无需进一步的努力,这两个约定是不同的,因为它们很可能位于不同的命名空间中,并且第一个约定指定了自己的命名空间,而第二个约定没有指定自己的命名空间。如果您想使用相同的接口,请将其放在单独的程序集上,并引用来自服务和客户端的程序集。否则,您将不得不检查ServiceContractOperationContract属性,并确保NamespaceActionReplyAction的值在两个接口中相同。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7964092

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档