用VisualStudio2010学习WCF服务编程总结(2)契约的继承
契约的设计
1 namespace MyService
2 {
3 [ServiceContract]
4 public interface IPerson
5 {
6 [OperationContract]
7 string Say(string say);
8 }
9 [ServiceContract]
10 public interface IStudent : IPerson
11 {
12 [OperationContract]
13 string Study(string study);
14 }
15 }
2 {
3 [ServiceContract]
4 public interface IPerson
5 {
6 [OperationContract]
7 string Say(string say);
8 }
9 [ServiceContract]
10 public interface IStudent : IPerson
11 {
12 [OperationContract]
13 string Study(string study);
14 }
15 }
契约的服务类型
1 namespace MyService
2 {
3 public class Service1 : IStudent
4 {
5 public string Study(string study)
6 {
7 return "2." + study;
8 }
9
10 public string Say(string say)
11 {
12 return "1."+say;
13 }
14 }
15 }
2 {
3 public class Service1 : IStudent
4 {
5 public string Study(string study)
6 {
7 return "2." + study;
8 }
9
10 public string Say(string say)
11 {
12 return "1."+say;
13 }
14 }
15 }
配置文件
1 <system.serviceModel>
2 <services>
3 <service behaviorConfiguration="MyService.Service1Behavior" name="MyService.Service1">
4 <endpoint address="" binding="wsHttpBinding" contract="MyService.IStudent">
5 <identity>
6 <dns value="localhost" />
7 </identity>
8 </endpoint>
9 <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
10 </service>
11 </services>
12 <behaviors>
13 <serviceBehaviors>
14 <behavior name="MyService.Service1Behavior">
15 <serviceMetadata httpGetEnabled="true"/>
16 <serviceDebug includeExceptionDetailInFaults="false"/>
17 </behavior>
18 </serviceBehaviors>
19 </behaviors>
20 </system.serviceModel>
2 <services>
3 <service behaviorConfiguration="MyService.Service1Behavior" name="MyService.Service1">
4 <endpoint address="" binding="wsHttpBinding" contract="MyService.IStudent">
5 <identity>
6 <dns value="localhost" />
7 </identity>
8 </endpoint>
9 <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
10 </service>
11 </services>
12 <behaviors>
13 <serviceBehaviors>
14 <behavior name="MyService.Service1Behavior">
15 <serviceMetadata httpGetEnabled="true"/>
16 <serviceDebug includeExceptionDetailInFaults="false"/>
17 </behavior>
18 </serviceBehaviors>
19 </behaviors>
20 </system.serviceModel>