WCF多服务配置
自己最近在写WCF的多服务搭建,然后遇到一些问题,特此做一些整理,希望可以帮到有缘人。
以下是相关代码处理,首先创建对应的WCF服务程序:
配置代码:
<system.serviceModel>
</system.serviceModel>
在配置文件中,其实发现在配置多文件的时候,baseAddresses其实并不需要,具体原因自己可以百度一下,最关键的一点就是对应的serviceHostingEnvironment 部分,在配置多服务时候要进行添加。
接口代码:
[ServiceContract(Name = “CAService”, Namespace = “www.valorcomm.com”)]
public interface ICAService
{
///
/// CA认证RUNCMD方法传参
///
///
///
/// ]
[OperationContract]
[WebInvoke(Method = “GET”, BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
string CaRunCommand(int signType, int command, string objectJsion);
接口实现代码:
namespace MedExCAService.ServiceInterface
{
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[JavascriptCallbackBehavior(UrlParameterName = “jsoncallback”)]
public class CAService : ICAService
{
public string CaRunCommand(int signType, int command, string objectJsion)
## 此处上方的AspNetCompatibilityRequirements是添加跨域处理的,会在接下来的下一篇文章中有介绍
主程序启动服务,此处没有什么介绍,和一般的常规服务启动一致:
m_WECGServiceHost = new ServiceHost(typeof(MedExCAService.ServiceInterface.CAService), caaddress);//实例化服务对象
自己处理就好。