Permalink
Browse files

add wcf and cleanups

  • Loading branch information...
1 parent d9ed3c6 commit 686f2d3dad35a58374f2bd94a427d53b72e79e9a @ScottWeinstein committed Apr 20, 2012
Showing with 806 additions and 53 deletions.
  1. +34 −4 ContainerBased/ContainerBased.csproj
  2. +29 −7 ContainerBased/Global.asax.cs
  3. +1 −0 ContainerBased/Models/AdvancedModel.cs
  4. +1 −2 ContainerBased/Models/LifetimeManagementModel.cs
  5. +6 −1 ContainerBased/Models/MyModel.cs
  6. +4 −0 ContainerBased/Service References/DataService/DataService.disco
  7. +38 −0 ContainerBased/Service References/DataService/DataService.wsdl
  8. +17 −0 ContainerBased/Service References/DataService/DataService.xsd
  9. +42 −0 ContainerBased/Service References/DataService/DataService1.xsd
  10. +53 −0 ContainerBased/Service References/DataService/Reference.cs
  11. +33 −0 ContainerBased/Service References/DataService/Reference.svcmap
  12. +10 −0 ContainerBased/Service References/DataService/configuration.svcinfo
  13. +201 −0 ContainerBased/Service References/DataService/configuration91.svcinfo
  14. +25 −0 ContainerBased/Web.config
  15. +1 −0 ContainerBased/packages.config
  16. +10 −0 Demos.sln
  17. +1 −3 NonContainerBased/Controllers/HomeController.cs
  18. +1 −0 NonContainerBased/Models/MyModel.cs
  19. +3 −4 NonContainerBased/NonContainerBased.csproj
  20. +5 −5 README.md
  21. +1 −1 UnitTestingWithIoC/TestSetup.cs
  22. +13 −0 WcfService/DataDbImplementer.cs
  23. +4 −0 WcfService/DataService.svc
  24. +19 −0 WcfService/DataService.svc.cs
  25. +1 −0 WcfService/Global.asax
  26. +21 −0 WcfService/Global.asax.cs
  27. +10 −0 WcfService/IDataDb.cs
  28. +14 −0 WcfService/IDataService.cs
  29. +36 −0 WcfService/Properties/AssemblyInfo.cs
  30. +125 −0 WcfService/WcfService.csproj
  31. +7 −0 WcfService/Web.Debug.config
  32. +11 −0 WcfService/Web.Release.config
  33. +24 −0 WcfService/Web.config
  34. +5 −0 WcfService/packages.config
  35. +0 −26 build.ps1
@@ -14,7 +14,7 @@
<AssemblyName>ContainerBased</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<MvcBuildViews>false</MvcBuildViews>
- <UseIISExpress>false</UseIISExpress>
+ <UseIISExpress>true</UseIISExpress>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
@@ -47,10 +47,14 @@
<Reference Include="Autofac.Integration.Mvc">
<HintPath>..\packages\Autofac.Mvc3.2.6.1.841\lib\NET40\Autofac.Integration.Mvc.dll</HintPath>
</Reference>
+ <Reference Include="Autofac.Integration.Wcf">
+ <HintPath>..\packages\Autofac.Wcf.2.6.1.841\lib\NET40\Autofac.Integration.Wcf.dll</HintPath>
+ </Reference>
<Reference Include="System.Data.Entity" />
<Reference Include="System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Security" />
+ <Reference Include="System.ServiceModel" />
<Reference Include="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System.Web.WebPages" />
<Reference Include="System.Web.Helpers" />
@@ -87,10 +91,22 @@
</Compile>
<Compile Include="Models\LifetimeManagementModel.cs" />
<Compile Include="Models\MyModel.cs" />
+ <Compile Include="Service References\DataService\Reference.cs">
+ <AutoGen>True</AutoGen>
+ <DesignTime>True</DesignTime>
+ <DependentUpon>Reference.svcmap</DependentUpon>
+ </Compile>
</ItemGroup>
<ItemGroup>
<Content Include="App_Data\DB.sdf" />
<Content Include="Global.asax" />
+ <None Include="Service References\DataService\DataService.disco" />
+ <None Include="Service References\DataService\configuration91.svcinfo" />
+ <None Include="Service References\DataService\configuration.svcinfo" />
+ <None Include="Service References\DataService\Reference.svcmap">
+ <Generator>WCF Proxy Generator</Generator>
+ <LastGenOutput>Reference.cs</LastGenOutput>
+ </None>
<Content Include="Web.config" />
<Content Include="Views\Web.config" />
<Content Include="Views\_ViewStart.cshtml" />
@@ -111,6 +127,21 @@
<ItemGroup>
<Content Include="packages.config" />
</ItemGroup>
+ <ItemGroup>
+ <WCFMetadata Include="Service References\" />
+ </ItemGroup>
+ <ItemGroup>
+ <WCFMetadataStorage Include="Service References\DataService\" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Service References\DataService\DataService.wsdl" />
+ <None Include="Service References\DataService\DataService.xsd">
+ <SubType>Designer</SubType>
+ </None>
+ <None Include="Service References\DataService\DataService1.xsd">
+ <SubType>Designer</SubType>
+ </None>
+ </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
@@ -126,12 +157,11 @@
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
- <UseIIS>False</UseIIS>
+ <UseIIS>True</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>65269</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
- <IISUrl>
- </IISUrl>
+ <IISUrl>http://localhost:65269/</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
@@ -1,14 +1,15 @@
using System;
using System.Configuration;
using System.Linq;
-using System.Reflection;
using System.Runtime.InteropServices;
-using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Autofac;
using Autofac.Integration.Mvc;
+using Autofac.Integration.Wcf;
using ContainerBased.Models;
+using System.ServiceModel;
+using ContainerBased.DataService;
[assembly: ComVisible(false)]
namespace ContainerBased
@@ -17,24 +18,45 @@ public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
- var container = BuildAutofac(false).Build();
- DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
+ var builder = ConfigureAutofac(isTest: false);
+ var container = builder.Build();
+
+
+ // Wire Autofac into ASP.NET MVC
+ DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
+
+
+
+
+
+ // Std MVC stuff
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
- public ContainerBuilder BuildAutofac(bool isTest)
+ public ContainerBuilder ConfigureAutofac(bool isTest)
{
var thisAppAssembly = typeof(MvcApplication).Assembly;
var builder = new ContainerBuilder();
- builder.RegisterAssemblyTypes(thisAppAssembly);
- builder.RegisterControllers(thisAppAssembly);
+
+ builder.RegisterAssemblyTypes(thisAppAssembly); // All classes are wired up for instance scope
+ builder.RegisterControllers(thisAppAssembly); // wire up all controller classes to be HTTPRequestScoped
// provide a factory method for creating new DBEntities
builder.Register<DBEntities>(ctx => new DBEntities(ConfigurationManager.ConnectionStrings["DBEntities"].ConnectionString));
+
+ // config WCF service
+
+ builder.Register(c => new ChannelFactory<IDataService>(new BasicHttpBinding(),
+ new EndpointAddress("http://localhost:47758/DataService.svc")))
+ .SingleInstance();
+
+ builder.Register(c => c.Resolve<ChannelFactory<IDataService>>().CreateChannel())
+ .UseWcfSafeRelease();
+
return builder;
}
@@ -15,6 +15,7 @@ public AdvancedModel(Func<DBEntities> dbFactory, Func<Owned<DBEntities>> ownedFa
_dbFactory = dbFactory;
_ownedFactory = ownedFactory;
_moreAdv = moreAdv;
+ // What do you think the difference is between Lazy<DBEntities> and Func<DBEntities>?
}
public void Proccess()
@@ -19,8 +19,7 @@ public void Proccess()
{
using (var localscope = _scope.BeginLifetimeScope())
{
- var db = localscope.Resolve<DBEntities>();
- // var q = localscope.Resolve<T>();
+ var db = localscope.Resolve<DBEntities>(); // will get cleaned up at the end of the using block
}
});
}
@@ -1,13 +1,18 @@
using System;
+using ContainerBased.DataService;
namespace ContainerBased.Models
{
public class MyModel
{
private readonly DBEntities _db;
+ private readonly IDataService _ds;
- public MyModel(DBEntities db, AdvancedModel am)
+ public MyModel(DBEntities db, AdvancedModel am, IDataService ds)
{
_db = db;
+ _ds = ds;
+
+ var res = _ds.GetData(1);
}
}
}
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<discovery xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/disco/">
+ <contractRef ref="http://localhost:47758/DataService.svc?wsdl" docRef="http://localhost:47758/DataService.svc" xmlns="http://schemas.xmlsoap.org/disco/scl/" />
+</discovery>
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<wsdl:definitions xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:tns="http://tempuri.org/" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="DataService" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
+ <wsdl:types>
+ <xsd:schema targetNamespace="http://tempuri.org/Imports">
+ <xsd:import schemaLocation="http://localhost:47758/DataService.svc?xsd=xsd0" namespace="http://tempuri.org/" />
+ <xsd:import schemaLocation="http://localhost:47758/DataService.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
+ </xsd:schema>
+ </wsdl:types>
+ <wsdl:message name="IDataService_GetData_InputMessage">
+ <wsdl:part name="parameters" element="tns:GetData" />
+ </wsdl:message>
+ <wsdl:message name="IDataService_GetData_OutputMessage">
+ <wsdl:part name="parameters" element="tns:GetDataResponse" />
+ </wsdl:message>
+ <wsdl:portType name="IDataService">
+ <wsdl:operation name="GetData">
+ <wsdl:input wsaw:Action="http://tempuri.org/IDataService/GetData" message="tns:IDataService_GetData_InputMessage" />
+ <wsdl:output wsaw:Action="http://tempuri.org/IDataService/GetDataResponse" message="tns:IDataService_GetData_OutputMessage" />
+ </wsdl:operation>
+ </wsdl:portType>
+ <wsdl:binding name="BasicHttpBinding_IDataService" type="tns:IDataService">
+ <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
+ <wsdl:operation name="GetData">
+ <soap:operation soapAction="http://tempuri.org/IDataService/GetData" style="document" />
+ <wsdl:input>
+ <soap:body use="literal" />
+ </wsdl:input>
+ <wsdl:output>
+ <soap:body use="literal" />
+ </wsdl:output>
+ </wsdl:operation>
+ </wsdl:binding>
+ <wsdl:service name="DataService">
+ <wsdl:port name="BasicHttpBinding_IDataService" binding="tns:BasicHttpBinding_IDataService">
+ <soap:address location="http://localhost:47758/DataService.svc" />
+ </wsdl:port>
+ </wsdl:service>
+</wsdl:definitions>
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xs:schema xmlns:tns="http://tempuri.org/" elementFormDefault="qualified" targetNamespace="http://tempuri.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
+ <xs:element name="GetData">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element minOccurs="0" name="value" type="xs:int" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="GetDataResponse">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element minOccurs="0" name="GetDataResult" nillable="true" type="xs:string" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+</xs:schema>
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xs:schema xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
+ <xs:element name="anyType" nillable="true" type="xs:anyType" />
+ <xs:element name="anyURI" nillable="true" type="xs:anyURI" />
+ <xs:element name="base64Binary" nillable="true" type="xs:base64Binary" />
+ <xs:element name="boolean" nillable="true" type="xs:boolean" />
+ <xs:element name="byte" nillable="true" type="xs:byte" />
+ <xs:element name="dateTime" nillable="true" type="xs:dateTime" />
+ <xs:element name="decimal" nillable="true" type="xs:decimal" />
+ <xs:element name="double" nillable="true" type="xs:double" />
+ <xs:element name="float" nillable="true" type="xs:float" />
+ <xs:element name="int" nillable="true" type="xs:int" />
+ <xs:element name="long" nillable="true" type="xs:long" />
+ <xs:element name="QName" nillable="true" type="xs:QName" />
+ <xs:element name="short" nillable="true" type="xs:short" />
+ <xs:element name="string" nillable="true" type="xs:string" />
+ <xs:element name="unsignedByte" nillable="true" type="xs:unsignedByte" />
+ <xs:element name="unsignedInt" nillable="true" type="xs:unsignedInt" />
+ <xs:element name="unsignedLong" nillable="true" type="xs:unsignedLong" />
+ <xs:element name="unsignedShort" nillable="true" type="xs:unsignedShort" />
+ <xs:element name="char" nillable="true" type="tns:char" />
+ <xs:simpleType name="char">
+ <xs:restriction base="xs:int" />
+ </xs:simpleType>
+ <xs:element name="duration" nillable="true" type="tns:duration" />
+ <xs:simpleType name="duration">
+ <xs:restriction base="xs:duration">
+ <xs:pattern value="\-?P(\d*D)?(T(\d*H)?(\d*M)?(\d*(\.\d*)?S)?)?" />
+ <xs:minInclusive value="-P10675199DT2H48M5.4775808S" />
+ <xs:maxInclusive value="P10675199DT2H48M5.4775807S" />
+ </xs:restriction>
+ </xs:simpleType>
+ <xs:element name="guid" nillable="true" type="tns:guid" />
+ <xs:simpleType name="guid">
+ <xs:restriction base="xs:string">
+ <xs:pattern value="[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}" />
+ </xs:restriction>
+ </xs:simpleType>
+ <xs:attribute name="FactoryType" type="xs:QName" />
+ <xs:attribute name="Id" type="xs:ID" />
+ <xs:attribute name="Ref" type="xs:IDREF" />
+</xs:schema>
@@ -0,0 +1,53 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.261
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace ContainerBased.DataService {
+
+
+ [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
+ [System.ServiceModel.ServiceContractAttribute(ConfigurationName="DataService.IDataService")]
+ public interface IDataService {
+
+ [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IDataService/GetData", ReplyAction="http://tempuri.org/IDataService/GetDataResponse")]
+ string GetData(int value);
+ }
+
+ [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
+ public interface IDataServiceChannel : ContainerBased.DataService.IDataService, System.ServiceModel.IClientChannel {
+ }
+
+ [System.Diagnostics.DebuggerStepThroughAttribute()]
+ [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
+ public partial class DataServiceClient : System.ServiceModel.ClientBase<ContainerBased.DataService.IDataService>, ContainerBased.DataService.IDataService {
+
+ public DataServiceClient() {
+ }
+
+ public DataServiceClient(string endpointConfigurationName) :
+ base(endpointConfigurationName) {
+ }
+
+ public DataServiceClient(string endpointConfigurationName, string remoteAddress) :
+ base(endpointConfigurationName, remoteAddress) {
+ }
+
+ public DataServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
+ base(endpointConfigurationName, remoteAddress) {
+ }
+
+ public DataServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
+ base(binding, remoteAddress) {
+ }
+
+ public string GetData(int value) {
+ return base.Channel.GetData(value);
+ }
+ }
+}
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ReferenceGroup xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ID="d7ec72f7-b938-49fa-89e1-4f8100ca7566" xmlns="urn:schemas-microsoft-com:xml-wcfservicemap">
+ <ClientOptions>
+ <GenerateAsynchronousMethods>false</GenerateAsynchronousMethods>
+ <EnableDataBinding>true</EnableDataBinding>
+ <ExcludedTypes />
+ <ImportXmlTypes>false</ImportXmlTypes>
+ <GenerateInternalTypes>false</GenerateInternalTypes>
+ <GenerateMessageContracts>false</GenerateMessageContracts>
+ <NamespaceMappings />
+ <CollectionMappings />
+ <GenerateSerializableTypes>true</GenerateSerializableTypes>
+ <Serializer>Auto</Serializer>
+ <UseSerializerForFaults>true</UseSerializerForFaults>
+ <ReferenceAllAssemblies>true</ReferenceAllAssemblies>
+ <ReferencedAssemblies />
+ <ReferencedDataContractTypes />
+ <ServiceContractMappings />
+ </ClientOptions>
+ <MetadataSources>
+ <MetadataSource Address="http://localhost:47758/DataService.svc" Protocol="http" SourceId="1" />
+ </MetadataSources>
+ <Metadata>
+ <MetadataFile FileName="DataService.xsd" MetadataType="Schema" ID="6a060e5d-d2c8-4728-b979-88c0b0e2cef6" SourceId="1" SourceUrl="http://localhost:47758/DataService.svc?xsd=xsd0" />
+ <MetadataFile FileName="DataService.wsdl" MetadataType="Wsdl" ID="ac13e7dc-d141-46fb-843a-8c2d61cbfbc9" SourceId="1" SourceUrl="http://localhost:47758/DataService.svc?wsdl" />
+ <MetadataFile FileName="DataService1.xsd" MetadataType="Schema" ID="73be186f-4aac-443c-80de-e282e96849eb" SourceId="1" SourceUrl="http://localhost:47758/DataService.svc?xsd=xsd1" />
+ <MetadataFile FileName="DataService.disco" MetadataType="Disco" ID="172e6e56-0905-4617-9cc9-8fc0a5117b1d" SourceId="1" SourceUrl="http://localhost:47758/DataService.svc?disco" />
+ </Metadata>
+ <Extensions>
+ <ExtensionFile FileName="configuration91.svcinfo" Name="configuration91.svcinfo" />
+ <ExtensionFile FileName="configuration.svcinfo" Name="configuration.svcinfo" />
+ </Extensions>
+</ReferenceGroup>
Oops, something went wrong.

0 comments on commit 686f2d3

Please sign in to comment.