开发者

Number of classes under one proxyClient in wcf

I want to know is it possible to create one wcf proxy client that have separated classes that hold number of methods ?

Meaning for example :

SomeClient _client = new SomeClient();
_client.Class1.SomeMethod();
_client.Class2.SomeMethod();

all of that in the same service and interface ?

in all what i want is to group the method under one class 开发者_运维问答with distinc name and in one service.

Thanks

Guy


You're not going to be able to do this with a ServiceReference WCF Proxy, no. It just doesn't generate the proxies that way.

You could wrap the proxy in classes that pass the methods you want to the proxy but otherwise do nothing.

Another option, if you have control over the service itself, is to separate the methods into separate services. Given your apparent desire to have separation of concerns, this may be a good option to pursue.

could you explain alittle bit more on the second part of your answer please. with example

There are multiple ways to accomplish this. This example is incomplete and doesn't feature important error handling and proxy instantiation. I'll leave that for you.

public class Svc1
{
    private Proxy proxy; 
    public void Method1(string param)
    {
        Proxy.Method1(param);
    }
}

public class Svc2
{
    private Proxy proxy;
    public int Method2()
    {
        return Proxy.Method2();
    }
}

public class MegaProxy
{
    public Svc1 Class1 {get; set;}
    public Svc2 Class2 {get; set;}
}

i dont want the programmer of the client side use many services, you know just writing all of the using statement is confusing, i want to give it to him plan and simple under one proxy

Hmm... I see some unfortunate assumptions in your statement here. I'm guessing you're relatively new to WCF, and that's fine, but that means you haven't run into this problem yet: Never, ever use using on a WCF proxy. The reason is that the Dispose method of WCF proxies can throw in certain circumstances -- primarily f the service call faulted. This can lead to some surprisingly ugly problems if you're not aware of the issue. It's almost always best to use an Open Proxy => Call Service => Close Proxy paradigm instead.

That said, I don't think it would be too different for your client to call separate services than to call methods on separate fields of a single proxy. If anything, separate services would allow your client better control over when and how a proxy is created.

If you have control over the client code -- if you're providing the proxy itself as a .DLL, for example -- you could build a static class with static methods that instantiate the different proxies for the client.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜