diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3a2238d --- /dev/null +++ b/.gitignore @@ -0,0 +1,245 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +[Xx]64/ +[Xx]86/ +[Bb]uild/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml + +# TODO: Un-comment the next line if you do not want to checkin +# your web deploy settings because they may include unencrypted +# passwords +#*.pubxml +*.publishproj + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Microsoft Azure ApplicationInsights config file +ApplicationInsights.config + +# Windows Store app package directory +AppPackages/ +BundleArtifacts/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# LightSwitch generated files +GeneratedArtifacts/ +ModelManifest.xml + +# Paket dependency manager +.paket/paket.exe + +# FAKE - F# Make +.fake/ \ No newline at end of file diff --git a/src/Default.sln b/src/Default.sln new file mode 100644 index 0000000..c6ec490 --- /dev/null +++ b/src/Default.sln @@ -0,0 +1,34 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Default", "Default\Default.csproj", "{18D29CED-5D67-4445-8CE8-30BDAF23143D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DemoForOldXmlConfig", "DemoForOldXmlConfig\DemoForOldXmlConfig.csproj", "{C3301AAC-4112-44B8-BD5E-AF27A87865CE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server", "Server\Server.csproj", "{113C2E62-F473-4B44-AC7C-002096B17E49}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {18D29CED-5D67-4445-8CE8-30BDAF23143D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {18D29CED-5D67-4445-8CE8-30BDAF23143D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {18D29CED-5D67-4445-8CE8-30BDAF23143D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {18D29CED-5D67-4445-8CE8-30BDAF23143D}.Release|Any CPU.Build.0 = Release|Any CPU + {C3301AAC-4112-44B8-BD5E-AF27A87865CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C3301AAC-4112-44B8-BD5E-AF27A87865CE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C3301AAC-4112-44B8-BD5E-AF27A87865CE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C3301AAC-4112-44B8-BD5E-AF27A87865CE}.Release|Any CPU.Build.0 = Release|Any CPU + {113C2E62-F473-4B44-AC7C-002096B17E49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {113C2E62-F473-4B44-AC7C-002096B17E49}.Debug|Any CPU.Build.0 = Debug|Any CPU + {113C2E62-F473-4B44-AC7C-002096B17E49}.Release|Any CPU.ActiveCfg = Release|Any CPU + {113C2E62-F473-4B44-AC7C-002096B17E49}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/src/Default/App.config b/src/Default/App.config new file mode 100644 index 0000000..03644c1 --- /dev/null +++ b/src/Default/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Default/Default.csproj b/src/Default/Default.csproj new file mode 100644 index 0000000..6f72855 --- /dev/null +++ b/src/Default/Default.csproj @@ -0,0 +1,89 @@ + + + + + Debug + AnyCPU + {18D29CED-5D67-4445-8CE8-30BDAF23143D} + Exe + Properties + Default + Default + v4.5.2 + 512 + true + + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\WebApiProxy.CSharp.1.0.6011.40179\lib\net45\Newtonsoft.Json.dll + True + + + + + ..\packages\WebApiProxy.CSharp.1.0.6011.40179\lib\net45\System.Net.Http.Formatting.dll + True + + + + + + + + + ..\packages\WebApiProxy.CSharp.1.0.6011.40179\lib\net45\WebApiProxy.Core.dll + True + + + ..\packages\WebApiProxy.CSharp.1.0.6011.40179\lib\net45\WebApiProxy.Tasks.dll + True + + + + + + + + + + + + + + + + + + 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 + + + + + \ No newline at end of file diff --git a/src/Default/Program.cs b/src/Default/Program.cs new file mode 100644 index 0000000..4a3d679 --- /dev/null +++ b/src/Default/Program.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using Newtonsoft.Json; +using WebApi.Proxies.One.Clients; +using WebApi.Proxies.One.Models; + +namespace Default +{ + /// + /// this project use new json config file for test multi services generate + /// before run this , build server project in this solution and run the exe file + /// + class Program + { + static void Main(string[] args) + { + + var baseAddr = "http://localhost:8888"; + Console.WriteLine("hello------from origin http client"); + + var client = new HttpClient { BaseAddress = new Uri(baseAddr) }; + + var res = client.GetAsync("api/test/GetFromSimpleArg?id=world").Result.Content.ReadAsStringAsync().Result; + Console.WriteLine(res); + Console.WriteLine("\n\n"); + + + var proxy = new ProxyClient(); + Console.WriteLine("hello------from web api proxy"); + + var v1 = proxy.GetFromSimpleArg("just say this is my name"); + Console.WriteLine("1---" + JsonConvert.SerializeObject(v1)); + + v1 = proxy.GetFromSimpleArgAsync("just say this is my name").Result; + Console.WriteLine("1-async---" + JsonConvert.SerializeObject(v1)); + + var complexModel = new ComplexModel() { Age = 18, Name = "super star" }; + var v2 = proxy.GetFromComplexArg(complexModel); + Console.WriteLine("2---" + JsonConvert.SerializeObject(v2)); + + var v3 = proxy.GetFromMixedArg(2016, complexModel); + Console.WriteLine("3---" + JsonConvert.SerializeObject(v3)); + + + var nest = new NestedModel() + { + Id = 999999, + ComplexModel = complexModel + }; + var v4 = proxy.PostFromMixedArg("this is my str", nest, complexModel); + Console.WriteLine("4---" + JsonConvert.SerializeObject(v4)); + + var v5 = proxy.PostFromMixedArg2("this is my str", complexModel, nest); + Console.WriteLine("5---" + JsonConvert.SerializeObject(v5)); + + + Console.WriteLine("---------------done!"); + Console.ReadLine(); + + } + } + + + public class ProxyClient : TestClient + { + protected override List> GenerateGetFromComplexArgKeyValueList(ComplexModel dataArg) + { + return new List>() + { + new KeyValuePair("Name", dataArg.Name), + new KeyValuePair("Age", dataArg.Age), + }; + } + + protected override List> GenerateGetFromMixedArgKeyValueList(int id, ComplexModel dataArg) + { + return new List>() + { + new KeyValuePair("Name", dataArg.Name), + new KeyValuePair("Age", dataArg.Age), + }; + } + + protected override List> GeneratePostFromMixedArg2KeyValueList(string simpleStr, ComplexModel uriComplexArg, NestedModel bodyNestedArg) + { + return new List>() + { + new KeyValuePair("Name", uriComplexArg.Name), + new KeyValuePair("Age", uriComplexArg.Age), + }; + } + } +} \ No newline at end of file diff --git a/src/Default/Properties/AssemblyInfo.cs b/src/Default/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..8489304 --- /dev/null +++ b/src/Default/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Default")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Default")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +//将 ComVisible 设置为 false 将使此程序集中的类型 +//对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("18d29ced-5d67-4445-8ce8-30bdaf23143d")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Default/WebApiProxy/DemoOne.cs b/src/Default/WebApiProxy/DemoOne.cs new file mode 100644 index 0000000..ce12340 --- /dev/null +++ b/src/Default/WebApiProxy/DemoOne.cs @@ -0,0 +1,757 @@ +//------------------------------------------------------------------------------ +// +// This file is auto-generated by WebApiProxy +// Project site: http://github.com/faniereynders/webapiproxy +// +// Any changes to this file will be overwritten +// +//------------------------------------------------------------------------------ + +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Threading.Tasks; +using System.Net.Http.Formatting; +using System.Linq; +using System.Net; +using System.Web; +using Newtonsoft.Json; +using WebApiProxy.Tasks.Models; +using WebApi.Proxies.One.Models; + + +#region Proxies +namespace WebApi.Proxies.One +{ + /// + /// Client configuration. + /// + public static partial class Configuration + { + /// + /// Web Api Base Address. + /// + public static string DemoOneBaseAddress = "http://localhost:8888/"; + } +} +#endregion + +#region Models +namespace WebApi.Proxies.One.Models +{ + + + /// + /// + /// + public partial class ComplexModel + { + #region Constants + #endregion + + #region Properties + /// + /// + /// + public virtual String Name { get; set; } + /// + /// + /// + public virtual Int32 Age { get; set; } + #endregion + } + + /// + /// + /// + public partial class GenericBase + { + #region Constants + #endregion + + #region Properties + /// + /// + /// + public virtual T Id { get; set; } + #endregion + } + + /// + /// + /// + public partial class NestedModel + { + #region Constants + #endregion + + #region Properties + /// + /// + /// + public virtual ComplexModel ComplexModel { get; set; } + /// + /// + /// + public virtual Int32 Id { get; set; } + #endregion + } + + /// + /// + /// + public partial class TotalResult + { + #region Constants + #endregion + + #region Properties + /// + /// + /// + public virtual String SimpleStr { get; set; } + /// + /// + /// + public virtual ComplexModel ComplexModel { get; set; } + /// + /// + /// + public virtual NestedModel NestedModel { get; set; } + #endregion + } + + +} +#endregion + +#region Interfaces +namespace WebApi.Proxies.One.Interfaces +{ + public interface IClientBase : IDisposable + { + HttpClient HttpClient { get; } + } + + + public partial interface ITestClient : IClientBase + { + + /// + /// + /// + /// + + Task> GetFromSimpleArgAsync(String id); + + /// + /// + /// + /// + /// + GenericBase GetFromSimpleArg(String id); + + /// + /// + /// + /// + + Task GetFromComplexArgAsync(ComplexModel dataArg); + + /// + /// + /// + /// + /// + ComplexModel GetFromComplexArg(ComplexModel dataArg); + + /// + /// + /// + /// + /// + + Task GetFromMixedArgAsync(Int32 id,ComplexModel dataArg); + + /// + /// + /// + /// + /// + /// + NestedModel GetFromMixedArg(Int32 id,ComplexModel dataArg); + + /// + /// + /// + /// + /// + /// + + Task PostFromMixedArgAsync(String simpleStr,NestedModel uriNestedArg,ComplexModel bodyComplexArg); + + /// + /// + /// + /// + /// + /// + /// + TotalResult PostFromMixedArg(String simpleStr,NestedModel uriNestedArg,ComplexModel bodyComplexArg); + + /// + /// + /// + /// + /// + /// + + Task PostFromMixedArg2Async(String simpleStr,ComplexModel uriComplexArg,NestedModel bodyNestedArg); + + /// + /// + /// + /// + /// + /// + /// + TotalResult PostFromMixedArg2(String simpleStr,ComplexModel uriComplexArg,NestedModel bodyNestedArg); + + } + +} +#endregion + +#region Clients +namespace WebApi.Proxies.One.Clients +{ + /// + /// Client base class. + /// + public abstract partial class ClientBase : IDisposable + { + /// + /// Gests the HttpClient. + /// + public HttpClient HttpClient { get; protected set; } + + /// + /// Initializes a new instance of the class. + /// + protected ClientBase() + { + HttpClient = new HttpClient() + { + BaseAddress = new Uri(Configuration.DemoOneBaseAddress) + }; + + SerializationSettings = new JsonSerializerSettings + { + NullValueHandling = NullValueHandling.Ignore, + ReferenceLoopHandling = ReferenceLoopHandling.Serialize, + }; + } + + public JsonSerializerSettings SerializationSettings; + + + /// + /// Ensures that response has a valid (200 - OK) status code + /// + public virtual void EnsureSuccess(HttpResponseMessage response) + { + if (response.IsSuccessStatusCode) + return; + + throw new WebApiProxyResponseException(response); + } + + protected virtual string GenerateQueryStrFromKvList(List> kvList) + { + var urlTpl = string.Join("&", + kvList.Select(item => + { + var queryKey = Uri.EscapeDataString(item.Key); + var queryValue = string.Empty; + + if (item.Value != null) + { + if (item.Value is string) + { + queryValue = Uri.EscapeDataString((string)item.Value); + } + else + { + var queryValueJson = JsonConvert.SerializeObject(item.Value,SerializationSettings).Trim('"'); + queryValue = Uri.EscapeDataString(queryValueJson); + } + } + return queryKey + "=" + queryValue; + })); + return urlTpl; + } + + + /// + /// Initializes a new instance of the class. + /// + /// The handler. + /// if set to true [dispose handler]. + protected ClientBase(HttpMessageHandler handler, bool disposeHandler = true) + { + HttpClient = new HttpClient(handler, disposeHandler) + { + BaseAddress = new Uri(Configuration.DemoOneBaseAddress) + }; + } + + + /// + /// Encode the input parameter as a string + /// + protected string EncodeParam(T value) + { + return System.Net.WebUtility.UrlEncode(value.ToString()); + } + + /// + /// Encode the input parameter as a string + /// + protected string EncodeParam(DateTime value) + { + return System.Net.WebUtility.UrlEncode(value.ToString("s")); + } + + /// + /// Encode the input parameter as a string + /// + protected string EncodeParam(DateTimeOffset value) + { + return System.Net.WebUtility.UrlEncode(value.ToString("s")); + } + + /// + /// Releases the unmanaged resources and disposes of the managed resources. + /// + protected virtual void Dispose(bool disposing) + { + if (disposing && HttpClient != null) + { + HttpClient.Dispose(); + HttpClient = null; + } + } + + /// + /// Releases the unmanaged resources and disposes of the managed resources. + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Destructor + /// + ~ClientBase() + { + Dispose(false); + } + } + + /// + /// Helper class to access all clients at once + /// + public partial class WebApiClients + { + public TestClient Test { get; private set; } + + protected IEnumerable Clients + { + get + { + yield return Test; + } + } + + public WebApiClients(Uri baseAddress = null) + { + if (baseAddress != null) + Configuration.DemoOneBaseAddress = baseAddress.AbsoluteUri; + + Test = new TestClient(); + } + + public void SetAuthentication(AuthenticationHeaderValue auth) + { + foreach (var client in Clients) + client.HttpClient.DefaultRequestHeaders.Authorization = auth; + } + + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + foreach (var client in Clients) + client.Dispose(); + } + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + ~WebApiClients() + { + Dispose(false); + } + } + + /// + /// + /// + public partial class TestClient : ClientBase, Interfaces.ITestClient + { + + /// + /// + /// + public TestClient() : base() + { + } + + /// + /// + /// + public TestClient(HttpMessageHandler handler, bool disposeHandler = true) : base(handler, disposeHandler) + { + } + + #region Methods + + + + + /// + /// + /// + /// + /// + public virtual async Task> GetFromSimpleArgAsync(String id) + { + var requestUrl = "api/test/GetFromSimpleArg"; + + + var queryHasParamUrl = "id="+Uri.EscapeDataString(Convert.ToString(id))+""; + + + + var queryNoParamUrl = string.Empty; + + + if (string.IsNullOrEmpty(queryHasParamUrl)) + { + requestUrl = requestUrl + "?" + queryNoParamUrl; + } + else + { + requestUrl = requestUrl + "?" + queryHasParamUrl + "&" + queryNoParamUrl; + } + + + var result = await HttpClient.GetAsync(requestUrl ); + + + EnsureSuccess(result); + + return await result.Content.ReadAsAsync>(); + } + + + + + /// + /// + /// + /// + public virtual GenericBase GetFromSimpleArg(String id) + { + + return GetFromSimpleArgAsync(id).Result; + + } + + + + + /// + /// + /// + /// + /// + public virtual async Task GetFromComplexArgAsync(ComplexModel dataArg) + { + var requestUrl = "api/test/GetFromComplexArg"; + + + var queryHasParamUrl = ""; + + + + var queryNoParamUrl = GenerateGetFromComplexArgQueryString(dataArg); + + + if (string.IsNullOrEmpty(queryHasParamUrl)) + { + requestUrl = requestUrl + "?" + queryNoParamUrl; + } + else + { + requestUrl = requestUrl + "?" + queryHasParamUrl + "&" + queryNoParamUrl; + } + + + var result = await HttpClient.GetAsync(requestUrl ); + + + EnsureSuccess(result); + + return await result.Content.ReadAsAsync(); + } + + + + protected virtual string GenerateGetFromComplexArgQueryString(ComplexModel dataArg) + { + var kvList = GenerateGetFromComplexArgKeyValueList( dataArg ); + var urlTpl = GenerateQueryStrFromKvList(kvList); + + return urlTpl; + } + + protected virtual List> GenerateGetFromComplexArgKeyValueList(ComplexModel dataArg) + { + // Name={Name}&Age={Age} + throw new NotImplementedException(); + } + + + + /// + /// + /// + /// + public virtual ComplexModel GetFromComplexArg(ComplexModel dataArg) + { + + return GetFromComplexArgAsync(dataArg).Result; + + } + + + + + /// + /// + /// + /// + /// + /// + public virtual async Task GetFromMixedArgAsync(Int32 id,ComplexModel dataArg) + { + var requestUrl = "api/test/GetFromMixedArg"; + + + var queryHasParamUrl = "id="+Uri.EscapeDataString(Convert.ToString(id))+""; + + + + var queryNoParamUrl = GenerateGetFromMixedArgQueryString(id, dataArg); + + + if (string.IsNullOrEmpty(queryHasParamUrl)) + { + requestUrl = requestUrl + "?" + queryNoParamUrl; + } + else + { + requestUrl = requestUrl + "?" + queryHasParamUrl + "&" + queryNoParamUrl; + } + + + var result = await HttpClient.GetAsync(requestUrl ); + + + EnsureSuccess(result); + + return await result.Content.ReadAsAsync(); + } + + + + protected virtual string GenerateGetFromMixedArgQueryString(Int32 id,ComplexModel dataArg) + { + var kvList = GenerateGetFromMixedArgKeyValueList( id, dataArg ); + var urlTpl = GenerateQueryStrFromKvList(kvList); + + return urlTpl; + } + + protected virtual List> GenerateGetFromMixedArgKeyValueList(Int32 id,ComplexModel dataArg) + { + // Name={Name}&Age={Age} + throw new NotImplementedException(); + } + + + + /// + /// + /// + /// + /// + public virtual NestedModel GetFromMixedArg(Int32 id,ComplexModel dataArg) + { + + return GetFromMixedArgAsync(id, dataArg).Result; + + } + + + + + /// + /// + /// + /// + /// + /// + /// + public virtual async Task PostFromMixedArgAsync(String simpleStr,NestedModel uriNestedArg,ComplexModel bodyComplexArg) + { + var requestUrl = "api/test/PostFromMixedArg"; + + + var queryHasParamUrl = "simpleStr="+Uri.EscapeDataString(Convert.ToString(simpleStr))+""; + + + + var queryNoParamUrl = string.Empty; + + + if (string.IsNullOrEmpty(queryHasParamUrl)) + { + requestUrl = requestUrl + "?" + queryNoParamUrl; + } + else + { + requestUrl = requestUrl + "?" + queryHasParamUrl + "&" + queryNoParamUrl; + } + + + var result = await HttpClient.PostAsJsonAsync(requestUrl , bodyComplexArg); + + + EnsureSuccess(result); + + return await result.Content.ReadAsAsync(); + } + + + + + /// + /// + /// + /// + /// + /// + public virtual TotalResult PostFromMixedArg(String simpleStr,NestedModel uriNestedArg,ComplexModel bodyComplexArg) + { + + return PostFromMixedArgAsync(simpleStr, uriNestedArg, bodyComplexArg).Result; + + } + + + + + /// + /// + /// + /// + /// + /// + /// + public virtual async Task PostFromMixedArg2Async(String simpleStr,ComplexModel uriComplexArg,NestedModel bodyNestedArg) + { + var requestUrl = "api/test/PostFromMixedArg2"; + + + var queryHasParamUrl = "simpleStr="+Uri.EscapeDataString(Convert.ToString(simpleStr))+""; + + + + var queryNoParamUrl = GeneratePostFromMixedArg2QueryString(simpleStr, uriComplexArg, bodyNestedArg); + + + if (string.IsNullOrEmpty(queryHasParamUrl)) + { + requestUrl = requestUrl + "?" + queryNoParamUrl; + } + else + { + requestUrl = requestUrl + "?" + queryHasParamUrl + "&" + queryNoParamUrl; + } + + + var result = await HttpClient.PostAsJsonAsync(requestUrl , bodyNestedArg); + + + EnsureSuccess(result); + + return await result.Content.ReadAsAsync(); + } + + + + protected virtual string GeneratePostFromMixedArg2QueryString(String simpleStr,ComplexModel uriComplexArg,NestedModel bodyNestedArg) + { + var kvList = GeneratePostFromMixedArg2KeyValueList( simpleStr, uriComplexArg, bodyNestedArg ); + var urlTpl = GenerateQueryStrFromKvList(kvList); + + return urlTpl; + } + + protected virtual List> GeneratePostFromMixedArg2KeyValueList(String simpleStr,ComplexModel uriComplexArg,NestedModel bodyNestedArg) + { + // Name={Name}&Age={Age} + throw new NotImplementedException(); + } + + + + /// + /// + /// + /// + /// + /// + public virtual TotalResult PostFromMixedArg2(String simpleStr,ComplexModel uriComplexArg,NestedModel bodyNestedArg) + { + + return PostFromMixedArg2Async(simpleStr, uriComplexArg, bodyNestedArg).Result; + + } + + #endregion + } + +} + +#endregion + diff --git a/src/Default/WebApiProxy/DemoTwo.cs b/src/Default/WebApiProxy/DemoTwo.cs new file mode 100644 index 0000000..178d45c --- /dev/null +++ b/src/Default/WebApiProxy/DemoTwo.cs @@ -0,0 +1,757 @@ +//------------------------------------------------------------------------------ +// +// This file is auto-generated by WebApiProxy +// Project site: http://github.com/faniereynders/webapiproxy +// +// Any changes to this file will be overwritten +// +//------------------------------------------------------------------------------ + +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Threading.Tasks; +using System.Net.Http.Formatting; +using System.Linq; +using System.Net; +using System.Web; +using Newtonsoft.Json; +using WebApiProxy.Tasks.Models; +using WebApi.Proxies.Two.Models; + + +#region Proxies +namespace WebApi.Proxies.Two +{ + /// + /// Client configuration. + /// + public static partial class Configuration + { + /// + /// Web Api Base Address. + /// + public static string DemoTwoBaseAddress = "http://localhost:8888/"; + } +} +#endregion + +#region Models +namespace WebApi.Proxies.Two.Models +{ + + + /// + /// + /// + public partial class ComplexModel + { + #region Constants + #endregion + + #region Properties + /// + /// + /// + public virtual String Name { get; set; } + /// + /// + /// + public virtual Int32 Age { get; set; } + #endregion + } + + /// + /// + /// + public partial class GenericBase + { + #region Constants + #endregion + + #region Properties + /// + /// + /// + public virtual T Id { get; set; } + #endregion + } + + /// + /// + /// + public partial class NestedModel + { + #region Constants + #endregion + + #region Properties + /// + /// + /// + public virtual ComplexModel ComplexModel { get; set; } + /// + /// + /// + public virtual Int32 Id { get; set; } + #endregion + } + + /// + /// + /// + public partial class TotalResult + { + #region Constants + #endregion + + #region Properties + /// + /// + /// + public virtual String SimpleStr { get; set; } + /// + /// + /// + public virtual ComplexModel ComplexModel { get; set; } + /// + /// + /// + public virtual NestedModel NestedModel { get; set; } + #endregion + } + + +} +#endregion + +#region Interfaces +namespace WebApi.Proxies.Two.Interfaces +{ + public interface IClientBase : IDisposable + { + HttpClient HttpClient { get; } + } + + + public partial interface ITestClient : IClientBase + { + + /// + /// + /// + /// + + Task> GetFromSimpleArgAsync(String id); + + /// + /// + /// + /// + /// + GenericBase GetFromSimpleArg(String id); + + /// + /// + /// + /// + + Task GetFromComplexArgAsync(ComplexModel dataArg); + + /// + /// + /// + /// + /// + ComplexModel GetFromComplexArg(ComplexModel dataArg); + + /// + /// + /// + /// + /// + + Task GetFromMixedArgAsync(Int32 id,ComplexModel dataArg); + + /// + /// + /// + /// + /// + /// + NestedModel GetFromMixedArg(Int32 id,ComplexModel dataArg); + + /// + /// + /// + /// + /// + /// + + Task PostFromMixedArgAsync(String simpleStr,NestedModel uriNestedArg,ComplexModel bodyComplexArg); + + /// + /// + /// + /// + /// + /// + /// + TotalResult PostFromMixedArg(String simpleStr,NestedModel uriNestedArg,ComplexModel bodyComplexArg); + + /// + /// + /// + /// + /// + /// + + Task PostFromMixedArg2Async(String simpleStr,ComplexModel uriComplexArg,NestedModel bodyNestedArg); + + /// + /// + /// + /// + /// + /// + /// + TotalResult PostFromMixedArg2(String simpleStr,ComplexModel uriComplexArg,NestedModel bodyNestedArg); + + } + +} +#endregion + +#region Clients +namespace WebApi.Proxies.Two.Clients +{ + /// + /// Client base class. + /// + public abstract partial class ClientBase : IDisposable + { + /// + /// Gests the HttpClient. + /// + public HttpClient HttpClient { get; protected set; } + + /// + /// Initializes a new instance of the class. + /// + protected ClientBase() + { + HttpClient = new HttpClient() + { + BaseAddress = new Uri(Configuration.DemoTwoBaseAddress) + }; + + SerializationSettings = new JsonSerializerSettings + { + NullValueHandling = NullValueHandling.Ignore, + ReferenceLoopHandling = ReferenceLoopHandling.Serialize, + }; + } + + public JsonSerializerSettings SerializationSettings; + + + /// + /// Ensures that response has a valid (200 - OK) status code + /// + public virtual void EnsureSuccess(HttpResponseMessage response) + { + if (response.IsSuccessStatusCode) + return; + + throw new WebApiProxyResponseException(response); + } + + protected virtual string GenerateQueryStrFromKvList(List> kvList) + { + var urlTpl = string.Join("&", + kvList.Select(item => + { + var queryKey = Uri.EscapeDataString(item.Key); + var queryValue = string.Empty; + + if (item.Value != null) + { + if (item.Value is string) + { + queryValue = Uri.EscapeDataString((string)item.Value); + } + else + { + var queryValueJson = JsonConvert.SerializeObject(item.Value,SerializationSettings).Trim('"'); + queryValue = Uri.EscapeDataString(queryValueJson); + } + } + return queryKey + "=" + queryValue; + })); + return urlTpl; + } + + + /// + /// Initializes a new instance of the class. + /// + /// The handler. + /// if set to true [dispose handler]. + protected ClientBase(HttpMessageHandler handler, bool disposeHandler = true) + { + HttpClient = new HttpClient(handler, disposeHandler) + { + BaseAddress = new Uri(Configuration.DemoTwoBaseAddress) + }; + } + + + /// + /// Encode the input parameter as a string + /// + protected string EncodeParam(T value) + { + return System.Net.WebUtility.UrlEncode(value.ToString()); + } + + /// + /// Encode the input parameter as a string + /// + protected string EncodeParam(DateTime value) + { + return System.Net.WebUtility.UrlEncode(value.ToString("s")); + } + + /// + /// Encode the input parameter as a string + /// + protected string EncodeParam(DateTimeOffset value) + { + return System.Net.WebUtility.UrlEncode(value.ToString("s")); + } + + /// + /// Releases the unmanaged resources and disposes of the managed resources. + /// + protected virtual void Dispose(bool disposing) + { + if (disposing && HttpClient != null) + { + HttpClient.Dispose(); + HttpClient = null; + } + } + + /// + /// Releases the unmanaged resources and disposes of the managed resources. + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Destructor + /// + ~ClientBase() + { + Dispose(false); + } + } + + /// + /// Helper class to access all clients at once + /// + public partial class WebApiClients + { + public TestClient Test { get; private set; } + + protected IEnumerable Clients + { + get + { + yield return Test; + } + } + + public WebApiClients(Uri baseAddress = null) + { + if (baseAddress != null) + Configuration.DemoTwoBaseAddress = baseAddress.AbsoluteUri; + + Test = new TestClient(); + } + + public void SetAuthentication(AuthenticationHeaderValue auth) + { + foreach (var client in Clients) + client.HttpClient.DefaultRequestHeaders.Authorization = auth; + } + + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + foreach (var client in Clients) + client.Dispose(); + } + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + ~WebApiClients() + { + Dispose(false); + } + } + + /// + /// + /// + public partial class TestClient : ClientBase, Interfaces.ITestClient + { + + /// + /// + /// + public TestClient() : base() + { + } + + /// + /// + /// + public TestClient(HttpMessageHandler handler, bool disposeHandler = true) : base(handler, disposeHandler) + { + } + + #region Methods + + + + + /// + /// + /// + /// + /// + public virtual async Task> GetFromSimpleArgAsync(String id) + { + var requestUrl = "api/test/GetFromSimpleArg"; + + + var queryHasParamUrl = "id="+Uri.EscapeDataString(Convert.ToString(id))+""; + + + + var queryNoParamUrl = string.Empty; + + + if (string.IsNullOrEmpty(queryHasParamUrl)) + { + requestUrl = requestUrl + "?" + queryNoParamUrl; + } + else + { + requestUrl = requestUrl + "?" + queryHasParamUrl + "&" + queryNoParamUrl; + } + + + var result = await HttpClient.GetAsync(requestUrl ); + + + EnsureSuccess(result); + + return await result.Content.ReadAsAsync>(); + } + + + + + /// + /// + /// + /// + public virtual GenericBase GetFromSimpleArg(String id) + { + + return GetFromSimpleArgAsync(id).Result; + + } + + + + + /// + /// + /// + /// + /// + public virtual async Task GetFromComplexArgAsync(ComplexModel dataArg) + { + var requestUrl = "api/test/GetFromComplexArg"; + + + var queryHasParamUrl = ""; + + + + var queryNoParamUrl = GenerateGetFromComplexArgQueryString(dataArg); + + + if (string.IsNullOrEmpty(queryHasParamUrl)) + { + requestUrl = requestUrl + "?" + queryNoParamUrl; + } + else + { + requestUrl = requestUrl + "?" + queryHasParamUrl + "&" + queryNoParamUrl; + } + + + var result = await HttpClient.GetAsync(requestUrl ); + + + EnsureSuccess(result); + + return await result.Content.ReadAsAsync(); + } + + + + protected virtual string GenerateGetFromComplexArgQueryString(ComplexModel dataArg) + { + var kvList = GenerateGetFromComplexArgKeyValueList( dataArg ); + var urlTpl = GenerateQueryStrFromKvList(kvList); + + return urlTpl; + } + + protected virtual List> GenerateGetFromComplexArgKeyValueList(ComplexModel dataArg) + { + // Name={Name}&Age={Age} + throw new NotImplementedException(); + } + + + + /// + /// + /// + /// + public virtual ComplexModel GetFromComplexArg(ComplexModel dataArg) + { + + return GetFromComplexArgAsync(dataArg).Result; + + } + + + + + /// + /// + /// + /// + /// + /// + public virtual async Task GetFromMixedArgAsync(Int32 id,ComplexModel dataArg) + { + var requestUrl = "api/test/GetFromMixedArg"; + + + var queryHasParamUrl = "id="+Uri.EscapeDataString(Convert.ToString(id))+""; + + + + var queryNoParamUrl = GenerateGetFromMixedArgQueryString(id, dataArg); + + + if (string.IsNullOrEmpty(queryHasParamUrl)) + { + requestUrl = requestUrl + "?" + queryNoParamUrl; + } + else + { + requestUrl = requestUrl + "?" + queryHasParamUrl + "&" + queryNoParamUrl; + } + + + var result = await HttpClient.GetAsync(requestUrl ); + + + EnsureSuccess(result); + + return await result.Content.ReadAsAsync(); + } + + + + protected virtual string GenerateGetFromMixedArgQueryString(Int32 id,ComplexModel dataArg) + { + var kvList = GenerateGetFromMixedArgKeyValueList( id, dataArg ); + var urlTpl = GenerateQueryStrFromKvList(kvList); + + return urlTpl; + } + + protected virtual List> GenerateGetFromMixedArgKeyValueList(Int32 id,ComplexModel dataArg) + { + // Name={Name}&Age={Age} + throw new NotImplementedException(); + } + + + + /// + /// + /// + /// + /// + public virtual NestedModel GetFromMixedArg(Int32 id,ComplexModel dataArg) + { + + return GetFromMixedArgAsync(id, dataArg).Result; + + } + + + + + /// + /// + /// + /// + /// + /// + /// + public virtual async Task PostFromMixedArgAsync(String simpleStr,NestedModel uriNestedArg,ComplexModel bodyComplexArg) + { + var requestUrl = "api/test/PostFromMixedArg"; + + + var queryHasParamUrl = "simpleStr="+Uri.EscapeDataString(Convert.ToString(simpleStr))+""; + + + + var queryNoParamUrl = string.Empty; + + + if (string.IsNullOrEmpty(queryHasParamUrl)) + { + requestUrl = requestUrl + "?" + queryNoParamUrl; + } + else + { + requestUrl = requestUrl + "?" + queryHasParamUrl + "&" + queryNoParamUrl; + } + + + var result = await HttpClient.PostAsJsonAsync(requestUrl , bodyComplexArg); + + + EnsureSuccess(result); + + return await result.Content.ReadAsAsync(); + } + + + + + /// + /// + /// + /// + /// + /// + public virtual TotalResult PostFromMixedArg(String simpleStr,NestedModel uriNestedArg,ComplexModel bodyComplexArg) + { + + return PostFromMixedArgAsync(simpleStr, uriNestedArg, bodyComplexArg).Result; + + } + + + + + /// + /// + /// + /// + /// + /// + /// + public virtual async Task PostFromMixedArg2Async(String simpleStr,ComplexModel uriComplexArg,NestedModel bodyNestedArg) + { + var requestUrl = "api/test/PostFromMixedArg2"; + + + var queryHasParamUrl = "simpleStr="+Uri.EscapeDataString(Convert.ToString(simpleStr))+""; + + + + var queryNoParamUrl = GeneratePostFromMixedArg2QueryString(simpleStr, uriComplexArg, bodyNestedArg); + + + if (string.IsNullOrEmpty(queryHasParamUrl)) + { + requestUrl = requestUrl + "?" + queryNoParamUrl; + } + else + { + requestUrl = requestUrl + "?" + queryHasParamUrl + "&" + queryNoParamUrl; + } + + + var result = await HttpClient.PostAsJsonAsync(requestUrl , bodyNestedArg); + + + EnsureSuccess(result); + + return await result.Content.ReadAsAsync(); + } + + + + protected virtual string GeneratePostFromMixedArg2QueryString(String simpleStr,ComplexModel uriComplexArg,NestedModel bodyNestedArg) + { + var kvList = GeneratePostFromMixedArg2KeyValueList( simpleStr, uriComplexArg, bodyNestedArg ); + var urlTpl = GenerateQueryStrFromKvList(kvList); + + return urlTpl; + } + + protected virtual List> GeneratePostFromMixedArg2KeyValueList(String simpleStr,ComplexModel uriComplexArg,NestedModel bodyNestedArg) + { + // Name={Name}&Age={Age} + throw new NotImplementedException(); + } + + + + /// + /// + /// + /// + /// + /// + public virtual TotalResult PostFromMixedArg2(String simpleStr,ComplexModel uriComplexArg,NestedModel bodyNestedArg) + { + + return PostFromMixedArg2Async(simpleStr, uriComplexArg, bodyNestedArg).Result; + + } + + #endregion + } + +} + +#endregion + diff --git a/src/Default/WebApiProxy/WebApiProxy.json b/src/Default/WebApiProxy/WebApiProxy.json new file mode 100644 index 0000000..6cf83b0 --- /dev/null +++ b/src/Default/WebApiProxy/WebApiProxy.json @@ -0,0 +1,18 @@ +{ + "GenerateOnBuild": true, + "GenerateAsyncReturnTypes": true, + "Services": [ + { + "ProxyEndpoint": "http://localhost:8888/api/proxies", + "Namespace": "WebApi.Proxies.One", + "Name": "DemoOne", + "ClientSuffix": "Client" + }, + { + "ProxyEndpoint": "http://localhost:8888/api/proxies", + "Namespace": "WebApi.Proxies.Two", + "Name": "DemoTwo", + "ClientSuffix": "Client" + } + ] +} \ No newline at end of file diff --git a/src/Default/packages.config b/src/Default/packages.config new file mode 100644 index 0000000..94a17da --- /dev/null +++ b/src/Default/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/DemoForOldXmlConfig/App.config b/src/DemoForOldXmlConfig/App.config new file mode 100644 index 0000000..03644c1 --- /dev/null +++ b/src/DemoForOldXmlConfig/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/DemoForOldXmlConfig/DemoForOldXmlConfig.csproj b/src/DemoForOldXmlConfig/DemoForOldXmlConfig.csproj new file mode 100644 index 0000000..3d197ad --- /dev/null +++ b/src/DemoForOldXmlConfig/DemoForOldXmlConfig.csproj @@ -0,0 +1,90 @@ + + + + + Debug + AnyCPU + {C3301AAC-4112-44B8-BD5E-AF27A87865CE} + Exe + Properties + DemoForOldXmlConfig + DemoForOldXmlConfig + v4.5.2 + 512 + true + + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\WebApiProxy.CSharp.1.0.6011.40179\lib\net45\Newtonsoft.Json.dll + True + + + + + ..\packages\WebApiProxy.CSharp.1.0.6011.40179\lib\net45\System.Net.Http.Formatting.dll + True + + + + + + + + + ..\packages\WebApiProxy.CSharp.1.0.6011.40179\lib\net45\WebApiProxy.Core.dll + True + + + ..\packages\WebApiProxy.CSharp.1.0.6011.40179\lib\net45\WebApiProxy.Tasks.dll + True + + + + + + + + + + + + Designer + + + + + + + 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 + + + + + \ No newline at end of file diff --git a/src/DemoForOldXmlConfig/Program.cs b/src/DemoForOldXmlConfig/Program.cs new file mode 100644 index 0000000..2d86c7a --- /dev/null +++ b/src/DemoForOldXmlConfig/Program.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using Newtonsoft.Json; +using WebApi.Proxies.One.Clients; +using WebApi.Proxies.One.Models; + +namespace DemoForOldXmlConfig +{ + /// + /// this project use old xml config file for test forward compatbility + /// before run this , build server project in this solution and run the exe file + /// + class Program + { + static void Main(string[] args) + { + + var baseAddr = "http://localhost:8888"; + Console.WriteLine("hello------from origin http client"); + + var client = new HttpClient { BaseAddress = new Uri(baseAddr) }; + + var res = client.GetAsync("api/test/GetFromSimpleArg?id=world").Result.Content.ReadAsStringAsync().Result; + Console.WriteLine(res); + Console.WriteLine("\n\n"); + + + var proxy = new ProxyClient(); + Console.WriteLine("hello------from web api proxy"); + + var v1 = proxy.GetFromSimpleArg("just say this is my name"); + Console.WriteLine("1---" + JsonConvert.SerializeObject(v1)); + + v1 = proxy.GetFromSimpleArgAsync("just say this is my name").Result; + Console.WriteLine("1-async---" + JsonConvert.SerializeObject(v1)); + + var complexModel = new ComplexModel() { Age = 18, Name = "super star" }; + var v2 = proxy.GetFromComplexArg(complexModel); + Console.WriteLine("2---" + JsonConvert.SerializeObject(v2)); + + var v3 = proxy.GetFromMixedArg(2016, complexModel); + Console.WriteLine("3---" + JsonConvert.SerializeObject(v3)); + + + var nest = new NestedModel() + { + Id = 999999, + ComplexModel = complexModel + }; + var v4 = proxy.PostFromMixedArg("this is my str", nest, complexModel); + Console.WriteLine("4---" + JsonConvert.SerializeObject(v4)); + + var v5 = proxy.PostFromMixedArg2("this is my str", complexModel, nest); + Console.WriteLine("5---" + JsonConvert.SerializeObject(v5)); + + + Console.WriteLine("---------------done!"); + Console.ReadLine(); + + } + } + + + public class ProxyClient : TestClient + { + protected override List> GenerateGetFromComplexArgKeyValueList(ComplexModel dataArg) + { + return new List>() + { + new KeyValuePair("Name", dataArg.Name), + new KeyValuePair("Age", dataArg.Age), + }; + } + + protected override List> GenerateGetFromMixedArgKeyValueList(int id, ComplexModel dataArg) + { + return new List>() + { + new KeyValuePair("Name", dataArg.Name), + new KeyValuePair("Age", dataArg.Age), + }; + } + + protected override List> GeneratePostFromMixedArg2KeyValueList(string simpleStr, ComplexModel uriComplexArg, NestedModel bodyNestedArg) + { + return new List>() + { + new KeyValuePair("Name", uriComplexArg.Name), + new KeyValuePair("Age", uriComplexArg.Age), + }; + } + } +} \ No newline at end of file diff --git a/src/DemoForOldXmlConfig/Properties/AssemblyInfo.cs b/src/DemoForOldXmlConfig/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..1099a09 --- /dev/null +++ b/src/DemoForOldXmlConfig/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("DemoForOldXmlConfig")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("DemoForOldXmlConfig")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +//将 ComVisible 设置为 false 将使此程序集中的类型 +//对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("c3301aac-4112-44b8-bd5e-af27a87865ce")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/DemoForOldXmlConfig/WebApiProxy/DemoOne.cs b/src/DemoForOldXmlConfig/WebApiProxy/DemoOne.cs new file mode 100644 index 0000000..ce12340 --- /dev/null +++ b/src/DemoForOldXmlConfig/WebApiProxy/DemoOne.cs @@ -0,0 +1,757 @@ +//------------------------------------------------------------------------------ +// +// This file is auto-generated by WebApiProxy +// Project site: http://github.com/faniereynders/webapiproxy +// +// Any changes to this file will be overwritten +// +//------------------------------------------------------------------------------ + +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Threading.Tasks; +using System.Net.Http.Formatting; +using System.Linq; +using System.Net; +using System.Web; +using Newtonsoft.Json; +using WebApiProxy.Tasks.Models; +using WebApi.Proxies.One.Models; + + +#region Proxies +namespace WebApi.Proxies.One +{ + /// + /// Client configuration. + /// + public static partial class Configuration + { + /// + /// Web Api Base Address. + /// + public static string DemoOneBaseAddress = "http://localhost:8888/"; + } +} +#endregion + +#region Models +namespace WebApi.Proxies.One.Models +{ + + + /// + /// + /// + public partial class ComplexModel + { + #region Constants + #endregion + + #region Properties + /// + /// + /// + public virtual String Name { get; set; } + /// + /// + /// + public virtual Int32 Age { get; set; } + #endregion + } + + /// + /// + /// + public partial class GenericBase + { + #region Constants + #endregion + + #region Properties + /// + /// + /// + public virtual T Id { get; set; } + #endregion + } + + /// + /// + /// + public partial class NestedModel + { + #region Constants + #endregion + + #region Properties + /// + /// + /// + public virtual ComplexModel ComplexModel { get; set; } + /// + /// + /// + public virtual Int32 Id { get; set; } + #endregion + } + + /// + /// + /// + public partial class TotalResult + { + #region Constants + #endregion + + #region Properties + /// + /// + /// + public virtual String SimpleStr { get; set; } + /// + /// + /// + public virtual ComplexModel ComplexModel { get; set; } + /// + /// + /// + public virtual NestedModel NestedModel { get; set; } + #endregion + } + + +} +#endregion + +#region Interfaces +namespace WebApi.Proxies.One.Interfaces +{ + public interface IClientBase : IDisposable + { + HttpClient HttpClient { get; } + } + + + public partial interface ITestClient : IClientBase + { + + /// + /// + /// + /// + + Task> GetFromSimpleArgAsync(String id); + + /// + /// + /// + /// + /// + GenericBase GetFromSimpleArg(String id); + + /// + /// + /// + /// + + Task GetFromComplexArgAsync(ComplexModel dataArg); + + /// + /// + /// + /// + /// + ComplexModel GetFromComplexArg(ComplexModel dataArg); + + /// + /// + /// + /// + /// + + Task GetFromMixedArgAsync(Int32 id,ComplexModel dataArg); + + /// + /// + /// + /// + /// + /// + NestedModel GetFromMixedArg(Int32 id,ComplexModel dataArg); + + /// + /// + /// + /// + /// + /// + + Task PostFromMixedArgAsync(String simpleStr,NestedModel uriNestedArg,ComplexModel bodyComplexArg); + + /// + /// + /// + /// + /// + /// + /// + TotalResult PostFromMixedArg(String simpleStr,NestedModel uriNestedArg,ComplexModel bodyComplexArg); + + /// + /// + /// + /// + /// + /// + + Task PostFromMixedArg2Async(String simpleStr,ComplexModel uriComplexArg,NestedModel bodyNestedArg); + + /// + /// + /// + /// + /// + /// + /// + TotalResult PostFromMixedArg2(String simpleStr,ComplexModel uriComplexArg,NestedModel bodyNestedArg); + + } + +} +#endregion + +#region Clients +namespace WebApi.Proxies.One.Clients +{ + /// + /// Client base class. + /// + public abstract partial class ClientBase : IDisposable + { + /// + /// Gests the HttpClient. + /// + public HttpClient HttpClient { get; protected set; } + + /// + /// Initializes a new instance of the class. + /// + protected ClientBase() + { + HttpClient = new HttpClient() + { + BaseAddress = new Uri(Configuration.DemoOneBaseAddress) + }; + + SerializationSettings = new JsonSerializerSettings + { + NullValueHandling = NullValueHandling.Ignore, + ReferenceLoopHandling = ReferenceLoopHandling.Serialize, + }; + } + + public JsonSerializerSettings SerializationSettings; + + + /// + /// Ensures that response has a valid (200 - OK) status code + /// + public virtual void EnsureSuccess(HttpResponseMessage response) + { + if (response.IsSuccessStatusCode) + return; + + throw new WebApiProxyResponseException(response); + } + + protected virtual string GenerateQueryStrFromKvList(List> kvList) + { + var urlTpl = string.Join("&", + kvList.Select(item => + { + var queryKey = Uri.EscapeDataString(item.Key); + var queryValue = string.Empty; + + if (item.Value != null) + { + if (item.Value is string) + { + queryValue = Uri.EscapeDataString((string)item.Value); + } + else + { + var queryValueJson = JsonConvert.SerializeObject(item.Value,SerializationSettings).Trim('"'); + queryValue = Uri.EscapeDataString(queryValueJson); + } + } + return queryKey + "=" + queryValue; + })); + return urlTpl; + } + + + /// + /// Initializes a new instance of the class. + /// + /// The handler. + /// if set to true [dispose handler]. + protected ClientBase(HttpMessageHandler handler, bool disposeHandler = true) + { + HttpClient = new HttpClient(handler, disposeHandler) + { + BaseAddress = new Uri(Configuration.DemoOneBaseAddress) + }; + } + + + /// + /// Encode the input parameter as a string + /// + protected string EncodeParam(T value) + { + return System.Net.WebUtility.UrlEncode(value.ToString()); + } + + /// + /// Encode the input parameter as a string + /// + protected string EncodeParam(DateTime value) + { + return System.Net.WebUtility.UrlEncode(value.ToString("s")); + } + + /// + /// Encode the input parameter as a string + /// + protected string EncodeParam(DateTimeOffset value) + { + return System.Net.WebUtility.UrlEncode(value.ToString("s")); + } + + /// + /// Releases the unmanaged resources and disposes of the managed resources. + /// + protected virtual void Dispose(bool disposing) + { + if (disposing && HttpClient != null) + { + HttpClient.Dispose(); + HttpClient = null; + } + } + + /// + /// Releases the unmanaged resources and disposes of the managed resources. + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Destructor + /// + ~ClientBase() + { + Dispose(false); + } + } + + /// + /// Helper class to access all clients at once + /// + public partial class WebApiClients + { + public TestClient Test { get; private set; } + + protected IEnumerable Clients + { + get + { + yield return Test; + } + } + + public WebApiClients(Uri baseAddress = null) + { + if (baseAddress != null) + Configuration.DemoOneBaseAddress = baseAddress.AbsoluteUri; + + Test = new TestClient(); + } + + public void SetAuthentication(AuthenticationHeaderValue auth) + { + foreach (var client in Clients) + client.HttpClient.DefaultRequestHeaders.Authorization = auth; + } + + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + foreach (var client in Clients) + client.Dispose(); + } + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + ~WebApiClients() + { + Dispose(false); + } + } + + /// + /// + /// + public partial class TestClient : ClientBase, Interfaces.ITestClient + { + + /// + /// + /// + public TestClient() : base() + { + } + + /// + /// + /// + public TestClient(HttpMessageHandler handler, bool disposeHandler = true) : base(handler, disposeHandler) + { + } + + #region Methods + + + + + /// + /// + /// + /// + /// + public virtual async Task> GetFromSimpleArgAsync(String id) + { + var requestUrl = "api/test/GetFromSimpleArg"; + + + var queryHasParamUrl = "id="+Uri.EscapeDataString(Convert.ToString(id))+""; + + + + var queryNoParamUrl = string.Empty; + + + if (string.IsNullOrEmpty(queryHasParamUrl)) + { + requestUrl = requestUrl + "?" + queryNoParamUrl; + } + else + { + requestUrl = requestUrl + "?" + queryHasParamUrl + "&" + queryNoParamUrl; + } + + + var result = await HttpClient.GetAsync(requestUrl ); + + + EnsureSuccess(result); + + return await result.Content.ReadAsAsync>(); + } + + + + + /// + /// + /// + /// + public virtual GenericBase GetFromSimpleArg(String id) + { + + return GetFromSimpleArgAsync(id).Result; + + } + + + + + /// + /// + /// + /// + /// + public virtual async Task GetFromComplexArgAsync(ComplexModel dataArg) + { + var requestUrl = "api/test/GetFromComplexArg"; + + + var queryHasParamUrl = ""; + + + + var queryNoParamUrl = GenerateGetFromComplexArgQueryString(dataArg); + + + if (string.IsNullOrEmpty(queryHasParamUrl)) + { + requestUrl = requestUrl + "?" + queryNoParamUrl; + } + else + { + requestUrl = requestUrl + "?" + queryHasParamUrl + "&" + queryNoParamUrl; + } + + + var result = await HttpClient.GetAsync(requestUrl ); + + + EnsureSuccess(result); + + return await result.Content.ReadAsAsync(); + } + + + + protected virtual string GenerateGetFromComplexArgQueryString(ComplexModel dataArg) + { + var kvList = GenerateGetFromComplexArgKeyValueList( dataArg ); + var urlTpl = GenerateQueryStrFromKvList(kvList); + + return urlTpl; + } + + protected virtual List> GenerateGetFromComplexArgKeyValueList(ComplexModel dataArg) + { + // Name={Name}&Age={Age} + throw new NotImplementedException(); + } + + + + /// + /// + /// + /// + public virtual ComplexModel GetFromComplexArg(ComplexModel dataArg) + { + + return GetFromComplexArgAsync(dataArg).Result; + + } + + + + + /// + /// + /// + /// + /// + /// + public virtual async Task GetFromMixedArgAsync(Int32 id,ComplexModel dataArg) + { + var requestUrl = "api/test/GetFromMixedArg"; + + + var queryHasParamUrl = "id="+Uri.EscapeDataString(Convert.ToString(id))+""; + + + + var queryNoParamUrl = GenerateGetFromMixedArgQueryString(id, dataArg); + + + if (string.IsNullOrEmpty(queryHasParamUrl)) + { + requestUrl = requestUrl + "?" + queryNoParamUrl; + } + else + { + requestUrl = requestUrl + "?" + queryHasParamUrl + "&" + queryNoParamUrl; + } + + + var result = await HttpClient.GetAsync(requestUrl ); + + + EnsureSuccess(result); + + return await result.Content.ReadAsAsync(); + } + + + + protected virtual string GenerateGetFromMixedArgQueryString(Int32 id,ComplexModel dataArg) + { + var kvList = GenerateGetFromMixedArgKeyValueList( id, dataArg ); + var urlTpl = GenerateQueryStrFromKvList(kvList); + + return urlTpl; + } + + protected virtual List> GenerateGetFromMixedArgKeyValueList(Int32 id,ComplexModel dataArg) + { + // Name={Name}&Age={Age} + throw new NotImplementedException(); + } + + + + /// + /// + /// + /// + /// + public virtual NestedModel GetFromMixedArg(Int32 id,ComplexModel dataArg) + { + + return GetFromMixedArgAsync(id, dataArg).Result; + + } + + + + + /// + /// + /// + /// + /// + /// + /// + public virtual async Task PostFromMixedArgAsync(String simpleStr,NestedModel uriNestedArg,ComplexModel bodyComplexArg) + { + var requestUrl = "api/test/PostFromMixedArg"; + + + var queryHasParamUrl = "simpleStr="+Uri.EscapeDataString(Convert.ToString(simpleStr))+""; + + + + var queryNoParamUrl = string.Empty; + + + if (string.IsNullOrEmpty(queryHasParamUrl)) + { + requestUrl = requestUrl + "?" + queryNoParamUrl; + } + else + { + requestUrl = requestUrl + "?" + queryHasParamUrl + "&" + queryNoParamUrl; + } + + + var result = await HttpClient.PostAsJsonAsync(requestUrl , bodyComplexArg); + + + EnsureSuccess(result); + + return await result.Content.ReadAsAsync(); + } + + + + + /// + /// + /// + /// + /// + /// + public virtual TotalResult PostFromMixedArg(String simpleStr,NestedModel uriNestedArg,ComplexModel bodyComplexArg) + { + + return PostFromMixedArgAsync(simpleStr, uriNestedArg, bodyComplexArg).Result; + + } + + + + + /// + /// + /// + /// + /// + /// + /// + public virtual async Task PostFromMixedArg2Async(String simpleStr,ComplexModel uriComplexArg,NestedModel bodyNestedArg) + { + var requestUrl = "api/test/PostFromMixedArg2"; + + + var queryHasParamUrl = "simpleStr="+Uri.EscapeDataString(Convert.ToString(simpleStr))+""; + + + + var queryNoParamUrl = GeneratePostFromMixedArg2QueryString(simpleStr, uriComplexArg, bodyNestedArg); + + + if (string.IsNullOrEmpty(queryHasParamUrl)) + { + requestUrl = requestUrl + "?" + queryNoParamUrl; + } + else + { + requestUrl = requestUrl + "?" + queryHasParamUrl + "&" + queryNoParamUrl; + } + + + var result = await HttpClient.PostAsJsonAsync(requestUrl , bodyNestedArg); + + + EnsureSuccess(result); + + return await result.Content.ReadAsAsync(); + } + + + + protected virtual string GeneratePostFromMixedArg2QueryString(String simpleStr,ComplexModel uriComplexArg,NestedModel bodyNestedArg) + { + var kvList = GeneratePostFromMixedArg2KeyValueList( simpleStr, uriComplexArg, bodyNestedArg ); + var urlTpl = GenerateQueryStrFromKvList(kvList); + + return urlTpl; + } + + protected virtual List> GeneratePostFromMixedArg2KeyValueList(String simpleStr,ComplexModel uriComplexArg,NestedModel bodyNestedArg) + { + // Name={Name}&Age={Age} + throw new NotImplementedException(); + } + + + + /// + /// + /// + /// + /// + /// + public virtual TotalResult PostFromMixedArg2(String simpleStr,ComplexModel uriComplexArg,NestedModel bodyNestedArg) + { + + return PostFromMixedArg2Async(simpleStr, uriComplexArg, bodyNestedArg).Result; + + } + + #endregion + } + +} + +#endregion + diff --git a/src/DemoForOldXmlConfig/WebApiProxy/WebApiProxy.config b/src/DemoForOldXmlConfig/WebApiProxy/WebApiProxy.config new file mode 100644 index 0000000..83a2b90 --- /dev/null +++ b/src/DemoForOldXmlConfig/WebApiProxy/WebApiProxy.config @@ -0,0 +1,12 @@ + + + + diff --git a/src/DemoForOldXmlConfig/packages.config b/src/DemoForOldXmlConfig/packages.config new file mode 100644 index 0000000..bbe988a --- /dev/null +++ b/src/DemoForOldXmlConfig/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Server/App.config b/src/Server/App.config new file mode 100644 index 0000000..88fa402 --- /dev/null +++ b/src/Server/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Server/Program.cs b/src/Server/Program.cs new file mode 100644 index 0000000..44a7b02 --- /dev/null +++ b/src/Server/Program.cs @@ -0,0 +1,44 @@ +using System; +using System.Net.Http; +using System.Web.Http; +using Microsoft.Owin.Hosting; +using Owin; +using WebApiProxy.Server; + +namespace Server +{ + class Program + { + static void Main(string[] args) + { + + var baseAddr = "http://localhost:8888"; + using (var server = WebApp.Start(baseAddr)) + { + Console.WriteLine("hello------from origin http client"); + + var client = new HttpClient { BaseAddress = new Uri(baseAddr) }; + + var res = client.GetAsync("api/test/GetFromSimpleArg?id=world").Result.Content.ReadAsStringAsync().Result; + Console.WriteLine(res); + + + Console.WriteLine("---------------done!"); + Console.ReadLine(); + } + + } + } + + + public class Startup + { + public void Configuration(IAppBuilder app) + { + var config = new HttpConfiguration(); + config.RegisterProxyRoutes(); + config.MapHttpAttributeRoutes(); + app.UseWebApi(config); + } + } +} \ No newline at end of file diff --git a/src/Server/Properties/AssemblyInfo.cs b/src/Server/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..a1d0281 --- /dev/null +++ b/src/Server/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Server")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Server")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +//将 ComVisible 设置为 false 将使此程序集中的类型 +//对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("113c2e62-f473-4b44-ac7c-002096b17e49")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Server/Server.csproj b/src/Server/Server.csproj new file mode 100644 index 0000000..c02d9cc --- /dev/null +++ b/src/Server/Server.csproj @@ -0,0 +1,110 @@ + + + + + Debug + AnyCPU + {113C2E62-F473-4B44-AC7C-002096B17E49} + Exe + Properties + Server + Server + v4.5.2 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\DocsByReflection.1.0.11\lib\net40\DocsByReflection.dll + True + + + ..\packages\HelperSharp.0.0.4.2\lib\net35\HelperSharp.dll + True + + + ..\packages\Microsoft.Owin.2.0.2\lib\net45\Microsoft.Owin.dll + True + + + ..\packages\Microsoft.Owin.Host.HttpListener.2.0.2\lib\net45\Microsoft.Owin.Host.HttpListener.dll + True + + + ..\packages\Microsoft.Owin.Hosting.2.0.2\lib\net45\Microsoft.Owin.Hosting.dll + True + + + ..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll + True + + + ..\packages\Owin.1.0\lib\net40\Owin.dll + True + + + + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll + True + + + ..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll + True + + + ..\packages\Microsoft.AspNet.WebApi.Owin.5.2.3\lib\net45\System.Web.Http.Owin.dll + True + + + + + + + + + ..\packages\WebApiProxy.1.3.6011.17725\lib\net45\WebApiProxy.Core.dll + True + + + ..\packages\WebApiProxy.1.3.6011.17725\lib\net45\WebApiProxy.Server.dll + True + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Server/TestController.cs b/src/Server/TestController.cs new file mode 100644 index 0000000..6edcc80 --- /dev/null +++ b/src/Server/TestController.cs @@ -0,0 +1,108 @@ +using System.Web.Http; +using System.Web.Http.Description; + +namespace Server +{ + [RoutePrefix("api/test")] + public class TestController : ApiController + { + [HttpGet] + [ResponseType(typeof(GenericBase))] + [Route("GetFromSimpleArg")] + public IHttpActionResult GetFromSimpleArg(string id) + { + return Ok(new GenericBase() { Id = id }); + } + + [HttpGet] + [ResponseType(typeof(ComplexModel))] + [Route("GetFromComplexArg")] + public IHttpActionResult GetFromComplexArg([FromUri]ComplexModel dataArg) + { + return Ok(dataArg); + } + + [HttpGet] + [ResponseType(typeof(NestedModel))] + [Route("GetFromMixedArg")] + public IHttpActionResult GetFromMixedArg(int id, [FromUri] ComplexModel dataArg) + { + return Ok(new NestedModel() + { + Id = id, + ComplexModel = dataArg + }); + } + + + [HttpPost] + [Route("PostFromMixedArg")] + public TotalResult PostFromMixedArg(string simpleStr, [FromUri] NestedModel uriNestedArg, [FromBody] ComplexModel bodyComplexArg) + { + /* + this will not work in proxy client, because uriNestedArg will not generate + a uri for client to post,but it can be support in proxyTemplate.tt + if nested class[array,list...] is used for uri parameters binding become more common. + + but this can be request from browser[post uri with body part], it means this Action has no problem. + */ + + + return new TotalResult() + { + SimpleStr = simpleStr, + ComplexModel = bodyComplexArg, + NestedModel = uriNestedArg + }; + } + + + [HttpPost] + [Route("PostFromMixedArg2")] + public TotalResult PostFromMixedArg2(string simpleStr, [FromUri]ComplexModel uriComplexArg, [FromBody]NestedModel bodyNestedArg) + { + return new TotalResult() + { + SimpleStr = simpleStr, + ComplexModel = uriComplexArg, + NestedModel = bodyNestedArg + }; + } + + + // PUT api/values/5 + public void Put(int id, [FromBody]string value) + { + } + + + + // DELETE api/values/5 + public void Delete(int id) + { + } + } + + public class GenericBase + { + public T Id { get; set; } + } + + public class ComplexModel + { + public string Name { get; set; } + public int Age { get; set; } + } + + public class NestedModel : GenericBase + { + public ComplexModel ComplexModel { get; set; } + } + + public class TotalResult + { + public string SimpleStr { get; set; } + public ComplexModel ComplexModel { get; set; } + public NestedModel NestedModel { get; set; } + } +} diff --git a/src/Server/packages.config b/src/Server/packages.config new file mode 100644 index 0000000..9d08a8a --- /dev/null +++ b/src/Server/packages.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file