public bool IsWCFCodeService(AnalyzerResult analyzerResult) { // For Code Based, look for Service Interface var project = analyzerResult.ProjectResult; Tuple <string, string> serviceInterfaceAndClass = WCFBindingAndTransportUtil.GetServiceInterfaceAndClass(project); return(serviceInterfaceAndClass != null); }
/// <summary> /// Given existing Startup.cs template file, generate new Startup.cs based on configuration. /// </summary> /// <param name="startupFilePath">Path to existing Startup.cs template</param> /// <returns>New Startup.cs contents</returns> public string ReplaceStartupFile(string startupFilePath) { var startupFileContents = File.ReadAllText(startupFilePath); if (_projectType == ProjectType.WCFConfigBasedService) { string configPath = Path.Combine(_projectPath, Constants.PortedConfigFileName); if (HasBehavioursTag()) { startupFileContents = HandleBehaviorsTag(startupFilePath); } return(startupFileContents.Replace(Constants.XMLPathPlaceholder, "@\"" + configPath + "\"")); } else { string addService = Constants.AddServiceFormat; string endpointConfigTemplate = Constants.AddServiceEndpointFormat; string endpointConfigs = ""; ProjectWorkspace project = _analyzerResult.ProjectResult; Dictionary <string, BindingConfiguration> bindingTransportMap = GetBindingsTransportMap(project); Tuple <string, string> serviceInterfaceAndClass = WCFBindingAndTransportUtil.GetServiceInterfaceAndClass(project); var serviceInterfaceName = serviceInterfaceAndClass.Item1 ?? Constants.DefaultServiceInterface; var serviceClassName = serviceInterfaceAndClass.Item2 ?? Constants.DefaultServiceClass; endpointConfigs += String.Format(addService, serviceClassName); foreach (KeyValuePair <string, BindingConfiguration> keyValuePair in bindingTransportMap) { var binding = keyValuePair.Key; var mode = keyValuePair.Value.Mode; var endpointAddress = keyValuePair.Value.EndpointAddress ?? String.Join("", "\"", "/", binding.ToLower(), "\""); if (mode.ToLower() == Constants.TransportMode.ToLower()) { mode = Constants.TransportMode; } else if (mode.ToLower() == Constants.TransportMessageCredentialsMode.ToLower()) { mode = Constants.TransportMessageCredentialsMode; } if (binding == Constants.HttpProtocol) { endpointConfigs += String.Format(endpointConfigTemplate, serviceClassName, serviceInterfaceName, mode == Constants.NoneMode ? "new BasicHttpBinding()" : "new BasicHttpBinding(BasicHttpSecurityMode." + mode + ")", endpointAddress); } else if (binding == Constants.NettcpProtocol) { endpointConfigs += String.Format(endpointConfigTemplate, serviceClassName, serviceInterfaceName, mode == Constants.NoneMode ? "new NetTcpBinding()" : "new NetTcpBinding(SecurityMode." + mode + ")", endpointAddress); } else if (binding == Constants.WSHttpProtocol) { endpointConfigs += String.Format(endpointConfigTemplate, serviceClassName, serviceInterfaceName, mode == Constants.NoneMode ? "new WSHttpBinding()" : "new WSHttpBinding(SecurityMode." + mode + ")", endpointAddress); } else if (binding == Constants.HttpsProtocol) { endpointConfigs += String.Format(endpointConfigTemplate, serviceClassName, serviceInterfaceName, "new BasicHttpBinding(BasicHttpSecurityMode.Transport)", endpointAddress); } else if (binding == Constants.NethttpProtocol) { endpointConfigs += String.Format(endpointConfigTemplate, serviceClassName, serviceInterfaceName, mode == Constants.NoneMode ? "new NetHttpBinding()" : "new NetHttpBinding(BasicHttpSecurityMode." + mode + ")", endpointAddress); } } return(startupFileContents.Replace(Constants.EndpointPlaceholder, endpointConfigs)); } }