【问题标题】:WCF error, service does nothingWCF 错误,服务什么也不做
【发布时间】:2013-08-12 15:44:21
【问题描述】:

我目前在调用 WCF 服务时遇到以下错误:

由于内部错误,服务器无法处理请求

但是我不明白这是怎么回事,因为我正在运行的方法实际上并没有做任何事情

界面:

[ServiceContract]
public interface IPrinterManager
{
    [OperationContract]
    Printer GetPrinter(int printerId);
}

服务:

public class PrinterManager : IPrinterManager
{
    public PrinterManager()
    {
               }

    public Printer GetPrinter(int printerId)
    {
       return null;
    }
}

客户:

 private Printer GetRequestedPrinter(int eventLocation)
    {
        ChannelFactory<IPrinterManager> channelFactory = new ChannelFactory<IPrinterManager>(new BasicHttpBinding(), "http://localhost:9877/printers");
        IPrinterManager printerManager = channelFactory.CreateChannel();

        int printerId = (int) _PlcClient.ReadItem(_PlcPrinterIdWords[eventLocation], true);
        Printer printer = printerManager.GetPrinter(printerId);
        return printer;
    }

我不明白为什么会出错?

谁能指点我正确的方向?

谢谢

【问题讨论】:

  • 在调试器中单步执行时,能否确认错误发生在GetPrinter()调用上?
  • 是的,在调试器中单步执行时会出现同样的错误
  • 我认为你返回 null 是问题所在。否则先尝试使用 void 方法

标签: c# wcf self-hosting


【解决方案1】:

设置你的 includeExceptionDetailsInFaults = true

<serviceDebug includeExceptionDetailInFaults="true" />

并开启追踪

http://msdn.microsoft.com/en-us/library/ms733025.aspx

这应该为您提供关于正在发生的事情的更清晰的解释。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-23
    • 1970-01-01
    相关资源
    最近更新 更多