1. 程式人生 > 實用技巧 >wcf首次使用程式碼配置檔案記錄

wcf首次使用程式碼配置檔案記錄

伺服器端配置檔案

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <services>
            <service name="SampleContract.Bird" behaviorConfiguration="Messagebehavior">
                <host>
                    <baseAddresses>
                        <add baseAddress = "
http://localhost:23451/SampleContract/" /> </baseAddresses> </host> <endpoint address="" binding="wsHttpBinding" contract ="SampleContract.IFly" bindingConfiguration="WSHttpBinding_IFly"> </endpoint> </service> </services> <bindings> <wsHttpBinding> <binding name="
WSHttpBinding_IFly"> <security mode="None"></security> </binding> </wsHttpBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name="Messagebehavior
"> <serviceMetadata httpGetEnabled="true"></serviceMetadata> <serviceDebug includeExceptionDetailInFaults="true"></serviceDebug> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" /> </startup> </configuration>

客戶端配置檔案

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
    </startup>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IFly">
                    <security mode="None"></security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://192.168.0.106:23451/SampleContract/" binding="wsHttpBinding"
                bindingConfiguration="WSHttpBinding_IFly" contract="MyServiceReference2.IFly"
                name="WSHttpBinding_IFly">
                <identity>
                    <userPrincipalName value="LAPTOP-UUEOUOB\Alex" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>