How to config clients for a wcf service?

后端 未结 1 1704
一整个雨季
一整个雨季 2020-12-21 00:17

I am developing a wcf service . I have created two dll\'s one for message contracts and one for service contracts interfaces. I share these two dll\'s with server and client

相关标签:
1条回答
  • 2020-12-21 01:03

    Use an app.config like this (when you use "Add Service Reference" from Visual Studio, VS will typically create this for you automatically - and you just need to tweak it to your needs):

    <configuration>
        <system.serviceModel>
            <bindings>
              <basicHttpBinding>
                <binding name="UserNameSecurity">
                  <security mode="Message">
                    <message clientCredentialType="UserName"/>
                  </security>
                </binding>
              </basicHttpBinding>
            </bindings>
            <client>
                <endpoint address="http://localhost:8888/MyService" binding="basicHttpBinding"
                    bindingConfiguration="UserNameSecurity" contract="IMyService" />
                <endpoint address="net.tcp://localhost:8484/MyService/Mex" 
                          binding="mexTcpBinding"
                          bindingConfiguration="" 
                          contract="IMetadataExchange" name="mexNetTcp" />
            </client>
        </system.serviceModel>
    </configuration>
    

    The section and its possible values and subsection are well documented in the WCF configuration.

    Alternatively, in VS 2008 SP1, you can use the "WCF Service Configuration Editor" - see it in "Tools > WCF Service Configuration Editor".

    alt text

    It allows you to visually define and modify your client config settings. Once you've launched it from the Tools menu, after that, you can acutally even right-click on the app.config in your Solution Explorer and launch it from there (using that app.config as its basis).

    alt text

    Marc

    0 讨论(0)
提交回复
热议问题