Windows Vista Forums

Async WCF method call, not using the proxy generated class
  1. #1


    ewolfman Guest

    Async WCF method call, not using the proxy generated class

    Hi,

    I attempted to perform an async call to a WCF service, using the same
    technique for calling an async webservice method (Begin/End
    AsyncPattern). This seems to be working ok.

    BUT, it works only if I generate and use a proxy using WSDL. This
    generates from the contract a single method which appears to the client
    as if it is executing synchroniously on the server (which is great).

    I prefer *not* to use the generated proxy (i.e. I use ChannelFactory<T>
    and the CreateChannel() method), so I cannot use the AsyncPattern (on
    the client side) because the interface of my server (which is available
    to the client) has only a Begin/End OperationContract exposed.

    For example:
    Server's interface:

    <code>
    [ServiceContract]
    public interface IServer
    {
    [OperationContract(AsyncPattern = true)]
    IAsyncResult BeginDoSomething(int data, AsyncCallback callback,
    object state);

    // runtime throws error if the OperationContractAttribute is
    placed here, unlike the earlier
    // documentation - but it doesn't matter now...
    void EndDoSomething(IAsyncResult result);
    }
    </code>

    Client code:

    <code>
    ChannelFactory<IServer> factory = new ChannelFactory<IServer>(new
    BasicHttpBinding(), new EndpointAddress(serverAddress));

    IServer server = factory.CreateChannel();

    // i want to be able to do this, just like when i use the proxy,
    // but naturally i cannot because the IServer doesn't have this method.
    server.DoSomething(2);
    </code>

    Using Reflector and reviewing the generated proxy, I saw that the proxy
    inherits from a ClientBase<T>, and performs the call on a
    base.InnerProxy, which eventually is created using CreateChannel() -
    which seems to me pretty much what I am doing so far. What I'm missing
    is how to perform the method call for DoSomething().



    BTW: I don't mind a solution which uses "dirty" invocation (such as
    reflection etc'). It just when I've iterated over the different methods
    available from the remote object on the server, I've received the
    Begin/End methods, but no sign of the DoSomething method.

    Finally, please don't post answers such as "just use the proxy" etc'. I
    know I can use the proxy, but I have my reasons and its quite
    reasonable that its possible to invoke a remote async method not
    necessarily using the proxy class generated by WSDL.

    Thanks.

      My System SpecsSystem Spec

  2. #2


    ewolfman Guest

    Re: Async WCF method call, not using the proxy generated class

    I got it working.

    I figured that the difference between the generated proxy solution and
    my solution was simply the Interface. The generated interface contained
    a single DoSomething method whereas my original interface had the
    Begin/End methods (as explained in my original post).

    So I simply created a new IServer2 interface, which contains the single
    DoSomething method, along with the Action property which identifies it
    uniquely (otherwise there's a "contract mismatched" exception - the
    specific type is ActionNotSupportedException).

    This solved the problem, so my understanding is simply that we have to
    dispatch a remote invocation of the single signatured method
    (DoSomething), and that Indigo does the rest for us on the server side
    (i.e. splits the calls to Begin/End). This sounds logical to me as the
    client should not be aware of the server side implementation.

    Just for the sake of it, I iterated over the Type once more (the
    Transparent proxy), and this time I got the DoSomething method instead
    of the two Begin/End methods. This is a bit weird, because it looks
    like the reflection is affected by the interface and doesn't actually
    reflect the object. I must be missing something here, but its a fact.

    So my new client code looks something like this:
    <code>
    [ServiceContract]
    public interface IServer2 // comes as an addition to IServer
    {
    [OperationContract(Action =
    "http://tempuri.org/IServer/DoSomething")]
    void DoSomething(int data);
    }

    ChannelFactory<IServer2> factory = new ChannelFactory<IServer2>(new
    BasicHttpBinding(), new EndpointAddress(serverAddress));

    IServer2 server = factory.CreateChannel();

    // works !
    server.DoSomething(2);
    </code>

      My System SpecsSystem Spec

  3. #3


    Arkady Frenkel Guest

    Re: Async WCF method call, not using the proxy generated class

    OTOH you do can use proxy but generate it with "svcutil /async ..." which
    create async proxy so you can use async client in this case , using and use
    async behavior of your server
    Arkady

    "ewolfman" <ewolfman@yahoo.com> wrote in message
    news:1151959693.104920.110200@a14g2000cwb.googlegroups.com...
    >I got it working.
    >
    > I figured that the difference between the generated proxy solution and
    > my solution was simply the Interface. The generated interface contained
    > a single DoSomething method whereas my original interface had the
    > Begin/End methods (as explained in my original post).
    >
    > So I simply created a new IServer2 interface, which contains the single
    > DoSomething method, along with the Action property which identifies it
    > uniquely (otherwise there's a "contract mismatched" exception - the
    > specific type is ActionNotSupportedException).
    >
    > This solved the problem, so my understanding is simply that we have to
    > dispatch a remote invocation of the single signatured method
    > (DoSomething), and that Indigo does the rest for us on the server side
    > (i.e. splits the calls to Begin/End). This sounds logical to me as the
    > client should not be aware of the server side implementation.
    >
    > Just for the sake of it, I iterated over the Type once more (the
    > Transparent proxy), and this time I got the DoSomething method instead
    > of the two Begin/End methods. This is a bit weird, because it looks
    > like the reflection is affected by the interface and doesn't actually
    > reflect the object. I must be missing something here, but its a fact.
    >
    > So my new client code looks something like this:
    > <code>
    > [ServiceContract]
    > public interface IServer2 // comes as an addition to IServer
    > {
    > [OperationContract(Action =
    > "http://tempuri.org/IServer/DoSomething")]
    > void DoSomething(int data);
    > }
    >
    > ChannelFactory<IServer2> factory = new ChannelFactory<IServer2>(new
    > BasicHttpBinding(), new EndpointAddress(serverAddress));
    >
    > IServer2 server = factory.CreateChannel();
    >
    > // works !
    > server.DoSomething(2);
    > </code>
    >



      My System SpecsSystem Spec

  4. #4


    Arkady Frenkel Guest

    Re: Async WCF method call, not using the proxy generated class

    Obviously, you don't need proxy in WCF but you can read meta data
    programmatically and behave in advance
    Arkady


    "Arkady Frenkel" <arkadyf@hotmailxdotx.com> wrote in message
    news:%23cVGMDznGHA.956@TK2MSFTNGP03.phx.gbl...
    > OTOH you do can use proxy but generate it with "svcutil /async ..." which
    > create async proxy so you can use async client in this case , using and
    > use async behavior of your server
    > Arkady
    >
    > "ewolfman" <ewolfman@yahoo.com> wrote in message
    > news:1151959693.104920.110200@a14g2000cwb.googlegroups.com...
    >>I got it working.
    >>
    >> I figured that the difference between the generated proxy solution and
    >> my solution was simply the Interface. The generated interface contained
    >> a single DoSomething method whereas my original interface had the
    >> Begin/End methods (as explained in my original post).
    >>
    >> So I simply created a new IServer2 interface, which contains the single
    >> DoSomething method, along with the Action property which identifies it
    >> uniquely (otherwise there's a "contract mismatched" exception - the
    >> specific type is ActionNotSupportedException).
    >>
    >> This solved the problem, so my understanding is simply that we have to
    >> dispatch a remote invocation of the single signatured method
    >> (DoSomething), and that Indigo does the rest for us on the server side
    >> (i.e. splits the calls to Begin/End). This sounds logical to me as the
    >> client should not be aware of the server side implementation.
    >>
    >> Just for the sake of it, I iterated over the Type once more (the
    >> Transparent proxy), and this time I got the DoSomething method instead
    >> of the two Begin/End methods. This is a bit weird, because it looks
    >> like the reflection is affected by the interface and doesn't actually
    >> reflect the object. I must be missing something here, but its a fact.
    >>
    >> So my new client code looks something like this:
    >> <code>
    >> [ServiceContract]
    >> public interface IServer2 // comes as an addition to IServer
    >> {
    >> [OperationContract(Action =
    >> "http://tempuri.org/IServer/DoSomething")]
    >> void DoSomething(int data);
    >> }
    >>
    >> ChannelFactory<IServer2> factory = new ChannelFactory<IServer2>(new
    >> BasicHttpBinding(), new EndpointAddress(serverAddress));
    >>
    >> IServer2 server = factory.CreateChannel();
    >>
    >> // works !
    >> server.DoSomething(2);
    >> </code>
    >>

    >
    >



      My System SpecsSystem Spec

Async WCF method call, not using the proxy generated class problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
When a class is both an inherited class of another, and alsoimplements an interface method Curious .NET General 1 14 Aug 2009
i want to make async process call in powershell isu PowerShell 1 26 Sep 2008
Design for async call Fred .NET General 0 10 Jun 2008
how to call a static method in a .net class from powershell? YY PowerShell 1 11 Sep 2007
Automatic Event Handler method for on the fly generated zammel control Hardikbill Indigo 2 18 Sep 2006