1.服务端配置如下(一个Service节点下可有多个endpoint,):
1 1<system.serviceModel> 2 2 <services> 3 3 <service name="Microsoft.ServiceModel.Samples.CalculatorService" behaviorConfiguration="returnFaults"> 4 4 <endpoint address="http://localhost:8000/GIX4" binding ="customBinding" 5 5 bindingConfiguration="compactBindingConfig" contract="Microsoft.ServiceModel.Samples.ICalculator"/> 6 6 <endpoint address="basic" binding="basicHttpBinding" contract="Microsoft.ServiceModel.Samples.ICalculator"></endpoint> 7 <!--前面加个basic基址就变成了http://localhost:8000/GIX4/basic--> 8 7 <endpoint address="secure" binding="wsHttpBinding" contract="Microsoft.ServiceModel.Samples.ICalculator"></endpoint> 9 8 <host> 10 9 <baseAddresses> 11 10 <add baseAddress="http://localhost:8000/GIX4"/> 12 11 </baseAddresses> 13 12 </host> 14 13 </service> 15 14 </services> 16 15 </system.serviceModel>
2. 客户端配置:
1 <system.serviceModel> 2 <bindings> 3 <basicHttpBinding> 4 <binding name="BasicHttpBinding_ICalculator" /> 5 </basicHttpBinding> 6 <customBinding> 7 <binding name="CustomBinding_ICalculator"> 8 <binaryMessageEncoding /> 9 <httpTransport /> 10 </binding> 11 </customBinding> 12 <wsHttpBinding> 13 <binding name="WSHttpBinding_ICalculator" /> 14 </wsHttpBinding> 15 </bindings> 16 <client> 17 <endpoint address="http://localhost:8000/GIX4" binding="customBinding" 18 bindingConfiguration="CustomBinding_ICalculator" contract="Calculator.Service.ICalculator" 19 name="CustomBinding_ICalculator" /> 20 <endpoint address="http://localhost:8000/GIX4/basic" binding="basicHttpBinding" 21 contract="Calculator.Service.ICalculator" 22 name="basic" /> 23 <endpoint address="http://localhost:8000/GIX4/secure" binding="wsHttpBinding" 24 contract="Calculator.Service.ICalculator" 25 name="secure"> <!--加上一个名字--> 26 <identity> 27 <userPrincipalName value="chenlh@huawei" /> 28 </identity> 29 </endpoint> 30 </client> 31 </system.serviceModel>
3.客户端声明如下:
1 CalculatorClient client = new CalculatorClient("basic");