views:

1711

answers:

2

I was checking out streaming in the Programming WCF Services book, and I spotted a line about configurating.

You will need to configure the binding on the client or service side (or both) per required stream mode

So what is this? How I know where I should configure them? And is this a common thing with WCF? Seems bit weird to me.

A: 

this is absolutely common! first of all, you need to configure (enable desired bindings) the service (web.config). then you need to create the proxy-class. if done with vs or svc-util your config will be created, otherwise you need to configure the binding within the config of your app (web.config/app.config).

the svcConfigEditor is very useful!

gotcha:
sometimes the project where your proxy-class lies isn't the same as your app-project. vs-studio generates the config inside the proxy-class-project. you can manually copy the needed section to your app.config/web.config or hack the building process to do this for you!

edit:
i thought about this once again: mainly this is intention! if you are going to program a wcf-service you should primarily care about programming your service and not thinking about the way the service will interact with the client. this is then done in the final step with the config!
this opens the possibility to only change the config and not recompile the service and deploy the binaries again, to achieve a different binding/communication way!
i hope you can follow my explanation :)

Andreas Niedermair
But I still need to configure it, no matter if it's automatic or not.
Tuoski
at least you need to configure your service. if you then add a service reference to your project, vs creates the client's config (this works, if there's only one binding - otherwise you need to edit).
Andreas Niedermair
A: 

Here's a really basic example of how to configure a WCF service in your web/app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <services>
            <service name="MyServiceTypes.MyService" >
                <endpoint address="http://localhost:55555/MyService"
                          binding="basicHttpBinding"
                          contract="MyServiceTypes.IMyService" />
            </service>
        </services>
    </system.serviceModel>
</configuration>

On the client side, you want to use the exact same endpoint settings, like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <client>
            <endpoint address="http://localhost:55555/MyService"
                      binding="basicHttpBinding"
                      contract="MyServiceTypes.IMyService" />
        </client>
    </system.serviceModel>
</configuration>

There are a ton of ways to customize the binding, etc. by adding bindingConfiguration sections, and stuff like that. The binding configuration might be where you configure your streaming mode.

It's usually a best practice to put your contract interface; your service and client implementations; and your DataContract types (your data-transfer-objects) in a separate DLL if you can. If you don't have control over the contract (e.g. you are accessing the service on a machine you don't control), an easy way to generate the client side code is to use "Add Service Reference" in Visual Studio, or the svcutil tool. I like svcutil better than Add Service Reference, because it gives you easier control over where the generated code ends up in your project.

Andy White