link/Files/callwangxiang/SimpleWCF.rar

为了简化WCF的开发,我们可以通过在项目中Add Service Reference的方式(或svcutil)生成一个代理类。
后来P&P提供了Service Factory,该工程可以帮助我们设计WCF, 并根据需要灵活选择WS-*或WCF实现、代码自动生成、配置的工作。
这两种方式生成的客户端代理都回包括一份重复的Service Contract、Data Contract(还有MessageContract、FaultContact定义),

不过就像我们不会在一些大些的项目中直接托拽Connection\Command空间辅助数据访问一样,用这些工具生成的代码、配置文件包括非常多的“垃圾”,
另外,同一份实体编译两次也不利于我们部署。

不妨回归到本来的WCF代码,我们采用类似Remoting的方式,下面是一个瘦身之后的示例:
避免WCF Service Reference 和 WCF Service Factory的误导作用
采用该方式的优势:
1、实体一致性, 便于在企业(或行业)内实施全局WCF项目时,标准业务实体重复定义,可以直接服务于行业XML DM(Data Model)或MDM(Master Data Management),可以在多个项目组的Service、Client分发标准业务实体
2、干净,没有“脏”的重复代码和配置
3、符合服务分层结构,
避免WCF Service Reference 和 WCF Service Factory的误导作用

1、Common.dll
避免WCF Service Reference 和 WCF Service Factory的误导作用[DataContract]
避免WCF Service Reference 和 WCF Service Factory的误导作用
public class Complex

2、Host.exe

避免WCF Service Reference 和 WCF Service Factory的误导作用public class CalculatorService : ICalculator
}

避免WCF Service Reference 和 WCF Service Factory的误导作用<?xml version="1.0" encoding="utf-8" ?>
避免WCF Service Reference 和 WCF Service Factory的误导作用
<configuration>
避免WCF Service Reference 和 WCF Service Factory的误导作用  
<system.serviceModel>
避免WCF Service Reference 和 WCF Service Factory的误导作用    
<services>
避免WCF Service Reference 和 WCF Service Factory的误导作用      
<service name="Host.CalculatorService">
避免WCF Service Reference 和 WCF Service Factory的误导作用        
<endpoint 
避免WCF Service Reference 和 WCF Service Factory的误导作用          
address="http://localhost:8000/Derivatives/Calculator"
避免WCF Service Reference 和 WCF Service Factory的误导作用          binding
="wsHttpBinding"         
避免WCF Service Reference 和 WCF Service Factory的误导作用          contract
="Common.ICalculator" />
避免WCF Service Reference 和 WCF Service Factory的误导作用      
</service>
避免WCF Service Reference 和 WCF Service Factory的误导作用    
</services>
避免WCF Service Reference 和 WCF Service Factory的误导作用  
</system.serviceModel>
避免WCF Service Reference 和 WCF Service Factory的误导作用
</configuration>
避免WCF Service Reference 和 WCF Service Factory的误导作用

避免WCF Service Reference 和 WCF Service Factory的误导作用static void Main(string[] args)
}

3、Client.exe
避免WCF Service Reference 和 WCF Service Factory的误导作用<?xml version="1.0" encoding="utf-8" ?>
避免WCF Service Reference 和 WCF Service Factory的误导作用
<configuration>
避免WCF Service Reference 和 WCF Service Factory的误导作用  
<system.serviceModel>
避免WCF Service Reference 和 WCF Service Factory的误导作用    
<client>
避免WCF Service Reference 和 WCF Service Factory的误导作用      
<endpoint name="CalculatorService"
避免WCF Service Reference 和 WCF Service Factory的误导作用                      address
="http://localhost:8000/Derivatives/Calculator"
避免WCF Service Reference 和 WCF Service Factory的误导作用                      binding
="wsHttpBinding"
避免WCF Service Reference 和 WCF Service Factory的误导作用                      contract
="Common.ICalculator"/>
避免WCF Service Reference 和 WCF Service Factory的误导作用    
</client>
避免WCF Service Reference 和 WCF Service Factory的误导作用  
</system.serviceModel>
避免WCF Service Reference 和 WCF Service Factory的误导作用
</configuration>

避免WCF Service Reference 和 WCF Service Factory的误导作用static void Main(string[] args)
}

相关文章:

  • 2022-12-23
  • 2021-12-29
  • 2021-11-19
  • 2022-12-23
  • 2021-07-10
  • 2022-02-10
猜你喜欢
  • 2021-11-28
  • 2021-11-16
  • 2022-01-16
  • 2021-10-18
  • 2022-12-23
  • 2022-01-26
  • 2021-09-23
相关资源
相似解决方案