简体   繁体   中英

Calling a WCF method from a WPF client does nothing

I have a very simple WCF service running that has a single method that returns an enum based on the result of the method.

I have tested this WCF service through a very simple console app both locally and over the internet to my server and both work perfectly fine. However once I use the, literally exact, code in my WPF application calling the method does nothing. No exception, no timeout. Testing it locally with a breakpoint at the start of the WCF method I found it does not even reach that far when calling it from WPF.

Both service reference configurations that were generated in the app.config are identical between the console and WPF application.

Edit: Had hoped to not need to put as much code in here but I'll just dump the whole thing.

In WPF the code is being called from a button in a dialog. This button triggers an Coroutine call using Caliburn.Micro. The WCF call is then being called in the Execute method from the Coroutine.

public IEnumerator<IResult> SendReport()
{
    var result = new Coroutines.SubmitNewExceptionIssueResult(Exception, UserNotes, Character);
    yield return result;
    if (result.Result == ErrorReportResult.OK)
        TryClose();
    else
        // TODO
}

public class SubmitNewExceptionIssueResult : IResult
{
    public event EventHandler<ResultCompletionEventArgs> Completed;
    private ErrorReporterClient _client = new ErrorReporterClient();

    private Exception _exception { get; set; }
    private string _userNotes { get; set; }
    private Character _character { get; set; }
    public ErrorReportResult Result { get; private set; }

    public SubmitNewExceptionIssueResult(Exception ex, string userNotes, Character character)
    {
        _exception = ex;
        _userNotes = userNotes;
        _character = character;
    }

    public void Execute(ActionExecutionContext context)
    {
        Result = _client.SendErrorReport(JsonConvert.SerializeObject(_exception, new JsonSerializerSettings
                                         {
                                             TypeNameHandling = TypeNameHandling.All
                                         }),
                                         _userNotes,
                                         JsonConvert.SerializeObject(_character, new JsonSerializerSettings
                                         {
                                             TypeNameHandling = TypeNameHandling.All
                                         }));
        Completed(this, new ResultCompletionEventArgs());
    }
}

The cause was indeed threading of some sort. While not happy with the implementation it now works.

Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal, new System.Action(() => { /* send report code */ }));

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