public void MergeData(ServiceMetadata other) { this.ServiceTypes.AddRange(other.ServiceTypes); foreach (var item in other.RequestTypes) { this.RequestTypes.Add(item); } foreach (var item in other.ResponseTypes) { this.ResponseTypes.Add(item); } foreach (var item in other.OperationTimeoutMap) { this.OperationTimeoutMap[item.Key] = item.Value; } foreach (var item in other.OperationNameMap) { this.OperationNameMap.Add(item.Key, item.Value); } this.Routes.RestPaths.AddRange(other.Routes.RestPaths); }
/// <summary> /// 拿到继承实现了CServiceInterface接口的class /// </summary> /// <param name="serviceFactoryFn"></param> /// <param name="serviceType"></param> public void RegisterGService(ITypeFactory serviceFactoryFn, Type serviceType) { if (serviceType.IsAbstract || serviceType.ContainsGenericParameters) { return; } //IService foreach (var serviceIntf in serviceType.GetInterfaces()) { // Is this service supported by AntServiceStack if (!serviceIntf.HasAttribute <AntServiceInterfaceAttribute>()) { continue; } // Copy service name and namespace from CServiceInterface attribute 只拿第一个 var cserviceAttribute = serviceIntf.AttributesOfType <AntServiceInterfaceAttribute>().First(); //拿到服务名称 服务的命名空间 和 CodeGen的版本号 ServiceMetadata serviceMetadata = new ServiceMetadata( serviceType, cserviceAttribute.ServiceName, cserviceAttribute.ServiceNamespace, cserviceAttribute.CodeGeneratorVersion); if (MetadataMap.ContainsKey(serviceMetadata.ServicePath)) { MetadataMap[serviceMetadata.ServicePath].MergeData(serviceMetadata); } else { MetadataMap[serviceMetadata.ServicePath] = serviceMetadata; } // reflect methods in service interface 拿到controller里面的所有的action foreach (MethodInfo methodInfoIntf in serviceIntf.GetMethods()) { //实现了接口的action MethodInfo methodInfoImpl = serviceType.GetMethod(methodInfoIntf.Name, BindingFlags.Public | BindingFlags.Instance); //注册action RegisterGServiceMethodExecutor(serviceMetadata.ServicePath, serviceMetadata.ServiceName, serviceType, methodInfoImpl, serviceFactoryFn); var responseType = methodInfoIntf.ReturnType; bool isAsync = responseType.FullName.StartsWith("System.Threading.Tasks.Task`1"); if (isAsync) { responseType = responseType.GetGenericArguments()[0]; } if (responseType == typeof(void)) { responseType = null; } Type requestType = methodInfoIntf.GetParameters()[0].ParameterType; RegisterCommon(serviceMetadata.ServicePath, serviceType, methodInfoImpl, requestType, responseType, isAsync); } } }
public MetadataPagesConfig( ServiceMetadata metadata, ServiceEndpointsMetadataConfig metadataConfig, HashSet <string> ignoredFormats, List <string> contentTypeFormats) { this.ignoredFormats = ignoredFormats; this.metadata = metadata; metadataConfigMap = new Dictionary <string, MetadataConfig> { { "xml", metadataConfig.Xml }, { "json", metadataConfig.Json }, { "jsv", metadataConfig.Jsv }, { "soap11", metadataConfig.Soap11 }, }; AvailableFormatConfigs = new List <MetadataConfig>(); var config = GetMetadataConfig("xml"); if (config != null) { AvailableFormatConfigs.Add(config); } config = GetMetadataConfig("json"); if (config != null) { AvailableFormatConfigs.Add(config); } config = GetMetadataConfig("jsv"); if (config != null) { AvailableFormatConfigs.Add(config); } foreach (var format in contentTypeFormats) { metadataConfigMap[format] = metadataConfig.Custom.Create(format); config = GetMetadataConfig(format); if (config != null) { AvailableFormatConfigs.Add(config); } } config = GetMetadataConfig("soap11"); if (config != null) { AvailableFormatConfigs.Add(config); } }
public XsdMetadata(ServiceMetadata metadata, bool flash = false) { Metadata = metadata; Flash = flash; }
internal static void LogError(string title, IHttpRequest httpRequest, ResponseStatusType responseStatus, string errorCode, LogLevel logLevel) { if (httpRequest == null) { return; } ServiceMetadata metadata = EndpointHost.Config.MetadataMap[httpRequest.ServicePath]; Dictionary <string, string> additionalExceptionInfo = new Dictionary <string, string>() { { "Version", ServiceUtils.SOA2VersionCatName }, { "Operation", metadata.FullServiceName + "." + httpRequest.OperationName } }; string clientAppId = httpRequest.GetClientAppId(); if (!string.IsNullOrWhiteSpace(clientAppId)) { additionalExceptionInfo.Add("ClientAppId", clientAppId); } if (!string.IsNullOrWhiteSpace(errorCode)) { additionalExceptionInfo.Add("ErrorCode", errorCode); } if (metadata.LogErrorWithRequestInfo) { try { try { var requestInfo = RequestInfoHandler.GetRequestInfo(httpRequest); additionalExceptionInfo["RequestInfo"] = TypeSerializer.SerializeToString(requestInfo); } catch { Dictionary <string, string> requestInfo = new Dictionary <string, string>() { { "Url", httpRequest.RawUrl }, { "PathInfo", httpRequest.PathInfo }, { "QueryString", TypeSerializer.SerializeToString(httpRequest.QueryString) }, { "Headers", TypeSerializer.SerializeToString(httpRequest.Headers) }, { "FormData", TypeSerializer.SerializeToString(httpRequest.FormData) } }; additionalExceptionInfo["RequestInfo"] = TypeSerializer.SerializeToString(requestInfo); } } catch { } if (httpRequest.RequestObject != null && !(httpRequest.RequestObject is RequestInfoResponse)) { additionalExceptionInfo["RequestObject"] = TypeSerializer.SerializeToString(httpRequest.RequestObject); } } string message = string.Empty; if (responseStatus != null) { additionalExceptionInfo["ResponseStatus"] = TypeSerializer.SerializeToString(responseStatus); if (responseStatus.Errors != null && responseStatus.Errors.Count > 0 && responseStatus.Errors[0] != null) { message = string.Format("ErrorCode: {0}, Message: {1}", responseStatus.Errors[0].ErrorCode, responseStatus.Errors[0].Message); } } switch (logLevel) { case LogLevel.DEBUG: Log.Debug(title, message, additionalExceptionInfo); break; case LogLevel.INFO: Log.Info(title, message, additionalExceptionInfo); break; case LogLevel.WARN: Log.Warn(title, message, additionalExceptionInfo); break; case LogLevel.ERROR: Log.Error(title, message, additionalExceptionInfo); break; case LogLevel.FATAL: Log.Fatal(title, message, additionalExceptionInfo); break; } }
internal static void LogError(string title, IHttpRequest httpRequest, Exception ex, string errorCode, LogLevel logLevel) { if (httpRequest == null) { return; } ServiceMetadata metadata = EndpointHost.Config.MetadataMap[httpRequest.ServicePath]; Dictionary <string, string> additionalExceptionInfo = new Dictionary <string, string>() { { "Operation", metadata.FullServiceName + "." + httpRequest.OperationName } }; string clientAppId = httpRequest.GetClientAppId(); if (!string.IsNullOrWhiteSpace(clientAppId)) { additionalExceptionInfo.Add("ClientAppId", clientAppId); } if (!string.IsNullOrWhiteSpace(errorCode)) { additionalExceptionInfo.Add("ErrorCode", errorCode); } if (metadata.LogErrorWithRequestInfo) { try { try { var requestInfo = RequestInfoHandler.GetRequestInfo(httpRequest); additionalExceptionInfo["RequestInfo"] = TypeSerializer.SerializeToString(requestInfo); } catch { Dictionary <string, string> requestInfo = new Dictionary <string, string>() { { "Url", httpRequest.RawUrl }, { "PathInfo", httpRequest.PathInfo }, { "QueryString", TypeSerializer.SerializeToString(httpRequest.QueryString) }, { "Headers", TypeSerializer.SerializeToString(httpRequest.Headers) }, { "FormData", TypeSerializer.SerializeToString(httpRequest.FormData) } }; additionalExceptionInfo["RequestInfo"] = TypeSerializer.SerializeToString(requestInfo); } } catch { } if (httpRequest.RequestObject != null && !(httpRequest.RequestObject is RequestInfoResponse)) { additionalExceptionInfo["RequestObject"] = TypeSerializer.SerializeToString(httpRequest.RequestObject); } } switch (logLevel) { case LogLevel.DEBUG: if (ex != null) { Log.Error(title, ex, additionalExceptionInfo); } else { Log.Error(title, string.Empty, additionalExceptionInfo); } break; case LogLevel.INFO: if (ex != null) { Log.Info(title, ex, additionalExceptionInfo); } else { Log.Info(title, string.Empty, additionalExceptionInfo); } break; case LogLevel.WARN: if (ex != null) { Log.Warn(title, ex, additionalExceptionInfo); } else { Log.Warn(title, string.Empty, additionalExceptionInfo); } break; case LogLevel.ERROR: if (ex != null) { Log.Error(title, ex, additionalExceptionInfo); } else { Log.Error(title, string.Empty, additionalExceptionInfo); } break; case LogLevel.FATAL: if (ex != null) { Log.Fatal(title, ex, additionalExceptionInfo); } else { Log.Fatal(title, string.Empty, additionalExceptionInfo); } break; } }