private List <ServiceDefinition> GetServices(ServiceDescription serviceDescription, WsdlHandlerConfiguration wsdlHandlerConfiguration) { var services = new List <ServiceDefinition>(); foreach (PortType portType in serviceDescription.PortTypes) { foreach (Operation operation in portType.Operations) { ServiceDefinition serviceDefinition = new ServiceDefinition(wsdlHandlerConfiguration) { ServiceName = operation.Name }; foreach (OperationMessage message in operation.Messages) { var parameter = serviceDescription.Messages.Cast <Message>().FirstOrDefault(x => x.Name == message.Message.Name); OperationInput operationInput = message as OperationInput; if (operationInput != null) { serviceDefinition.InputType = parameter != null && parameter.Parts.Count > 0 ? parameter.Parts[0].Type.Name : String.Empty; serviceDefinition.InputParameterName = parameter != null && parameter.Parts.Count > 0 ? parameter.Parts[0].Name : String.Empty; } OperationOutput operationOutput = message as OperationOutput; if (operationOutput != null) { serviceDefinition.OutputType = parameter != null && parameter.Parts.Count > 0 ? parameter.Parts[0].Type.Name : String.Empty; serviceDefinition.OutputParameterName = parameter != null && parameter.Parts.Count > 0 ? parameter.Parts[0].Name : String.Empty; } } serviceDefinition.Input = GetTypeDefinition(serviceDefinition.InputType); serviceDefinition.Output = GetTypeDefinition(serviceDefinition.OutputType); services.Add(serviceDefinition); } } return(services); }
public ServiceDefinition(WsdlHandlerConfiguration wsdlHandlerConfiguration) { _wsdlHandlerConfiguration = wsdlHandlerConfiguration; }
public NpsSdk(WsdlHandlerConfiguration wsdlHandlerConfiguration) { try { _wsdlHandlerConfiguration = wsdlHandlerConfiguration; if (wsdlHandlerConfiguration.LogLevel == LogLevel.Debug && wsdlHandlerConfiguration.NpsEnvironment == NpsEnvironment.Production) { throw new ArgumentException("LogLevel can't be set to Debug on Production environment", "wsdlHandlerConfiguration"); } if (wsdlHandlerConfiguration.IgnoreSslValidation && wsdlHandlerConfiguration.NpsEnvironment == NpsEnvironment.Production) { throw new ArgumentException("IgnoreSslValidation can't be set to true on Production environment", "wsdlHandlerConfiguration"); } if (_wsdlHandlerConfiguration.IgnoreSslValidation) { ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); }; } if (_wsdlHandlerConfiguration.NpsEnvironment == NpsEnvironment.CustomEnv) { if (_wsdlHandlerConfiguration.customEnvUrls == null) { throw new ArgumentException("customEnvUrls cannot be empty using CUSTOM_ENV environment", "wsdlHandlerConfiguration"); } } if (wsdlHandlerConfiguration.customEnvUrls != null) { if (wsdlHandlerConfiguration.NpsEnvironment != NpsEnvironment.CustomEnv) { throw new ArgumentException("Only CUSTOM_ENV environment is available with customEnvUrls", "wsdlHandlerConfiguration"); } if (_wsdlHandlerConfiguration.customEnvUrls.Length == 0) { throw new Exception("customEnvUrls cannot by empty"); } if (_wsdlHandlerConfiguration.customEnvUrls.Length > MaxCustomUrls) { throw new Exception(String.Format("customEnvUrls must contain at most {0} urls", MaxCustomUrls)); } foreach (string url in _wsdlHandlerConfiguration.customEnvUrls) { if (!(Uri.IsWellFormedUriString(url, UriKind.Absolute))) { throw new Exception(String.Format("Invalid URL - {0}", url)); } } } var assembly = Assembly.GetExecutingAssembly(); Stream stream = assembly.GetManifestResourceStream(typeof(NpsSdk), String.Format("{0}.wsdl", (_wsdlHandlerConfiguration.NpsEnvironment == NpsEnvironment.CustomEnv ? NpsEnvironment.Production.ToString().ToLower() : _wsdlHandlerConfiguration.NpsEnvironment.ToString().ToLower()))); if (stream == null) { throw new FileNotFoundException("Missing local WSDL"); } var serviceDescription = ServiceDescription.Read(stream); _types = GetTypes(serviceDescription); _services = GetServices(serviceDescription, wsdlHandlerConfiguration); } catch (Exception ex) { _wsdlHandlerConfiguration.Logger.Log(LogLevel.Debug, ex.Message); throw; } }