From 184062cf325805e47cfd9f3ddca73b827ee6516f Mon Sep 17 00:00:00 2001 From: $+j <lust4life.jun@gmail.com> Date: Thu, 16 Jun 2016 20:29:11 +0800 Subject: [PATCH 1/2] add samples strcuture --- .gitattributes | 63 +++++ .gitignore | 245 ++++++++++++++++++ src/Default.sln | 28 ++ src/Default/App.config | 18 ++ src/Default/Default.csproj | 110 ++++++++ src/Default/FooController.cs | 108 ++++++++ src/Default/Program.cs | 44 ++++ src/Default/Properties/AssemblyInfo.cs | 36 +++ src/Default/packages.config | 15 ++ src/DemoForOldXmlConfig/App.config | 6 + .../DemoForOldXmlConfig.csproj | 60 +++++ src/DemoForOldXmlConfig/Program.cs | 15 ++ .../Properties/AssemblyInfo.cs | 36 +++ 13 files changed, 784 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 src/Default.sln create mode 100644 src/Default/App.config create mode 100644 src/Default/Default.csproj create mode 100644 src/Default/FooController.cs create mode 100644 src/Default/Program.cs create mode 100644 src/Default/Properties/AssemblyInfo.cs create mode 100644 src/Default/packages.config create mode 100644 src/DemoForOldXmlConfig/App.config create mode 100644 src/DemoForOldXmlConfig/DemoForOldXmlConfig.csproj create mode 100644 src/DemoForOldXmlConfig/Program.cs create mode 100644 src/DemoForOldXmlConfig/Properties/AssemblyInfo.cs 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..5b70f93 --- /dev/null +++ b/src/Default.sln @@ -0,0 +1,28 @@ + +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 +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 + 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..8212e14 --- /dev/null +++ b/src/Default/App.config @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="utf-8"?> +<configuration> + <startup> + <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> + </startup> + <runtime> + <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> + <dependentAssembly> + <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" /> + </dependentAssembly> + </assemblyBinding> + </runtime> +</configuration> \ No newline at end of file diff --git a/src/Default/Default.csproj b/src/Default/Default.csproj new file mode 100644 index 0000000..06f73fe --- /dev/null +++ b/src/Default/Default.csproj @@ -0,0 +1,110 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{18D29CED-5D67-4445-8CE8-30BDAF23143D}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>Default</RootNamespace> + <AssemblyName>Default</AssemblyName> + <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="DocsByReflection, Version=1.0.8.0, Culture=neutral, PublicKeyToken=64d1e8338525e7be, processorArchitecture=MSIL"> + <HintPath>..\packages\DocsByReflection.1.0.11\lib\net40\DocsByReflection.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="HelperSharp, Version=1.0.5560.27038, Culture=neutral, PublicKeyToken=3d44152485e1a4e1, processorArchitecture=MSIL"> + <HintPath>..\packages\HelperSharp.0.0.4.2\lib\net35\HelperSharp.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="Microsoft.Owin, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> + <HintPath>..\packages\Microsoft.Owin.3.0.1\lib\net45\Microsoft.Owin.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="Microsoft.Owin.Host.HttpListener, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> + <HintPath>..\packages\Microsoft.Owin.Host.HttpListener.3.0.1\lib\net45\Microsoft.Owin.Host.HttpListener.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="Microsoft.Owin.Hosting, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> + <HintPath>..\packages\Microsoft.Owin.Hosting.3.0.1\lib\net45\Microsoft.Owin.Hosting.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> + <HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL"> + <HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="System" /> + <Reference Include="System.Core" /> + <Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> + <HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> + <HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="System.Web.Http.Owin, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> + <HintPath>..\packages\Microsoft.AspNet.WebApi.Owin.5.2.3\lib\net45\System.Web.Http.Owin.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="System.Xml.Linq" /> + <Reference Include="System.Data.DataSetExtensions" /> + <Reference Include="Microsoft.CSharp" /> + <Reference Include="System.Data" /> + <Reference Include="System.Net.Http" /> + <Reference Include="System.Xml" /> + <Reference Include="WebApiProxy.Core, Version=1.3.6011.17722, Culture=neutral, processorArchitecture=MSIL"> + <HintPath>..\packages\WebApiProxy.1.3.6011.17725\lib\net45\WebApiProxy.Core.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="WebApiProxy.Server, Version=1.3.6011.17725, Culture=neutral, processorArchitecture=MSIL"> + <HintPath>..\packages\WebApiProxy.1.3.6011.17725\lib\net45\WebApiProxy.Server.dll</HintPath> + <Private>True</Private> + </Reference> + </ItemGroup> + <ItemGroup> + <Compile Include="FooController.cs" /> + <Compile Include="Program.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="App.config" /> + <None Include="packages.config" /> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> +</Project> \ No newline at end of file diff --git a/src/Default/FooController.cs b/src/Default/FooController.cs new file mode 100644 index 0000000..389eb06 --- /dev/null +++ b/src/Default/FooController.cs @@ -0,0 +1,108 @@ +using System.Web.Http; +using System.Web.Http.Description; + +namespace Default +{ + [RoutePrefix("api/test")] + public class TestController : ApiController + { + [HttpGet] + [ResponseType(typeof(GenericBase<string>))] + [Route("GetFromSimpleArg")] + public IHttpActionResult GetFromSimpleArg(string id) + { + return Ok(new GenericBase<string>() { 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<T> + { + public T Id { get; set; } + } + + public class ComplexModel + { + public string Name { get; set; } + public int Age { get; set; } + } + + public class NestedModel : GenericBase<int> + { + 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/Default/Program.cs b/src/Default/Program.cs new file mode 100644 index 0000000..d391e07 --- /dev/null +++ b/src/Default/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 Default +{ + class Program + { + static void Main(string[] args) + { + + var baseAddr = "http://localhost:8888"; + using (var server = WebApp.Start<Startup>(baseAddr)) + { + Console.WriteLine("hello"); + + 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/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/packages.config b/src/Default/packages.config new file mode 100644 index 0000000..0dc846d --- /dev/null +++ b/src/Default/packages.config @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="DocsByReflection" version="1.0.11" targetFramework="net452" /> + <package id="HelperSharp" version="0.0.4.2" targetFramework="net452" /> + <package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" /> + <package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net452" /> + <package id="Microsoft.AspNet.WebApi.Owin" version="5.2.3" targetFramework="net452" /> + <package id="Microsoft.AspNet.WebApi.OwinSelfHost" version="5.2.3" targetFramework="net452" /> + <package id="Microsoft.Owin" version="3.0.1" targetFramework="net452" /> + <package id="Microsoft.Owin.Host.HttpListener" version="3.0.1" targetFramework="net452" /> + <package id="Microsoft.Owin.Hosting" version="3.0.1" targetFramework="net452" /> + <package id="Newtonsoft.Json" version="8.0.3" targetFramework="net452" /> + <package id="Owin" version="1.0" targetFramework="net452" /> + <package id="WebApiProxy" version="1.3.6011.17725" targetFramework="net452" /> +</packages> \ No newline at end of file diff --git a/src/DemoForOldXmlConfig/App.config b/src/DemoForOldXmlConfig/App.config new file mode 100644 index 0000000..88fa402 --- /dev/null +++ b/src/DemoForOldXmlConfig/App.config @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8" ?> +<configuration> + <startup> + <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> + </startup> +</configuration> \ No newline at end of file diff --git a/src/DemoForOldXmlConfig/DemoForOldXmlConfig.csproj b/src/DemoForOldXmlConfig/DemoForOldXmlConfig.csproj new file mode 100644 index 0000000..e881b19 --- /dev/null +++ b/src/DemoForOldXmlConfig/DemoForOldXmlConfig.csproj @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{C3301AAC-4112-44B8-BD5E-AF27A87865CE}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>DemoForOldXmlConfig</RootNamespace> + <AssemblyName>DemoForOldXmlConfig</AssemblyName> + <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="System" /> + <Reference Include="System.Core" /> + <Reference Include="System.Xml.Linq" /> + <Reference Include="System.Data.DataSetExtensions" /> + <Reference Include="Microsoft.CSharp" /> + <Reference Include="System.Data" /> + <Reference Include="System.Net.Http" /> + <Reference Include="System.Xml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Program.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="App.config" /> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> +</Project> \ No newline at end of file diff --git a/src/DemoForOldXmlConfig/Program.cs b/src/DemoForOldXmlConfig/Program.cs new file mode 100644 index 0000000..c11b646 --- /dev/null +++ b/src/DemoForOldXmlConfig/Program.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DemoForOldXmlConfig +{ + class Program + { + static void Main(string[] args) + { + } + } +} 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")] From bd85a7c277918b42675bdb0170b437a3c7759c4d Mon Sep 17 00:00:00 2001 From: $+j <lust4life.jun@gmail.com> Date: Thu, 16 Jun 2016 23:42:43 +0800 Subject: [PATCH 2/2] refine structure, samples run exactly --- src/Default.sln | 6 + src/Default/App.config | 12 - src/Default/Default.csproj | 59 +- src/Default/Program.cs | 88 +- src/Default/WebApiProxy/DemoOne.cs | 757 ++++++++++++++++++ src/Default/WebApiProxy/DemoTwo.cs | 757 ++++++++++++++++++ src/Default/WebApiProxy/WebApiProxy.json | 18 + src/Default/packages.config | 13 +- src/DemoForOldXmlConfig/App.config | 2 +- .../DemoForOldXmlConfig.csproj | 30 + src/DemoForOldXmlConfig/Program.cs | 87 +- .../WebApiProxy/DemoOne.cs | 757 ++++++++++++++++++ .../WebApiProxy/WebApiProxy.config | 12 + src/DemoForOldXmlConfig/packages.config | 6 + src/Server/App.config | 6 + src/Server/Program.cs | 44 + src/Server/Properties/AssemblyInfo.cs | 36 + src/Server/Server.csproj | 110 +++ .../TestController.cs} | 2 +- src/Server/packages.config | 15 + 20 files changed, 2729 insertions(+), 88 deletions(-) create mode 100644 src/Default/WebApiProxy/DemoOne.cs create mode 100644 src/Default/WebApiProxy/DemoTwo.cs create mode 100644 src/Default/WebApiProxy/WebApiProxy.json create mode 100644 src/DemoForOldXmlConfig/WebApiProxy/DemoOne.cs create mode 100644 src/DemoForOldXmlConfig/WebApiProxy/WebApiProxy.config create mode 100644 src/DemoForOldXmlConfig/packages.config create mode 100644 src/Server/App.config create mode 100644 src/Server/Program.cs create mode 100644 src/Server/Properties/AssemblyInfo.cs create mode 100644 src/Server/Server.csproj rename src/{Default/FooController.cs => Server/TestController.cs} (99%) create mode 100644 src/Server/packages.config diff --git a/src/Default.sln b/src/Default.sln index 5b70f93..c6ec490 100644 --- a/src/Default.sln +++ b/src/Default.sln @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Default", "Default\Default. 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 @@ -21,6 +23,10 @@ Global {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 diff --git a/src/Default/App.config b/src/Default/App.config index 8212e14..03644c1 100644 --- a/src/Default/App.config +++ b/src/Default/App.config @@ -3,16 +3,4 @@ <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> </startup> - <runtime> - <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> - <dependentAssembly> - <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" /> - <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> - </dependentAssembly> - <dependentAssembly> - <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> - <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" /> - </dependentAssembly> - </assemblyBinding> - </runtime> </configuration> \ No newline at end of file diff --git a/src/Default/Default.csproj b/src/Default/Default.csproj index 06f73fe..6f72855 100644 --- a/src/Default/Default.csproj +++ b/src/Default/Default.csproj @@ -12,6 +12,8 @@ <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> + <NuGetPackageImportStamp> + </NuGetPackageImportStamp> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> @@ -33,46 +35,14 @@ <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> - <Reference Include="DocsByReflection, Version=1.0.8.0, Culture=neutral, PublicKeyToken=64d1e8338525e7be, processorArchitecture=MSIL"> - <HintPath>..\packages\DocsByReflection.1.0.11\lib\net40\DocsByReflection.dll</HintPath> - <Private>True</Private> - </Reference> - <Reference Include="HelperSharp, Version=1.0.5560.27038, Culture=neutral, PublicKeyToken=3d44152485e1a4e1, processorArchitecture=MSIL"> - <HintPath>..\packages\HelperSharp.0.0.4.2\lib\net35\HelperSharp.dll</HintPath> - <Private>True</Private> - </Reference> - <Reference Include="Microsoft.Owin, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> - <HintPath>..\packages\Microsoft.Owin.3.0.1\lib\net45\Microsoft.Owin.dll</HintPath> - <Private>True</Private> - </Reference> - <Reference Include="Microsoft.Owin.Host.HttpListener, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> - <HintPath>..\packages\Microsoft.Owin.Host.HttpListener.3.0.1\lib\net45\Microsoft.Owin.Host.HttpListener.dll</HintPath> - <Private>True</Private> - </Reference> - <Reference Include="Microsoft.Owin.Hosting, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> - <HintPath>..\packages\Microsoft.Owin.Hosting.3.0.1\lib\net45\Microsoft.Owin.Hosting.dll</HintPath> - <Private>True</Private> - </Reference> - <Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> - <HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath> - <Private>True</Private> - </Reference> - <Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL"> - <HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath> + <Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> + <HintPath>..\packages\WebApiProxy.CSharp.1.0.6011.40179\lib\net45\Newtonsoft.Json.dll</HintPath> <Private>True</Private> </Reference> <Reference Include="System" /> <Reference Include="System.Core" /> <Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> - <HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath> - <Private>True</Private> - </Reference> - <Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> - <HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath> - <Private>True</Private> - </Reference> - <Reference Include="System.Web.Http.Owin, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> - <HintPath>..\packages\Microsoft.AspNet.WebApi.Owin.5.2.3\lib\net45\System.Web.Http.Owin.dll</HintPath> + <HintPath>..\packages\WebApiProxy.CSharp.1.0.6011.40179\lib\net45\System.Net.Http.Formatting.dll</HintPath> <Private>True</Private> </Reference> <Reference Include="System.Xml.Linq" /> @@ -81,25 +51,34 @@ <Reference Include="System.Data" /> <Reference Include="System.Net.Http" /> <Reference Include="System.Xml" /> - <Reference Include="WebApiProxy.Core, Version=1.3.6011.17722, Culture=neutral, processorArchitecture=MSIL"> - <HintPath>..\packages\WebApiProxy.1.3.6011.17725\lib\net45\WebApiProxy.Core.dll</HintPath> + <Reference Include="WebApiProxy.Core, Version=1.0.6011.28483, Culture=neutral, processorArchitecture=MSIL"> + <HintPath>..\packages\WebApiProxy.CSharp.1.0.6011.40179\lib\net45\WebApiProxy.Core.dll</HintPath> <Private>True</Private> </Reference> - <Reference Include="WebApiProxy.Server, Version=1.3.6011.17725, Culture=neutral, processorArchitecture=MSIL"> - <HintPath>..\packages\WebApiProxy.1.3.6011.17725\lib\net45\WebApiProxy.Server.dll</HintPath> + <Reference Include="WebApiProxy.Tasks, Version=1.0.6011.40179, Culture=neutral, processorArchitecture=MSIL"> + <HintPath>..\packages\WebApiProxy.CSharp.1.0.6011.40179\lib\net45\WebApiProxy.Tasks.dll</HintPath> <Private>True</Private> </Reference> </ItemGroup> <ItemGroup> - <Compile Include="FooController.cs" /> <Compile Include="Program.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="WebApiProxy\DemoOne.cs" /> + <Compile Include="WebApiProxy\DemoTwo.cs" /> </ItemGroup> <ItemGroup> <None Include="App.config" /> <None Include="packages.config" /> + <None Include="WebApiProxy\WebApiProxy.json" /> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <Import Project="..\packages\WebApiProxy.CSharp.1.0.6011.40179\build\WebApiProxy.CSharp.targets" Condition="Exists('..\packages\WebApiProxy.CSharp.1.0.6011.40179\build\WebApiProxy.CSharp.targets')" /> + <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> + <PropertyGroup> + <ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText> + </PropertyGroup> + <Error Condition="!Exists('..\packages\WebApiProxy.CSharp.1.0.6011.40179\build\WebApiProxy.CSharp.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\WebApiProxy.CSharp.1.0.6011.40179\build\WebApiProxy.CSharp.targets'))" /> + </Target> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. <Target Name="BeforeBuild"> diff --git a/src/Default/Program.cs b/src/Default/Program.cs index d391e07..4a3d679 100644 --- a/src/Default/Program.cs +++ b/src/Default/Program.cs @@ -1,44 +1,94 @@ using System; +using System.Collections.Generic; using System.Net.Http; -using System.Web.Http; -using Microsoft.Owin.Hosting; -using Owin; -using WebApiProxy.Server; +using Newtonsoft.Json; +using WebApi.Proxies.One.Clients; +using WebApi.Proxies.One.Models; namespace Default { + /// <summary> + /// 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 + /// </summary> class Program { static void Main(string[] args) { var baseAddr = "http://localhost:8888"; - using (var server = WebApp.Start<Startup>(baseAddr)) - { - Console.WriteLine("hello"); + 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 client = new HttpClient {BaseAddress = new Uri(baseAddr)}; + var v1 = proxy.GetFromSimpleArg("just say this is my name"); + Console.WriteLine("1---" + JsonConvert.SerializeObject(v1)); - var res = client.GetAsync("api/test/GetFromSimpleArg?id=world").Result.Content.ReadAsStringAsync().Result; - Console.WriteLine(res); + 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)); - Console.WriteLine("---------------done!"); - Console.ReadLine(); - } + var v5 = proxy.PostFromMixedArg2("this is my str", complexModel, nest); + Console.WriteLine("5---" + JsonConvert.SerializeObject(v5)); + + + Console.WriteLine("---------------done!"); + Console.ReadLine(); } } - public class Startup + public class ProxyClient : TestClient { - public void Configuration(IAppBuilder app) + protected override List<KeyValuePair<string, object>> GenerateGetFromComplexArgKeyValueList(ComplexModel dataArg) + { + return new List<KeyValuePair<string, object>>() + { + new KeyValuePair<string, object>("Name", dataArg.Name), + new KeyValuePair<string, object>("Age", dataArg.Age), + }; + } + + protected override List<KeyValuePair<string, object>> GenerateGetFromMixedArgKeyValueList(int id, ComplexModel dataArg) + { + return new List<KeyValuePair<string, object>>() + { + new KeyValuePair<string, object>("Name", dataArg.Name), + new KeyValuePair<string, object>("Age", dataArg.Age), + }; + } + + protected override List<KeyValuePair<string, object>> GeneratePostFromMixedArg2KeyValueList(string simpleStr, ComplexModel uriComplexArg, NestedModel bodyNestedArg) { - var config = new HttpConfiguration(); - config.RegisterProxyRoutes(); - config.MapHttpAttributeRoutes(); - app.UseWebApi(config); + return new List<KeyValuePair<string, object>>() + { + new KeyValuePair<string, object>("Name", uriComplexArg.Name), + new KeyValuePair<string, object>("Age", uriComplexArg.Age), + }; } } } \ No newline at end of file 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 @@ +//------------------------------------------------------------------------------ +//<auto-generated> +// This file is auto-generated by WebApiProxy +// Project site: http://github.com/faniereynders/webapiproxy +// +// Any changes to this file will be overwritten +//</auto-generated> +//------------------------------------------------------------------------------ + +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 +{ + /// <summary> + /// Client configuration. + /// </summary> + public static partial class Configuration + { + /// <summary> + /// Web Api Base Address. + /// </summary> + public static string DemoOneBaseAddress = "http://localhost:8888/"; + } +} +#endregion + +#region Models +namespace WebApi.Proxies.One.Models +{ + + + /// <summary> + /// + /// </summary> + public partial class ComplexModel + { + #region Constants + #endregion + + #region Properties + /// <summary> + /// + /// </summary> + public virtual String Name { get; set; } + /// <summary> + /// + /// </summary> + public virtual Int32 Age { get; set; } + #endregion + } + + /// <summary> + /// + /// </summary> + public partial class GenericBase<T> + { + #region Constants + #endregion + + #region Properties + /// <summary> + /// + /// </summary> + public virtual T Id { get; set; } + #endregion + } + + /// <summary> + /// + /// </summary> + public partial class NestedModel + { + #region Constants + #endregion + + #region Properties + /// <summary> + /// + /// </summary> + public virtual ComplexModel ComplexModel { get; set; } + /// <summary> + /// + /// </summary> + public virtual Int32 Id { get; set; } + #endregion + } + + /// <summary> + /// + /// </summary> + public partial class TotalResult + { + #region Constants + #endregion + + #region Properties + /// <summary> + /// + /// </summary> + public virtual String SimpleStr { get; set; } + /// <summary> + /// + /// </summary> + public virtual ComplexModel ComplexModel { get; set; } + /// <summary> + /// + /// </summary> + 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 + { + + /// <summary> + /// + /// </summary> + /// <param name="id"></param> + + Task<GenericBase<String>> GetFromSimpleArgAsync(String id); + + /// <summary> + /// + /// </summary> + /// <param name="id"></param> + /// <returns></returns> + GenericBase<String> GetFromSimpleArg(String id); + + /// <summary> + /// + /// </summary> + /// <param name="dataArg"></param> + + Task<ComplexModel> GetFromComplexArgAsync(ComplexModel dataArg); + + /// <summary> + /// + /// </summary> + /// <param name="dataArg"></param> + /// <returns></returns> + ComplexModel GetFromComplexArg(ComplexModel dataArg); + + /// <summary> + /// + /// </summary> + /// <param name="id"></param> + /// <param name="dataArg"></param> + + Task<NestedModel> GetFromMixedArgAsync(Int32 id,ComplexModel dataArg); + + /// <summary> + /// + /// </summary> + /// <param name="id"></param> + /// <param name="dataArg"></param> + /// <returns></returns> + NestedModel GetFromMixedArg(Int32 id,ComplexModel dataArg); + + /// <summary> + /// + /// </summary> + /// <param name="simpleStr"></param> + /// <param name="uriNestedArg"></param> + /// <param name="bodyComplexArg"></param> + + Task<TotalResult> PostFromMixedArgAsync(String simpleStr,NestedModel uriNestedArg,ComplexModel bodyComplexArg); + + /// <summary> + /// + /// </summary> + /// <param name="simpleStr"></param> + /// <param name="uriNestedArg"></param> + /// <param name="bodyComplexArg"></param> + /// <returns></returns> + TotalResult PostFromMixedArg(String simpleStr,NestedModel uriNestedArg,ComplexModel bodyComplexArg); + + /// <summary> + /// + /// </summary> + /// <param name="simpleStr"></param> + /// <param name="uriComplexArg"></param> + /// <param name="bodyNestedArg"></param> + + Task<TotalResult> PostFromMixedArg2Async(String simpleStr,ComplexModel uriComplexArg,NestedModel bodyNestedArg); + + /// <summary> + /// + /// </summary> + /// <param name="simpleStr"></param> + /// <param name="uriComplexArg"></param> + /// <param name="bodyNestedArg"></param> + /// <returns></returns> + TotalResult PostFromMixedArg2(String simpleStr,ComplexModel uriComplexArg,NestedModel bodyNestedArg); + + } + +} +#endregion + +#region Clients +namespace WebApi.Proxies.One.Clients +{ + /// <summary> + /// Client base class. + /// </summary> + public abstract partial class ClientBase : IDisposable + { + /// <summary> + /// Gests the HttpClient. + /// </summary> + public HttpClient HttpClient { get; protected set; } + + /// <summary> + /// Initializes a new instance of the <see cref="ClientBase"/> class. + /// </summary> + protected ClientBase() + { + HttpClient = new HttpClient() + { + BaseAddress = new Uri(Configuration.DemoOneBaseAddress) + }; + + SerializationSettings = new JsonSerializerSettings + { + NullValueHandling = NullValueHandling.Ignore, + ReferenceLoopHandling = ReferenceLoopHandling.Serialize, + }; + } + + public JsonSerializerSettings SerializationSettings; + + + /// <summary> + /// Ensures that response has a valid (200 - OK) status code + /// </summary> + public virtual void EnsureSuccess(HttpResponseMessage response) + { + if (response.IsSuccessStatusCode) + return; + + throw new WebApiProxyResponseException(response); + } + + protected virtual string GenerateQueryStrFromKvList(List<KeyValuePair<string, object>> 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; + } + + + /// <summary> + /// Initializes a new instance of the <see cref="ClientBase"/> class. + /// </summary> + /// <param name="handler">The handler.</param> + /// <param name="disposeHandler">if set to <c>true</c> [dispose handler].</param> + protected ClientBase(HttpMessageHandler handler, bool disposeHandler = true) + { + HttpClient = new HttpClient(handler, disposeHandler) + { + BaseAddress = new Uri(Configuration.DemoOneBaseAddress) + }; + } + + + /// <summary> + /// Encode the input parameter as a string + /// </summary> + protected string EncodeParam<T>(T value) + { + return System.Net.WebUtility.UrlEncode(value.ToString()); + } + + /// <summary> + /// Encode the input parameter as a string + /// </summary> + protected string EncodeParam(DateTime value) + { + return System.Net.WebUtility.UrlEncode(value.ToString("s")); + } + + /// <summary> + /// Encode the input parameter as a string + /// </summary> + protected string EncodeParam(DateTimeOffset value) + { + return System.Net.WebUtility.UrlEncode(value.ToString("s")); + } + + /// <summary> + /// Releases the unmanaged resources and disposes of the managed resources. + /// </summary> + protected virtual void Dispose(bool disposing) + { + if (disposing && HttpClient != null) + { + HttpClient.Dispose(); + HttpClient = null; + } + } + + /// <summary> + /// Releases the unmanaged resources and disposes of the managed resources. + /// </summary> + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// <summary> + /// Destructor + /// </summary> + ~ClientBase() + { + Dispose(false); + } + } + + /// <summary> + /// Helper class to access all clients at once + /// </summary> + public partial class WebApiClients + { + public TestClient Test { get; private set; } + + protected IEnumerable<Interfaces.IClientBase> 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); + } + } + + /// <summary> + /// + /// </summary> + public partial class TestClient : ClientBase, Interfaces.ITestClient + { + + /// <summary> + /// + /// </summary> + public TestClient() : base() + { + } + + /// <summary> + /// + /// </summary> + public TestClient(HttpMessageHandler handler, bool disposeHandler = true) : base(handler, disposeHandler) + { + } + + #region Methods + + + + + /// <summary> + /// + /// </summary> + /// <param name="id"></param> + /// <returns></returns> + public virtual async Task<GenericBase<String>> 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<GenericBase<String>>(); + } + + + + + /// <summary> + /// + /// </summary> + /// <param name="id"></param> + public virtual GenericBase<String> GetFromSimpleArg(String id) + { + + return GetFromSimpleArgAsync(id).Result; + + } + + + + + /// <summary> + /// + /// </summary> + /// <param name="dataArg"></param> + /// <returns></returns> + public virtual async Task<ComplexModel> 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<ComplexModel>(); + } + + + + protected virtual string GenerateGetFromComplexArgQueryString(ComplexModel dataArg) + { + var kvList = GenerateGetFromComplexArgKeyValueList( dataArg ); + var urlTpl = GenerateQueryStrFromKvList(kvList); + + return urlTpl; + } + + protected virtual List<KeyValuePair<string, object>> GenerateGetFromComplexArgKeyValueList(ComplexModel dataArg) + { + // Name={Name}&Age={Age} + throw new NotImplementedException(); + } + + + + /// <summary> + /// + /// </summary> + /// <param name="dataArg"></param> + public virtual ComplexModel GetFromComplexArg(ComplexModel dataArg) + { + + return GetFromComplexArgAsync(dataArg).Result; + + } + + + + + /// <summary> + /// + /// </summary> + /// <param name="id"></param> + /// <param name="dataArg"></param> + /// <returns></returns> + public virtual async Task<NestedModel> 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<NestedModel>(); + } + + + + protected virtual string GenerateGetFromMixedArgQueryString(Int32 id,ComplexModel dataArg) + { + var kvList = GenerateGetFromMixedArgKeyValueList( id, dataArg ); + var urlTpl = GenerateQueryStrFromKvList(kvList); + + return urlTpl; + } + + protected virtual List<KeyValuePair<string, object>> GenerateGetFromMixedArgKeyValueList(Int32 id,ComplexModel dataArg) + { + // Name={Name}&Age={Age} + throw new NotImplementedException(); + } + + + + /// <summary> + /// + /// </summary> + /// <param name="id"></param> + /// <param name="dataArg"></param> + public virtual NestedModel GetFromMixedArg(Int32 id,ComplexModel dataArg) + { + + return GetFromMixedArgAsync(id, dataArg).Result; + + } + + + + + /// <summary> + /// + /// </summary> + /// <param name="simpleStr"></param> + /// <param name="uriNestedArg"></param> + /// <param name="bodyComplexArg"></param> + /// <returns></returns> + public virtual async Task<TotalResult> 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<ComplexModel>(requestUrl , bodyComplexArg); + + + EnsureSuccess(result); + + return await result.Content.ReadAsAsync<TotalResult>(); + } + + + + + /// <summary> + /// + /// </summary> + /// <param name="simpleStr"></param> + /// <param name="uriNestedArg"></param> + /// <param name="bodyComplexArg"></param> + public virtual TotalResult PostFromMixedArg(String simpleStr,NestedModel uriNestedArg,ComplexModel bodyComplexArg) + { + + return PostFromMixedArgAsync(simpleStr, uriNestedArg, bodyComplexArg).Result; + + } + + + + + /// <summary> + /// + /// </summary> + /// <param name="simpleStr"></param> + /// <param name="uriComplexArg"></param> + /// <param name="bodyNestedArg"></param> + /// <returns></returns> + public virtual async Task<TotalResult> 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<NestedModel>(requestUrl , bodyNestedArg); + + + EnsureSuccess(result); + + return await result.Content.ReadAsAsync<TotalResult>(); + } + + + + 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<KeyValuePair<string, object>> GeneratePostFromMixedArg2KeyValueList(String simpleStr,ComplexModel uriComplexArg,NestedModel bodyNestedArg) + { + // Name={Name}&Age={Age} + throw new NotImplementedException(); + } + + + + /// <summary> + /// + /// </summary> + /// <param name="simpleStr"></param> + /// <param name="uriComplexArg"></param> + /// <param name="bodyNestedArg"></param> + 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 @@ +//------------------------------------------------------------------------------ +//<auto-generated> +// This file is auto-generated by WebApiProxy +// Project site: http://github.com/faniereynders/webapiproxy +// +// Any changes to this file will be overwritten +//</auto-generated> +//------------------------------------------------------------------------------ + +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 +{ + /// <summary> + /// Client configuration. + /// </summary> + public static partial class Configuration + { + /// <summary> + /// Web Api Base Address. + /// </summary> + public static string DemoTwoBaseAddress = "http://localhost:8888/"; + } +} +#endregion + +#region Models +namespace WebApi.Proxies.Two.Models +{ + + + /// <summary> + /// + /// </summary> + public partial class ComplexModel + { + #region Constants + #endregion + + #region Properties + /// <summary> + /// + /// </summary> + public virtual String Name { get; set; } + /// <summary> + /// + /// </summary> + public virtual Int32 Age { get; set; } + #endregion + } + + /// <summary> + /// + /// </summary> + public partial class GenericBase<T> + { + #region Constants + #endregion + + #region Properties + /// <summary> + /// + /// </summary> + public virtual T Id { get; set; } + #endregion + } + + /// <summary> + /// + /// </summary> + public partial class NestedModel + { + #region Constants + #endregion + + #region Properties + /// <summary> + /// + /// </summary> + public virtual ComplexModel ComplexModel { get; set; } + /// <summary> + /// + /// </summary> + public virtual Int32 Id { get; set; } + #endregion + } + + /// <summary> + /// + /// </summary> + public partial class TotalResult + { + #region Constants + #endregion + + #region Properties + /// <summary> + /// + /// </summary> + public virtual String SimpleStr { get; set; } + /// <summary> + /// + /// </summary> + public virtual ComplexModel ComplexModel { get; set; } + /// <summary> + /// + /// </summary> + 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 + { + + /// <summary> + /// + /// </summary> + /// <param name="id"></param> + + Task<GenericBase<String>> GetFromSimpleArgAsync(String id); + + /// <summary> + /// + /// </summary> + /// <param name="id"></param> + /// <returns></returns> + GenericBase<String> GetFromSimpleArg(String id); + + /// <summary> + /// + /// </summary> + /// <param name="dataArg"></param> + + Task<ComplexModel> GetFromComplexArgAsync(ComplexModel dataArg); + + /// <summary> + /// + /// </summary> + /// <param name="dataArg"></param> + /// <returns></returns> + ComplexModel GetFromComplexArg(ComplexModel dataArg); + + /// <summary> + /// + /// </summary> + /// <param name="id"></param> + /// <param name="dataArg"></param> + + Task<NestedModel> GetFromMixedArgAsync(Int32 id,ComplexModel dataArg); + + /// <summary> + /// + /// </summary> + /// <param name="id"></param> + /// <param name="dataArg"></param> + /// <returns></returns> + NestedModel GetFromMixedArg(Int32 id,ComplexModel dataArg); + + /// <summary> + /// + /// </summary> + /// <param name="simpleStr"></param> + /// <param name="uriNestedArg"></param> + /// <param name="bodyComplexArg"></param> + + Task<TotalResult> PostFromMixedArgAsync(String simpleStr,NestedModel uriNestedArg,ComplexModel bodyComplexArg); + + /// <summary> + /// + /// </summary> + /// <param name="simpleStr"></param> + /// <param name="uriNestedArg"></param> + /// <param name="bodyComplexArg"></param> + /// <returns></returns> + TotalResult PostFromMixedArg(String simpleStr,NestedModel uriNestedArg,ComplexModel bodyComplexArg); + + /// <summary> + /// + /// </summary> + /// <param name="simpleStr"></param> + /// <param name="uriComplexArg"></param> + /// <param name="bodyNestedArg"></param> + + Task<TotalResult> PostFromMixedArg2Async(String simpleStr,ComplexModel uriComplexArg,NestedModel bodyNestedArg); + + /// <summary> + /// + /// </summary> + /// <param name="simpleStr"></param> + /// <param name="uriComplexArg"></param> + /// <param name="bodyNestedArg"></param> + /// <returns></returns> + TotalResult PostFromMixedArg2(String simpleStr,ComplexModel uriComplexArg,NestedModel bodyNestedArg); + + } + +} +#endregion + +#region Clients +namespace WebApi.Proxies.Two.Clients +{ + /// <summary> + /// Client base class. + /// </summary> + public abstract partial class ClientBase : IDisposable + { + /// <summary> + /// Gests the HttpClient. + /// </summary> + public HttpClient HttpClient { get; protected set; } + + /// <summary> + /// Initializes a new instance of the <see cref="ClientBase"/> class. + /// </summary> + protected ClientBase() + { + HttpClient = new HttpClient() + { + BaseAddress = new Uri(Configuration.DemoTwoBaseAddress) + }; + + SerializationSettings = new JsonSerializerSettings + { + NullValueHandling = NullValueHandling.Ignore, + ReferenceLoopHandling = ReferenceLoopHandling.Serialize, + }; + } + + public JsonSerializerSettings SerializationSettings; + + + /// <summary> + /// Ensures that response has a valid (200 - OK) status code + /// </summary> + public virtual void EnsureSuccess(HttpResponseMessage response) + { + if (response.IsSuccessStatusCode) + return; + + throw new WebApiProxyResponseException(response); + } + + protected virtual string GenerateQueryStrFromKvList(List<KeyValuePair<string, object>> 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; + } + + + /// <summary> + /// Initializes a new instance of the <see cref="ClientBase"/> class. + /// </summary> + /// <param name="handler">The handler.</param> + /// <param name="disposeHandler">if set to <c>true</c> [dispose handler].</param> + protected ClientBase(HttpMessageHandler handler, bool disposeHandler = true) + { + HttpClient = new HttpClient(handler, disposeHandler) + { + BaseAddress = new Uri(Configuration.DemoTwoBaseAddress) + }; + } + + + /// <summary> + /// Encode the input parameter as a string + /// </summary> + protected string EncodeParam<T>(T value) + { + return System.Net.WebUtility.UrlEncode(value.ToString()); + } + + /// <summary> + /// Encode the input parameter as a string + /// </summary> + protected string EncodeParam(DateTime value) + { + return System.Net.WebUtility.UrlEncode(value.ToString("s")); + } + + /// <summary> + /// Encode the input parameter as a string + /// </summary> + protected string EncodeParam(DateTimeOffset value) + { + return System.Net.WebUtility.UrlEncode(value.ToString("s")); + } + + /// <summary> + /// Releases the unmanaged resources and disposes of the managed resources. + /// </summary> + protected virtual void Dispose(bool disposing) + { + if (disposing && HttpClient != null) + { + HttpClient.Dispose(); + HttpClient = null; + } + } + + /// <summary> + /// Releases the unmanaged resources and disposes of the managed resources. + /// </summary> + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// <summary> + /// Destructor + /// </summary> + ~ClientBase() + { + Dispose(false); + } + } + + /// <summary> + /// Helper class to access all clients at once + /// </summary> + public partial class WebApiClients + { + public TestClient Test { get; private set; } + + protected IEnumerable<Interfaces.IClientBase> 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); + } + } + + /// <summary> + /// + /// </summary> + public partial class TestClient : ClientBase, Interfaces.ITestClient + { + + /// <summary> + /// + /// </summary> + public TestClient() : base() + { + } + + /// <summary> + /// + /// </summary> + public TestClient(HttpMessageHandler handler, bool disposeHandler = true) : base(handler, disposeHandler) + { + } + + #region Methods + + + + + /// <summary> + /// + /// </summary> + /// <param name="id"></param> + /// <returns></returns> + public virtual async Task<GenericBase<String>> 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<GenericBase<String>>(); + } + + + + + /// <summary> + /// + /// </summary> + /// <param name="id"></param> + public virtual GenericBase<String> GetFromSimpleArg(String id) + { + + return GetFromSimpleArgAsync(id).Result; + + } + + + + + /// <summary> + /// + /// </summary> + /// <param name="dataArg"></param> + /// <returns></returns> + public virtual async Task<ComplexModel> 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<ComplexModel>(); + } + + + + protected virtual string GenerateGetFromComplexArgQueryString(ComplexModel dataArg) + { + var kvList = GenerateGetFromComplexArgKeyValueList( dataArg ); + var urlTpl = GenerateQueryStrFromKvList(kvList); + + return urlTpl; + } + + protected virtual List<KeyValuePair<string, object>> GenerateGetFromComplexArgKeyValueList(ComplexModel dataArg) + { + // Name={Name}&Age={Age} + throw new NotImplementedException(); + } + + + + /// <summary> + /// + /// </summary> + /// <param name="dataArg"></param> + public virtual ComplexModel GetFromComplexArg(ComplexModel dataArg) + { + + return GetFromComplexArgAsync(dataArg).Result; + + } + + + + + /// <summary> + /// + /// </summary> + /// <param name="id"></param> + /// <param name="dataArg"></param> + /// <returns></returns> + public virtual async Task<NestedModel> 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<NestedModel>(); + } + + + + protected virtual string GenerateGetFromMixedArgQueryString(Int32 id,ComplexModel dataArg) + { + var kvList = GenerateGetFromMixedArgKeyValueList( id, dataArg ); + var urlTpl = GenerateQueryStrFromKvList(kvList); + + return urlTpl; + } + + protected virtual List<KeyValuePair<string, object>> GenerateGetFromMixedArgKeyValueList(Int32 id,ComplexModel dataArg) + { + // Name={Name}&Age={Age} + throw new NotImplementedException(); + } + + + + /// <summary> + /// + /// </summary> + /// <param name="id"></param> + /// <param name="dataArg"></param> + public virtual NestedModel GetFromMixedArg(Int32 id,ComplexModel dataArg) + { + + return GetFromMixedArgAsync(id, dataArg).Result; + + } + + + + + /// <summary> + /// + /// </summary> + /// <param name="simpleStr"></param> + /// <param name="uriNestedArg"></param> + /// <param name="bodyComplexArg"></param> + /// <returns></returns> + public virtual async Task<TotalResult> 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<ComplexModel>(requestUrl , bodyComplexArg); + + + EnsureSuccess(result); + + return await result.Content.ReadAsAsync<TotalResult>(); + } + + + + + /// <summary> + /// + /// </summary> + /// <param name="simpleStr"></param> + /// <param name="uriNestedArg"></param> + /// <param name="bodyComplexArg"></param> + public virtual TotalResult PostFromMixedArg(String simpleStr,NestedModel uriNestedArg,ComplexModel bodyComplexArg) + { + + return PostFromMixedArgAsync(simpleStr, uriNestedArg, bodyComplexArg).Result; + + } + + + + + /// <summary> + /// + /// </summary> + /// <param name="simpleStr"></param> + /// <param name="uriComplexArg"></param> + /// <param name="bodyNestedArg"></param> + /// <returns></returns> + public virtual async Task<TotalResult> 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<NestedModel>(requestUrl , bodyNestedArg); + + + EnsureSuccess(result); + + return await result.Content.ReadAsAsync<TotalResult>(); + } + + + + 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<KeyValuePair<string, object>> GeneratePostFromMixedArg2KeyValueList(String simpleStr,ComplexModel uriComplexArg,NestedModel bodyNestedArg) + { + // Name={Name}&Age={Age} + throw new NotImplementedException(); + } + + + + /// <summary> + /// + /// </summary> + /// <param name="simpleStr"></param> + /// <param name="uriComplexArg"></param> + /// <param name="bodyNestedArg"></param> + 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 index 0dc846d..94a17da 100644 --- a/src/Default/packages.config +++ b/src/Default/packages.config @@ -1,15 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <packages> - <package id="DocsByReflection" version="1.0.11" targetFramework="net452" /> - <package id="HelperSharp" version="0.0.4.2" targetFramework="net452" /> <package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" /> - <package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net452" /> - <package id="Microsoft.AspNet.WebApi.Owin" version="5.2.3" targetFramework="net452" /> - <package id="Microsoft.AspNet.WebApi.OwinSelfHost" version="5.2.3" targetFramework="net452" /> - <package id="Microsoft.Owin" version="3.0.1" targetFramework="net452" /> - <package id="Microsoft.Owin.Host.HttpListener" version="3.0.1" targetFramework="net452" /> - <package id="Microsoft.Owin.Hosting" version="3.0.1" targetFramework="net452" /> - <package id="Newtonsoft.Json" version="8.0.3" targetFramework="net452" /> - <package id="Owin" version="1.0" targetFramework="net452" /> - <package id="WebApiProxy" version="1.3.6011.17725" targetFramework="net452" /> + <package id="Newtonsoft.Json" version="6.0.4" targetFramework="net452" /> + <package id="WebApiProxy.CSharp" version="1.0.6011.40179" targetFramework="net452" /> </packages> \ No newline at end of file diff --git a/src/DemoForOldXmlConfig/App.config b/src/DemoForOldXmlConfig/App.config index 88fa402..03644c1 100644 --- a/src/DemoForOldXmlConfig/App.config +++ b/src/DemoForOldXmlConfig/App.config @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8" ?> +<?xml version="1.0" encoding="utf-8"?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> diff --git a/src/DemoForOldXmlConfig/DemoForOldXmlConfig.csproj b/src/DemoForOldXmlConfig/DemoForOldXmlConfig.csproj index e881b19..3d197ad 100644 --- a/src/DemoForOldXmlConfig/DemoForOldXmlConfig.csproj +++ b/src/DemoForOldXmlConfig/DemoForOldXmlConfig.csproj @@ -12,6 +12,8 @@ <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> + <NuGetPackageImportStamp> + </NuGetPackageImportStamp> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> @@ -33,23 +35,51 @@ <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> + <Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> + <HintPath>..\packages\WebApiProxy.CSharp.1.0.6011.40179\lib\net45\Newtonsoft.Json.dll</HintPath> + <Private>True</Private> + </Reference> <Reference Include="System" /> <Reference Include="System.Core" /> + <Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> + <HintPath>..\packages\WebApiProxy.CSharp.1.0.6011.40179\lib\net45\System.Net.Http.Formatting.dll</HintPath> + <Private>True</Private> + </Reference> <Reference Include="System.Xml.Linq" /> <Reference Include="System.Data.DataSetExtensions" /> <Reference Include="Microsoft.CSharp" /> <Reference Include="System.Data" /> <Reference Include="System.Net.Http" /> <Reference Include="System.Xml" /> + <Reference Include="WebApiProxy.Core, Version=1.0.6011.28483, Culture=neutral, processorArchitecture=MSIL"> + <HintPath>..\packages\WebApiProxy.CSharp.1.0.6011.40179\lib\net45\WebApiProxy.Core.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="WebApiProxy.Tasks, Version=1.0.6011.40179, Culture=neutral, processorArchitecture=MSIL"> + <HintPath>..\packages\WebApiProxy.CSharp.1.0.6011.40179\lib\net45\WebApiProxy.Tasks.dll</HintPath> + <Private>True</Private> + </Reference> </ItemGroup> <ItemGroup> <Compile Include="Program.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="WebApiProxy\DemoOne.cs" /> </ItemGroup> <ItemGroup> <None Include="App.config" /> + <None Include="packages.config" /> + <None Include="WebApiProxy\WebApiProxy.config"> + <SubType>Designer</SubType> + </None> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <Import Project="..\packages\WebApiProxy.CSharp.1.0.6011.40179\build\WebApiProxy.CSharp.targets" Condition="Exists('..\packages\WebApiProxy.CSharp.1.0.6011.40179\build\WebApiProxy.CSharp.targets')" /> + <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> + <PropertyGroup> + <ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText> + </PropertyGroup> + <Error Condition="!Exists('..\packages\WebApiProxy.CSharp.1.0.6011.40179\build\WebApiProxy.CSharp.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\WebApiProxy.CSharp.1.0.6011.40179\build\WebApiProxy.CSharp.targets'))" /> + </Target> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. <Target Name="BeforeBuild"> diff --git a/src/DemoForOldXmlConfig/Program.cs b/src/DemoForOldXmlConfig/Program.cs index c11b646..2d86c7a 100644 --- a/src/DemoForOldXmlConfig/Program.cs +++ b/src/DemoForOldXmlConfig/Program.cs @@ -1,15 +1,94 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Net.Http; +using Newtonsoft.Json; +using WebApi.Proxies.One.Clients; +using WebApi.Proxies.One.Models; namespace DemoForOldXmlConfig { + /// <summary> + /// 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 + /// </summary> 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<KeyValuePair<string, object>> GenerateGetFromComplexArgKeyValueList(ComplexModel dataArg) + { + return new List<KeyValuePair<string, object>>() + { + new KeyValuePair<string, object>("Name", dataArg.Name), + new KeyValuePair<string, object>("Age", dataArg.Age), + }; + } + + protected override List<KeyValuePair<string, object>> GenerateGetFromMixedArgKeyValueList(int id, ComplexModel dataArg) + { + return new List<KeyValuePair<string, object>>() + { + new KeyValuePair<string, object>("Name", dataArg.Name), + new KeyValuePair<string, object>("Age", dataArg.Age), + }; + } + + protected override List<KeyValuePair<string, object>> GeneratePostFromMixedArg2KeyValueList(string simpleStr, ComplexModel uriComplexArg, NestedModel bodyNestedArg) + { + return new List<KeyValuePair<string, object>>() + { + new KeyValuePair<string, object>("Name", uriComplexArg.Name), + new KeyValuePair<string, object>("Age", uriComplexArg.Age), + }; } } -} +} \ No newline at end of file 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 @@ +//------------------------------------------------------------------------------ +//<auto-generated> +// This file is auto-generated by WebApiProxy +// Project site: http://github.com/faniereynders/webapiproxy +// +// Any changes to this file will be overwritten +//</auto-generated> +//------------------------------------------------------------------------------ + +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 +{ + /// <summary> + /// Client configuration. + /// </summary> + public static partial class Configuration + { + /// <summary> + /// Web Api Base Address. + /// </summary> + public static string DemoOneBaseAddress = "http://localhost:8888/"; + } +} +#endregion + +#region Models +namespace WebApi.Proxies.One.Models +{ + + + /// <summary> + /// + /// </summary> + public partial class ComplexModel + { + #region Constants + #endregion + + #region Properties + /// <summary> + /// + /// </summary> + public virtual String Name { get; set; } + /// <summary> + /// + /// </summary> + public virtual Int32 Age { get; set; } + #endregion + } + + /// <summary> + /// + /// </summary> + public partial class GenericBase<T> + { + #region Constants + #endregion + + #region Properties + /// <summary> + /// + /// </summary> + public virtual T Id { get; set; } + #endregion + } + + /// <summary> + /// + /// </summary> + public partial class NestedModel + { + #region Constants + #endregion + + #region Properties + /// <summary> + /// + /// </summary> + public virtual ComplexModel ComplexModel { get; set; } + /// <summary> + /// + /// </summary> + public virtual Int32 Id { get; set; } + #endregion + } + + /// <summary> + /// + /// </summary> + public partial class TotalResult + { + #region Constants + #endregion + + #region Properties + /// <summary> + /// + /// </summary> + public virtual String SimpleStr { get; set; } + /// <summary> + /// + /// </summary> + public virtual ComplexModel ComplexModel { get; set; } + /// <summary> + /// + /// </summary> + 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 + { + + /// <summary> + /// + /// </summary> + /// <param name="id"></param> + + Task<GenericBase<String>> GetFromSimpleArgAsync(String id); + + /// <summary> + /// + /// </summary> + /// <param name="id"></param> + /// <returns></returns> + GenericBase<String> GetFromSimpleArg(String id); + + /// <summary> + /// + /// </summary> + /// <param name="dataArg"></param> + + Task<ComplexModel> GetFromComplexArgAsync(ComplexModel dataArg); + + /// <summary> + /// + /// </summary> + /// <param name="dataArg"></param> + /// <returns></returns> + ComplexModel GetFromComplexArg(ComplexModel dataArg); + + /// <summary> + /// + /// </summary> + /// <param name="id"></param> + /// <param name="dataArg"></param> + + Task<NestedModel> GetFromMixedArgAsync(Int32 id,ComplexModel dataArg); + + /// <summary> + /// + /// </summary> + /// <param name="id"></param> + /// <param name="dataArg"></param> + /// <returns></returns> + NestedModel GetFromMixedArg(Int32 id,ComplexModel dataArg); + + /// <summary> + /// + /// </summary> + /// <param name="simpleStr"></param> + /// <param name="uriNestedArg"></param> + /// <param name="bodyComplexArg"></param> + + Task<TotalResult> PostFromMixedArgAsync(String simpleStr,NestedModel uriNestedArg,ComplexModel bodyComplexArg); + + /// <summary> + /// + /// </summary> + /// <param name="simpleStr"></param> + /// <param name="uriNestedArg"></param> + /// <param name="bodyComplexArg"></param> + /// <returns></returns> + TotalResult PostFromMixedArg(String simpleStr,NestedModel uriNestedArg,ComplexModel bodyComplexArg); + + /// <summary> + /// + /// </summary> + /// <param name="simpleStr"></param> + /// <param name="uriComplexArg"></param> + /// <param name="bodyNestedArg"></param> + + Task<TotalResult> PostFromMixedArg2Async(String simpleStr,ComplexModel uriComplexArg,NestedModel bodyNestedArg); + + /// <summary> + /// + /// </summary> + /// <param name="simpleStr"></param> + /// <param name="uriComplexArg"></param> + /// <param name="bodyNestedArg"></param> + /// <returns></returns> + TotalResult PostFromMixedArg2(String simpleStr,ComplexModel uriComplexArg,NestedModel bodyNestedArg); + + } + +} +#endregion + +#region Clients +namespace WebApi.Proxies.One.Clients +{ + /// <summary> + /// Client base class. + /// </summary> + public abstract partial class ClientBase : IDisposable + { + /// <summary> + /// Gests the HttpClient. + /// </summary> + public HttpClient HttpClient { get; protected set; } + + /// <summary> + /// Initializes a new instance of the <see cref="ClientBase"/> class. + /// </summary> + protected ClientBase() + { + HttpClient = new HttpClient() + { + BaseAddress = new Uri(Configuration.DemoOneBaseAddress) + }; + + SerializationSettings = new JsonSerializerSettings + { + NullValueHandling = NullValueHandling.Ignore, + ReferenceLoopHandling = ReferenceLoopHandling.Serialize, + }; + } + + public JsonSerializerSettings SerializationSettings; + + + /// <summary> + /// Ensures that response has a valid (200 - OK) status code + /// </summary> + public virtual void EnsureSuccess(HttpResponseMessage response) + { + if (response.IsSuccessStatusCode) + return; + + throw new WebApiProxyResponseException(response); + } + + protected virtual string GenerateQueryStrFromKvList(List<KeyValuePair<string, object>> 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; + } + + + /// <summary> + /// Initializes a new instance of the <see cref="ClientBase"/> class. + /// </summary> + /// <param name="handler">The handler.</param> + /// <param name="disposeHandler">if set to <c>true</c> [dispose handler].</param> + protected ClientBase(HttpMessageHandler handler, bool disposeHandler = true) + { + HttpClient = new HttpClient(handler, disposeHandler) + { + BaseAddress = new Uri(Configuration.DemoOneBaseAddress) + }; + } + + + /// <summary> + /// Encode the input parameter as a string + /// </summary> + protected string EncodeParam<T>(T value) + { + return System.Net.WebUtility.UrlEncode(value.ToString()); + } + + /// <summary> + /// Encode the input parameter as a string + /// </summary> + protected string EncodeParam(DateTime value) + { + return System.Net.WebUtility.UrlEncode(value.ToString("s")); + } + + /// <summary> + /// Encode the input parameter as a string + /// </summary> + protected string EncodeParam(DateTimeOffset value) + { + return System.Net.WebUtility.UrlEncode(value.ToString("s")); + } + + /// <summary> + /// Releases the unmanaged resources and disposes of the managed resources. + /// </summary> + protected virtual void Dispose(bool disposing) + { + if (disposing && HttpClient != null) + { + HttpClient.Dispose(); + HttpClient = null; + } + } + + /// <summary> + /// Releases the unmanaged resources and disposes of the managed resources. + /// </summary> + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// <summary> + /// Destructor + /// </summary> + ~ClientBase() + { + Dispose(false); + } + } + + /// <summary> + /// Helper class to access all clients at once + /// </summary> + public partial class WebApiClients + { + public TestClient Test { get; private set; } + + protected IEnumerable<Interfaces.IClientBase> 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); + } + } + + /// <summary> + /// + /// </summary> + public partial class TestClient : ClientBase, Interfaces.ITestClient + { + + /// <summary> + /// + /// </summary> + public TestClient() : base() + { + } + + /// <summary> + /// + /// </summary> + public TestClient(HttpMessageHandler handler, bool disposeHandler = true) : base(handler, disposeHandler) + { + } + + #region Methods + + + + + /// <summary> + /// + /// </summary> + /// <param name="id"></param> + /// <returns></returns> + public virtual async Task<GenericBase<String>> 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<GenericBase<String>>(); + } + + + + + /// <summary> + /// + /// </summary> + /// <param name="id"></param> + public virtual GenericBase<String> GetFromSimpleArg(String id) + { + + return GetFromSimpleArgAsync(id).Result; + + } + + + + + /// <summary> + /// + /// </summary> + /// <param name="dataArg"></param> + /// <returns></returns> + public virtual async Task<ComplexModel> 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<ComplexModel>(); + } + + + + protected virtual string GenerateGetFromComplexArgQueryString(ComplexModel dataArg) + { + var kvList = GenerateGetFromComplexArgKeyValueList( dataArg ); + var urlTpl = GenerateQueryStrFromKvList(kvList); + + return urlTpl; + } + + protected virtual List<KeyValuePair<string, object>> GenerateGetFromComplexArgKeyValueList(ComplexModel dataArg) + { + // Name={Name}&Age={Age} + throw new NotImplementedException(); + } + + + + /// <summary> + /// + /// </summary> + /// <param name="dataArg"></param> + public virtual ComplexModel GetFromComplexArg(ComplexModel dataArg) + { + + return GetFromComplexArgAsync(dataArg).Result; + + } + + + + + /// <summary> + /// + /// </summary> + /// <param name="id"></param> + /// <param name="dataArg"></param> + /// <returns></returns> + public virtual async Task<NestedModel> 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<NestedModel>(); + } + + + + protected virtual string GenerateGetFromMixedArgQueryString(Int32 id,ComplexModel dataArg) + { + var kvList = GenerateGetFromMixedArgKeyValueList( id, dataArg ); + var urlTpl = GenerateQueryStrFromKvList(kvList); + + return urlTpl; + } + + protected virtual List<KeyValuePair<string, object>> GenerateGetFromMixedArgKeyValueList(Int32 id,ComplexModel dataArg) + { + // Name={Name}&Age={Age} + throw new NotImplementedException(); + } + + + + /// <summary> + /// + /// </summary> + /// <param name="id"></param> + /// <param name="dataArg"></param> + public virtual NestedModel GetFromMixedArg(Int32 id,ComplexModel dataArg) + { + + return GetFromMixedArgAsync(id, dataArg).Result; + + } + + + + + /// <summary> + /// + /// </summary> + /// <param name="simpleStr"></param> + /// <param name="uriNestedArg"></param> + /// <param name="bodyComplexArg"></param> + /// <returns></returns> + public virtual async Task<TotalResult> 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<ComplexModel>(requestUrl , bodyComplexArg); + + + EnsureSuccess(result); + + return await result.Content.ReadAsAsync<TotalResult>(); + } + + + + + /// <summary> + /// + /// </summary> + /// <param name="simpleStr"></param> + /// <param name="uriNestedArg"></param> + /// <param name="bodyComplexArg"></param> + public virtual TotalResult PostFromMixedArg(String simpleStr,NestedModel uriNestedArg,ComplexModel bodyComplexArg) + { + + return PostFromMixedArgAsync(simpleStr, uriNestedArg, bodyComplexArg).Result; + + } + + + + + /// <summary> + /// + /// </summary> + /// <param name="simpleStr"></param> + /// <param name="uriComplexArg"></param> + /// <param name="bodyNestedArg"></param> + /// <returns></returns> + public virtual async Task<TotalResult> 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<NestedModel>(requestUrl , bodyNestedArg); + + + EnsureSuccess(result); + + return await result.Content.ReadAsAsync<TotalResult>(); + } + + + + 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<KeyValuePair<string, object>> GeneratePostFromMixedArg2KeyValueList(String simpleStr,ComplexModel uriComplexArg,NestedModel bodyNestedArg) + { + // Name={Name}&Age={Age} + throw new NotImplementedException(); + } + + + + /// <summary> + /// + /// </summary> + /// <param name="simpleStr"></param> + /// <param name="uriComplexArg"></param> + /// <param name="bodyNestedArg"></param> + 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 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!-- See http://github.com/faniereynders/webapiproxy for documentation on using this configuration file --> + +<proxy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="http://webapiproxy.github.io/schemas/client-config.xsd" + + endpoint="http://localhost:8888/api/proxies" + generateOnBuild="true" + namespace="WebApi.Proxies.One" + name="DemoOne" + generateAsyncReturnTypes="true" +/> 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" /> + <package id="Newtonsoft.Json" version="8.0.3" targetFramework="net452" /> + <package id="WebApiProxy.CSharp" version="1.0.6011.40179" targetFramework="net452" /> +</packages> \ 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 @@ +<?xml version="1.0" encoding="utf-8" ?> +<configuration> + <startup> + <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> + </startup> +</configuration> \ 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<Startup>(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 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{113C2E62-F473-4B44-AC7C-002096B17E49}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>Server</RootNamespace> + <AssemblyName>Server</AssemblyName> + <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="DocsByReflection, Version=1.0.8.0, Culture=neutral, PublicKeyToken=64d1e8338525e7be, processorArchitecture=MSIL"> + <HintPath>..\packages\DocsByReflection.1.0.11\lib\net40\DocsByReflection.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="HelperSharp, Version=1.0.5560.27038, Culture=neutral, PublicKeyToken=3d44152485e1a4e1, processorArchitecture=MSIL"> + <HintPath>..\packages\HelperSharp.0.0.4.2\lib\net35\HelperSharp.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="Microsoft.Owin, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> + <HintPath>..\packages\Microsoft.Owin.2.0.2\lib\net45\Microsoft.Owin.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="Microsoft.Owin.Host.HttpListener, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> + <HintPath>..\packages\Microsoft.Owin.Host.HttpListener.2.0.2\lib\net45\Microsoft.Owin.Host.HttpListener.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="Microsoft.Owin.Hosting, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> + <HintPath>..\packages\Microsoft.Owin.Hosting.2.0.2\lib\net45\Microsoft.Owin.Hosting.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> + <HintPath>..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL"> + <HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="System" /> + <Reference Include="System.Core" /> + <Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> + <HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> + <HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="System.Web.Http.Owin, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> + <HintPath>..\packages\Microsoft.AspNet.WebApi.Owin.5.2.3\lib\net45\System.Web.Http.Owin.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="System.Xml.Linq" /> + <Reference Include="System.Data.DataSetExtensions" /> + <Reference Include="Microsoft.CSharp" /> + <Reference Include="System.Data" /> + <Reference Include="System.Net.Http" /> + <Reference Include="System.Xml" /> + <Reference Include="WebApiProxy.Core, Version=1.3.6011.17722, Culture=neutral, processorArchitecture=MSIL"> + <HintPath>..\packages\WebApiProxy.1.3.6011.17725\lib\net45\WebApiProxy.Core.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="WebApiProxy.Server, Version=1.3.6011.17725, Culture=neutral, processorArchitecture=MSIL"> + <HintPath>..\packages\WebApiProxy.1.3.6011.17725\lib\net45\WebApiProxy.Server.dll</HintPath> + <Private>True</Private> + </Reference> + </ItemGroup> + <ItemGroup> + <Compile Include="Program.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="TestController.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="App.config" /> + <None Include="packages.config" /> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> +</Project> \ No newline at end of file diff --git a/src/Default/FooController.cs b/src/Server/TestController.cs similarity index 99% rename from src/Default/FooController.cs rename to src/Server/TestController.cs index 389eb06..6edcc80 100644 --- a/src/Default/FooController.cs +++ b/src/Server/TestController.cs @@ -1,7 +1,7 @@ using System.Web.Http; using System.Web.Http.Description; -namespace Default +namespace Server { [RoutePrefix("api/test")] public class TestController : ApiController 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="DocsByReflection" version="1.0.11" targetFramework="net452" /> + <package id="HelperSharp" version="0.0.4.2" targetFramework="net452" /> + <package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" /> + <package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net452" /> + <package id="Microsoft.AspNet.WebApi.Owin" version="5.2.3" targetFramework="net452" /> + <package id="Microsoft.AspNet.WebApi.OwinSelfHost" version="5.2.3" targetFramework="net452" /> + <package id="Microsoft.Owin" version="2.0.2" targetFramework="net452" /> + <package id="Microsoft.Owin.Host.HttpListener" version="2.0.2" targetFramework="net452" /> + <package id="Microsoft.Owin.Hosting" version="2.0.2" targetFramework="net452" /> + <package id="Newtonsoft.Json" version="6.0.4" targetFramework="net452" /> + <package id="Owin" version="1.0" targetFramework="net452" /> + <package id="WebApiProxy" version="1.3.6011.17725" targetFramework="net452" /> +</packages> \ No newline at end of file