简体   繁体   English

如何在托管解决方案中调试WCF服务?

[英]How to debug a WCF service in a hosted solution?

I've created a fairly simply web service that has 1 method: UploadFile. 我创建了一个相当简单的Web服务,它有一个方法:UploadFile。 Obviously, it works on my machine ©. 显然,它适用于我的机器©。 However, once I upload it, the method return status 202 (Accepted). 但是,一旦我上传它,方法返回状态202(已接受)。 However, the file never arrives there and there are no errors that I can see. 但是,文件永远不会到达那里,并且没有我能看到的错误。 I've added logging to pretty much every second like of code, but it does not seem like the method actually executes. 我几乎每秒都添加了日志记录,就像代码一样,但它似乎并不像实际执行的那样。

How do I debug something like that? 我该如何调试这样的东西?

Here is my server-side code for reference: 这是我的服务器端代码供参考:

[ServiceContract]
interface IUploaderService
{
    [OperationContract(IsOneWay = true)]
    [WebInvoke(Method = "POST", UriTemplate = "/UploadFile?fileName={fileName}")]
    void UploadFile(string fileName, Stream fileContents);
}


[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class UploaderService : IUploaderService //ServiceHostFactory
{
    public void UploadFile(string fileName, Stream fileContents)
    {
        Log.Add("In UploadFile");
    }
}

You have an interesting problem, and I played around with it and wrote a solution in the post at http://blogs.msdn.com/b/carlosfigueira/archive/2011/08/02/wcf-extensibility-system-diagnostic-tracing.aspx . 你有一个有趣的问题,我玩了它并在http://blogs.msdn.com/b/carlosfigueira/archive/2011/08/02/wcf-extensibility-system-diagnostic-的帖子中写了一个解决方案。 tracing.aspx

Basically, instead of tracing to a file (which is the usual way of doing tracing), you'd add a custom trace listener which would collect the traces from your application. 基本上,您不是跟踪文件(这是执行跟踪的常用方法),而是添加一个自定义跟踪侦听器,它将从您的应用程序中收集跟踪。 You can use one of the databases provided by GoDaddy (MySql, SqlServer, EasyDB), or like in the code sample linked in the post, store the traces in memory and expose them via another WCF service. 您可以在帖子中链接的代码示例中使用GoDaddy(MySql,SqlServer,EasyDB)等提供的数据库之一,将跟踪存储在内存中,并通过另一个WCF服务公开它们。

try following 尝试下面

[ServiceContract]
interface IUploaderService
{
    [OperationContract(IsOneWay = true)]
    [WebInvoke(Method = "POST", UriTemplate = "/UploadFile?fileName={fileName}")]
    [WebContentType("application/octet-stream")]
    void UploadFile(string fileName, Stream fileContents);
}

If it doesn't work I would also try 如果它不起作用我也会尝试

[OperationContract]

this way if something happens on service you will have feedback on client side. 这样,如果在服务上发生某些事情,您将在客户端获得反馈。

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

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