Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Indigo

Vista - Async WCF method call, not using the proxy generated class

 
 
Old 07-01-2006   #1 (permalink)
ewolfman


 
 

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
Old 07-03-2006   #2 (permalink)
ewolfman


 
 

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
Old 07-04-2006   #3 (permalink)
Arkady Frenkel


 
 

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
Old 07-04-2006   #4 (permalink)
Arkady Frenkel


 
 

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
 

Thread Tools


Similar Threads
Thread Forum
When a class is both an inherited class of another, and alsoimplements an interface method .NET General
i want to make async process call in powershell PowerShell
Design for async call .NET General
how to call a static method in a .net class from powershell? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46