locked
Portal Library: Unable / Unsure how to Call Async Task Web Method

    Question

  • Hello,

    I have a Cloud Service, that has a method that is defined like this

    [OperationContract]
    Task<bool> TestMethod();

    I then implemented

    public async Task<bool> TestMethod()
    {
       System.Threading.Thread.Sleep(5000);
       return true;
    }

    Now this isn't really my implementation but I have the same issue with my real implementation

    Start a new universal portable library

    Add a service reference

    The issue is, it will only show "Void" as the return type, not "awaitable bool".

    I've added the BCL libraries. I've tried targeting only certain things...

    It just doesn't seem to work. I can add the same reference to a console app etc and it works fine.

    Shouldn't this be possible?

    Please any suggestions would be awesome.

    Thanks!!


    Tuesday, May 20, 2014 12:12 AM

All replies

  • How did you add the service reference? I'm asking because I don't have that option in VS2013 with universal projects.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, May 20, 2014 1:08 PM
    Moderator
  • Hi Matt,

    Good question, forgot to mention that. It's... sort of a little buggy (how to get it to work imho)

    If you start a new project it includes Windows Phone / Windows 8.1

    As you say, if you click you cannot see Add Service Reference.

    Go to Properties, add .NET 4.5. Still you cannot see it.

    Now intentionally uncheck Windows Phone 8.1, and check Silverlight 5 and apply. The project now changes to .NET Framework 4.5, Windows 8 and Windows Phone Silverlight 8, but.... the Silverlight 5 checkmark is gone, and Windows 8.1 Phone is no longer checked.

    Now you can add the reference.

    What is also very odd is.. if you go back in and Check Silverlight 5 it will not stay checked.

    Also on top of that if you initially merely change to Windows 8, Windows Phone Silverlight 8 and do nothing else. .NET 4.5 is added, Windows Phone 8.1 stays checked and you cannot add it. Again, check Silverlight 5 and click Ok... It will all change to what I said above.

    At least it does for me with 2013 UR 2 RC (and any other patches)

    Cheers

    Tuesday, May 20, 2014 1:29 PM
  • I am not following this at all.

    "Go to Properties, add .NET 4.5. Still you cannot see it. "
    Where do I do this? properties of what?


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, May 21, 2014 2:19 PM
    Moderator
  • See below.

    Problem: (again), Async web methods are NOT showing up as async web methods (web api/controller/mvc)

    You, asked me "How did you add the service reference? I'm asking because I don't have that option in VS2013 with universal projects."

    So I am answering your question on how you get the ability to add the service reference.

    As I said it's trick, goofy.. who knows (maybe now that I am updating to RTM of RC 2 it won't be)

    If you start a new project it includes Windows Phone / Windows 8.1

    As you say, you cannot see Add Service Reference option when you right click the references "listing in the UI"

    Go to Properties of the project, add(check) .NET 4.5.  and apply that. When you right click the project Still you cannot see it.

    Now go back into project properties and change the target platform. Intentionally uncheck Windows Phone 8.1, and check Silverlight 5 and apply. The project now changes  the target to .NET Framework 4.5, Windows 8 and Windows Phone Silverlight 8, but.... the Silverlight 5 checkmark that you added is gone, and Windows 8.1 Phone is no longer checked.

    However... Now you can add the reference.

    What is also very odd is.. if you go back into try to retarget and Check Silverlight 5 it will not stay checked. (no matter what it won't)

    Also on top of that if you initially (with a new project) merely change to Windows 8, Windows Phone Silverlight 8 and do nothing else. .NET 4.5 becomes targeted, Windows Phone 8.1 stays checked and yet you cannot "Add Service Reference" it. Again, check Silverlight 5 and click Ok... It will all change to what I said above and now you can add it.

    weird.

    I guess at the end of the day though, none of that really matters. My question is merely why can I not use Async Task based Web Api's from a Portable Library, as they do not come across as Async Task, but instead always just Void (or I can do the async with events), which is not what I want.

    Again, if I point to the exact same Wep Api from anything other than the PCL, it shows up as Async Task no problem

    Thanks

    Thursday, May 22, 2014 12:36 AM