From 2f9f5db72d5a43173d0fda0137180f4d205800da Mon Sep 17 00:00:00 2001 From: ENikS Date: Sun, 20 Jan 2019 15:46:20 -0500 Subject: [PATCH] Added WCF example --- .../Wcf.Service.Unity.Example/IService1.cs | 47 +++++++ .../Properties/AssemblyInfo.cs | 36 ++++++ .../Wcf.Service.Unity.Example/Service1.svc | 1 + .../Wcf.Service.Unity.Example/Service1.svc.cs | 33 +++++ .../Wcf.Service.Unity.Example.csproj | 117 ++++++++++++++++++ .../Web.Debug.config | 30 +++++ .../Web.Release.config | 31 +++++ src/Wcf/Wcf.Service.Unity.Example/Web.config | 36 ++++++ .../Controllers/HomeController.cs | 15 ++- 9 files changed, 340 insertions(+), 6 deletions(-) create mode 100644 src/Wcf/Wcf.Service.Unity.Example/IService1.cs create mode 100644 src/Wcf/Wcf.Service.Unity.Example/Properties/AssemblyInfo.cs create mode 100644 src/Wcf/Wcf.Service.Unity.Example/Service1.svc create mode 100644 src/Wcf/Wcf.Service.Unity.Example/Service1.svc.cs create mode 100644 src/Wcf/Wcf.Service.Unity.Example/Wcf.Service.Unity.Example.csproj create mode 100644 src/Wcf/Wcf.Service.Unity.Example/Web.Debug.config create mode 100644 src/Wcf/Wcf.Service.Unity.Example/Web.Release.config create mode 100644 src/Wcf/Wcf.Service.Unity.Example/Web.config diff --git a/src/Wcf/Wcf.Service.Unity.Example/IService1.cs b/src/Wcf/Wcf.Service.Unity.Example/IService1.cs new file mode 100644 index 0000000..10fbb40 --- /dev/null +++ b/src/Wcf/Wcf.Service.Unity.Example/IService1.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.ServiceModel; +using System.ServiceModel.Web; +using System.Text; + +namespace WcfUnityService +{ + // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together. + [ServiceContract] + public interface IService1 + { + + [OperationContract] + string GetData(int value); + + [OperationContract] + CompositeType GetDataUsingDataContract(CompositeType composite); + + // TODO: Add your service operations here + } + + + // Use a data contract as illustrated in the sample below to add composite types to service operations. + [DataContract] + public class CompositeType + { + bool boolValue = true; + string stringValue = "Hello "; + + [DataMember] + public bool BoolValue + { + get { return boolValue; } + set { boolValue = value; } + } + + [DataMember] + public string StringValue + { + get { return stringValue; } + set { stringValue = value; } + } + } +} diff --git a/src/Wcf/Wcf.Service.Unity.Example/Properties/AssemblyInfo.cs b/src/Wcf/Wcf.Service.Unity.Example/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..d653495 --- /dev/null +++ b/src/Wcf/Wcf.Service.Unity.Example/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("WcfUnityService")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("WcfUnityService")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("a4a256a5-ad8f-4d6f-8720-d9798d0aaa66")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Wcf/Wcf.Service.Unity.Example/Service1.svc b/src/Wcf/Wcf.Service.Unity.Example/Service1.svc new file mode 100644 index 0000000..5c06685 --- /dev/null +++ b/src/Wcf/Wcf.Service.Unity.Example/Service1.svc @@ -0,0 +1 @@ +<%@ ServiceHost Language="C#" Debug="true" Service="WcfUnityService.Service1" CodeBehind="Service1.svc.cs" %> \ No newline at end of file diff --git a/src/Wcf/Wcf.Service.Unity.Example/Service1.svc.cs b/src/Wcf/Wcf.Service.Unity.Example/Service1.svc.cs new file mode 100644 index 0000000..ee62cac --- /dev/null +++ b/src/Wcf/Wcf.Service.Unity.Example/Service1.svc.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.ServiceModel; +using System.ServiceModel.Web; +using System.Text; + +namespace WcfUnityService +{ + // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together. + // NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging. + public class Service1 : IService1 + { + public string GetData(int value) + { + return string.Format("You entered: {0}", value); + } + + public CompositeType GetDataUsingDataContract(CompositeType composite) + { + if (composite == null) + { + throw new ArgumentNullException("composite"); + } + if (composite.BoolValue) + { + composite.StringValue += "Suffix"; + } + return composite; + } + } +} diff --git a/src/Wcf/Wcf.Service.Unity.Example/Wcf.Service.Unity.Example.csproj b/src/Wcf/Wcf.Service.Unity.Example/Wcf.Service.Unity.Example.csproj new file mode 100644 index 0000000..2630f5d --- /dev/null +++ b/src/Wcf/Wcf.Service.Unity.Example/Wcf.Service.Unity.Example.csproj @@ -0,0 +1,117 @@ + + + + Debug + AnyCPU + + + 2.0 + {A4A256A5-AD8F-4D6F-8720-D9798D0AAA66} + {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + WcfUnityService + WcfUnityService + v4.7.2 + True + true + true + + + + + + + + + true + full + false + bin\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + Service1.svc + + + + + + + + + + Web.config + + + Web.config + + + + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + + + + + True + True + 49916 + / + http://localhost:49916/ + False + False + + + False + + + + + + \ No newline at end of file diff --git a/src/Wcf/Wcf.Service.Unity.Example/Web.Debug.config b/src/Wcf/Wcf.Service.Unity.Example/Web.Debug.config new file mode 100644 index 0000000..fae9cfe --- /dev/null +++ b/src/Wcf/Wcf.Service.Unity.Example/Web.Debug.config @@ -0,0 +1,30 @@ + + + + + + + + + + \ No newline at end of file diff --git a/src/Wcf/Wcf.Service.Unity.Example/Web.Release.config b/src/Wcf/Wcf.Service.Unity.Example/Web.Release.config new file mode 100644 index 0000000..da6e960 --- /dev/null +++ b/src/Wcf/Wcf.Service.Unity.Example/Web.Release.config @@ -0,0 +1,31 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/Wcf/Wcf.Service.Unity.Example/Web.config b/src/Wcf/Wcf.Service.Unity.Example/Web.config new file mode 100644 index 0000000..a01d6db --- /dev/null +++ b/src/Wcf/Wcf.Service.Unity.Example/Web.config @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/web/ASP.Net.Unity.Example/Controllers/HomeController.cs b/src/web/ASP.Net.Unity.Example/Controllers/HomeController.cs index 674e644..f2073e6 100644 --- a/src/web/ASP.Net.Unity.Example/Controllers/HomeController.cs +++ b/src/web/ASP.Net.Unity.Example/Controllers/HomeController.cs @@ -1,15 +1,18 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Threading.Tasks; +using ASP.Net.Unity.Example.Models; using Microsoft.AspNetCore.Mvc; -using ASP.Net.Unity.Example.Models; +using System.Diagnostics; +using Unity; namespace ASP.Net.Unity.Example.Controllers { public class HomeController : Controller { + public HomeController(IUnityContainer container) + { + // Verify controller was created by Unity container + Debug.Assert(null != container); + } + public IActionResult Index() { return View();