public static async Task <string> CreateMethods(List <MethodDeclarationSyntax> wcfClientMethods, IEnumerable <MethodDeclarationSyntax> serviceGenMethods, List <MethodDeclarationSyntax> wcfServiceMethods) { var methods = await wcfClientMethods .Select(async wcfClientMethod => { var returnType = wcfClientMethod.ReturnType.ToFullString(); var methodName = wcfClientMethod.Identifier.ValueText; var parameters = wcfClientMethod.ParameterList.ToFullString(); var serviceGenMethod = FindServiceGenMethod(wcfClientMethod, wcfClientMethods, serviceGenMethods); var isActiveWcfMethod = serviceGenMethod != null; var complexTypeClass = await ClientCodeMultipleComplexTypesGenerator.CreateComplexTypeClass(wcfClientMethod, methodName, isActiveWcfMethod); var block = CreateMethodBlock(wcfClientMethod, serviceGenMethod, wcfServiceMethods, isActiveWcfMethod); block = ClientCodeOutKeywordGenerator.TransformMethodBlockWithOutKeywords(block, wcfClientMethod, isActiveWcfMethod); var method = $@" {complexTypeClass} public {returnType}{methodName}{parameters} {block} "; return(method); }) .Aggregate(async(method1, method2) => $"{await method1}\r\n{await method2}"); return(methods); }
private static (string startRequest, string endRequest) CreateHttpPostRequest(MethodDeclarationSyntax wcfClientMethod, MethodDeclarationSyntax serviceGenMethod, IEnumerable <MethodDeclarationSyntax> wcfServiceMethods) { var serviceParameters = serviceGenMethod.ParameterList.Parameters; var serviceComplexTypeParameter = ComplexTypesGenerator.FindComplexTypes(serviceParameters).SingleOrDefault(); var serviceComplexTypeParameterName = serviceComplexTypeParameter?.Identifier.ValueText; // create anon class instance if method has two or more (i.e. "multiple") complex types parameters var multipleComplexTypes = ClientCodeMultipleComplexTypesGenerator.CreateMultipleComplexTypesClassInstance(wcfClientMethod, serviceComplexTypeParameterName, wcfServiceMethods); // should only be one complex type parmeter for any service method // hence serialize it to json for http post var jsonRequest = CreateJsonRequest(serviceComplexTypeParameter, serviceComplexTypeParameterName); // create http post request var startHttpPostRequest = $@" {multipleComplexTypes} var json = {jsonRequest}; var content = new StringContent(json, Encoding.UTF8, ""application/json""); var response = _httpClient.PostAsync(requestUri, content).Result; "; var httpPostRequest = (startRequest : startHttpPostRequest, endRequest : "response.Content.ReadAsStringAsync().Result"); return(httpPostRequest); }