简体   繁体   中英

How to debug a WCF service in a hosted solution?

I've created a fairly simply web service that has 1 method: UploadFile. Obviously, it works on my machine ©. However, once I upload it, the method return status 202 (Accepted). 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 .

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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