none
looking for file less as well as configuration less WCF service - IIS host RRS feed

  • Question

  • Hello,

    I am trying to do file less as well as config less IIS hosting for a WCF service. I wrote a Factory class and invoke through config setting in web.config file like below,

    <system.serviceModel>
        <serviceHostingEnvironment>
          <serviceActivations>
            <add factory="HelloServiceCustomHost" relativeAddress="./HelloService.svc" service="HelloService" />
          </serviceActivations>
        </serviceHostingEnvironment>
      </system.serviceModel>

    public class HelloServiceCustomHost: ServiceHostFactoryBase
        {
            public override ServiceHostBase CreateServiceHost(string constructorString, Uri[] baseAddresses)
            {
                ServiceHost shost = new ServiceHost(typeof(HelloService), baseAddresses);
                ServiceMetadataBehavior smb = shost.Description.Behaviors.Find<ServiceMetadataBehavior>();
                if (smb == null)
                    smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                shost.Description.Behaviors.Add(smb);
                shost.AddServiceEndpoint(typeof(IHelloService), new BasicHttpBinding(), "");
                return shost;
            }
        }

    The thing is that still I need to use configuration file where I m defining factory and service base address.

    Question - Is there any chance to do above configuration settings grammatically, zero configuration?

    Thanks!

    Tuesday, March 25, 2014 4:39 PM

All replies

  • Wednesday, March 26, 2014 9:21 AM
  • thanks for reply.

    in above link without configuration is OK, but they assign Factory in service file (.svc).

    i'm looking file less (not svc) and configuration less.

    thanks!

    Wednesday, March 26, 2014 4:42 PM
  • using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    using System.Web.UI.DataVisualization.Charting;
    using System.Drawing;
    using System.Web.UI.DataVisualization;

    namespace PieChart
    {
        public partial class Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                // Populate series data
                double[] yValues = { 71.15, 23.19, 5.66 };
                string[] xValues = { "AAA", "BBB", "CCC" };
                Chart1.Series["Default"].Points.DataBindXY(xValues, yValues);

                //Set the colors of the Pie chart
                //Chart1.Series["Default"].Points[0].Color = Color.CornflowerBlue;
                //Chart1.Series["Default"].Points[1].Color = Color.LightSkyBlue;
                //Chart1.Series["Default"].Points[2].Color = Color.OldLace;

                Chart1.Series["Default"].Points[0].Color = Color.MediumSeaGreen;
                Chart1.Series["Default"].Points[1].Color = Color.PaleGreen;
                Chart1.Series["Default"].Points[2].Color = Color.LawnGreen;

                //Set Pie chart type
                Chart1.Series["Default"].ChartType = SeriesChartType.Pie;

                //Set labels style (Inside, Outside, Disabled)
                Chart1.Series["Default"]["PieLabelStyle"] = "Disabled";

                //Set chart title, color and font
                //Chart1.Titles[0].Text = "Pie Chart Title";
                Chart1.Titles[0].ForeColor = Color.DarkBlue;
                Chart1.Titles[0].ShadowColor = Color.LightGray;
                Chart1.Titles[0].Font = new Font("Arial Black", 14, FontStyle.Bold);

                //Enable 3D
                Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;

                //Default, SoftEdge, Concave (not enabled if 3D)
                Chart1.Series[0]["PieDrawingStyle"] = "SoftEdge";

                // Disable/Enable the Legend
                Chart1.Legends[0].Enabled = true;
            }
        }
    }
    Sunday, April 27, 2014 8:37 AM
  • <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="PieChart.Default" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <asp:Table ID="table1" runat="server">
            <asp:TableRow>
                <asp:TableCell>
                    <asp:chart id="Chart1" runat="server" Height="300px" Width="400px">
    <titles>
    <asp:Title ShadowOffset="3" Name="Title1" />
    </titles>
    <legends>
    <asp:Legend Alignment="Center" Docking="Bottom" IsTextAutoFit="False" Name="Default" LegendStyle="Row" />
    </legends>
    <series>
    <asp:Series Name="Default" />
    </series>
    <chartareas>
    <asp:ChartArea Name="ChartArea1" BorderWidth="0" />
    </chartareas>
    </asp:chart> 
                </asp:TableCell>
            </asp:TableRow>
        </asp:Table>
        </div>
        </form>
    </body>
    </html>
    Sunday, April 27, 2014 8:37 AM
  • [HttpGet]
            public ActionResult GetChart()
            {
                List<Inq> enquiries = new List<Inq>();
                enquiries.Add(new Inq() { Date = DateTime.Now, Count = 8 });
                var data = from p in enquiries
                           group p by p.Date.Date into g
                           select new { Date = g.Key, Count = g.Count() };

                Response.Clear();
                Response.ContentType = "image/png";
                ChartLoader.SaveChartImage(
                            "LastEnquiriesChart.ascx",
                            data,
                            Response.OutputStream);
                Response.End();

                return null; // have to return something
            }

     public class Inq
        {
            public DateTime Date { get; set; }
            public int Count { get; set; }
        }

     public static class ChartLoader
        {
            public static void SaveChartImage(string controlLocation, IEnumerable data, Stream stream)
            {
                using (var page = new Page())
                using (var control = (IReportControl)
                       page.LoadControl("~/Reports/" + controlLocation))
                {
                    control.DataSource = data;
                    control.DataBind();
                    control.SaveChartImage(stream);
                }
            }
        }

        public interface IReportControl : IDisposable
        {
            void DataBind();
            object DataSource { set; }
            void SaveChartImage(Stream stream);
        }

    Sunday, April 27, 2014 8:39 AM
  • public partial class LastEnquiriesChart : System.Web.UI.UserControl, IReportControl
        {
            public object DataSource
            {
                set
                {
                    Chart1.DataSource = value;
                }
            }

            public override void DataBind()
            {
                base.DataBind();
                Chart1.DataBind();
            }

            public void SaveChartImage(Stream stream)
            {
                Chart1.SaveImage(stream);
            }
        }

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="LastEnquiriesChart.ascx.cs"
        Inherits="ReportingApp.Web.Reports.LastEnquiriesChart" %>
    <%@ Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>
    <asp:Chart ID="Chart1" runat="server" Palette="Excel" Height="200px" Width="200px">
        <Series>
            <asp:Series Name="Series2" CustomProperties="DrawingStyle=Emboss" XValueMember="Date"
                YValueMembers="Count" IsValueShownAsLabel="True" Font="Microsoft Sans Serif, 8pt"
                LabelBackColor="255, 255, 192" LabelBorderColor="192, 192, 0" LabelForeColor="Red">
            </asp:Series>
        </Series>
        <ChartAreas>
            <asp:ChartArea Name="ChartArea1" BorderDashStyle="Solid">
                <AxisX IntervalAutoMode="VariableCount" IntervalOffsetType="Days" IntervalType="Days"
                    IsLabelAutoFit="False" IsStartedFromZero="False">
                    <MajorGrid Interval="Auto" IntervalOffsetType="Days" IntervalType="Days" />
                </AxisX>
            </asp:ChartArea>
        </ChartAreas>
        <Titles>
            <asp:Title Font="Microsoft Sans Serif, 8pt, style=Bold" Name="Title1" Text="Last week enquiries">
            </asp:Title>
        </Titles>
    </asp:Chart>

    @{
        ViewBag.Title = "Index";
    }

    <img 
        src="@Url.Action("GetChart")" 
        alt="Last week enquiries"  
        title="Last week enquiries" 
    />

    Sunday, April 27, 2014 8:41 AM
  • protected void Page_Load(object sender, EventArgs e)
            {
                DataTable oDataTable = CreatePieChartData();
                CreatePieChartData(oDataTable);
            }

            void CreatePieChartData(DataTable oDataTable)
            {
                foreach (DataRow dr in oDataTable.Rows)
                {
                    DataPoint dp = new DataPoint(0, Double.Parse(dr["Comission"].ToString()));
                    dp.Color = Color.FromName(dr["Color"].ToString());
                    dp.ToolTip = dr["AdvisorName"].ToString() + " has earned " + dr["Comission"].ToString() + " as comission";

                    pieChart.Series["chartSeries"].Points.Add(dp);
                    pieChart.Series["chartSeries"]["PointWidth"] = "0.1";
                    pieChart.Series["chartSeries"]["DrawingStyle"] = "Cylinder";
                    pieChart.Series["chartSeries"]["PieLabelStyle"] = "Inside";
                    pieChart.Series["chartSeries"].Font = new Font("Calibri", 7, FontStyle.Regular);

                    pieChart.ChartAreas["MainArea"].InnerPlotPosition.Width = 40;
                    pieChart.ChartAreas["MainArea"].InnerPlotPosition.Height = 90;
                    pieChart.ChartAreas["MainArea"].InnerPlotPosition.X = 25;
                    pieChart.ChartAreas["MainArea"].InnerPlotPosition.Y = 1;
                }
            }

            DataTable CreatePieChartData()
            {
                DataTable dt = new DataTable("Chart");
                dt.Columns.Add("AdvisorName", typeof(string));
                dt.Columns.Add("Color", typeof(string));
                dt.Columns.Add("Comission", typeof(double));
                DataRow dr = dt.NewRow();
                dr["AdvisorName"] = "Stephen";
                dr["Color"] = "Green";
                dr["Comission"] = 1098.98;
                dt.Rows.Add(dr);
                dr = dt.NewRow();
                dr["AdvisorName"] = "Reggie";
                dr["Color"] = "Red";
                dr["Comission"] = 900.98;
                dt.Rows.Add(dr);
                dr = dt.NewRow();
                dr["AdvisorName"] = "Ajmal";
                dr["Color"] = "Blue";
                dr["Comission"] = 98.98;
                dt.Rows.Add(dr);

                return dt;
            }

    <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
        CodeBehind="Default.aspx.cs" Inherits="PieChartDemo._Default" %>

    <%@ Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>
    <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    </asp:Content>
    <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
        <asp:Chart ID="pieChart" runat="server" Height="250px" Width="500px">
            <Series>
                <asp:Series Name="chartSeries" ChartType="Pie" ChartArea="MainArea" IsValueShownAsLabel="true" Label="#PERCENT">
                </asp:Series>
            </Series>
            <ChartAreas>
                <asp:ChartArea Name="MainArea" Area3DStyle-Enable3D="true" Area3DStyle-Inclination="50" Area3DStyle-IsClustered="false">
                </asp:ChartArea>
            </ChartAreas>
        </asp:Chart>
    </asp:Content>

    Monday, April 28, 2014 4:12 AM
  • /// <reference path="../jquery-1.7.2.min.js" />
    /// <reference path="../jquery-1.7.2-vsdoc.js" />
    /// <reference path="../jquery.jqGrid.min.js" />
    
    var curvyCornersVerbose = false;
    
    $(function () {
    	$("#student-grid-array").jqGrid({
    		datatype: "local",
    		colNames: ["Student ID", "Name", "Course", "Year"],
    		colModel: [
    					{ name: "StudentID", index: "StudentID" },
    					{ name: "Name", index: "Name" },
    					{ name: "Course", index: "Course" },
    					{ name: "Year", index: "Year", sorttype: "int" }
    				],
    		multiselect: true,
    		shrinkToFit: false,
    		caption: "Student List - Loading via Array"
    	});
    
    	var students = [
    				{ StudentID: "JC200300001", Name: "Jessica Cohen", Course: "Applied Arts and Sciences", Year: "1" },
    				{ StudentID: "SF200800002", Name: "Shane Foster", Course: "Business Administration", Year: "2" },
    				{ StudentID: "KK200800003", Name: "Kellan Kher", Course: "Social Sciences", Year: "4" },
    				{ StudentID: "PS200100004", Name: "Patrick Shirazi", Course: "Education", Year: "1" },
    				{ StudentID: "CB200400005", Name: "Constance Barry", Course: "Social Sciences", Year: "3" },
    				{ StudentID: "DW200400006", Name: "Dustin Wallace", Course: "Philosophy", Year: "1" },
    				{ StudentID: "AG200900007", Name: "Amal Goodman", Course: "Education", Year: "2" }
    			];
    
    	for (var x = 0; x <= students.length; x++) {
    		$("#student-grid-array").addRowData(x, students[x]);
    	}
    
    	$("#student-grid-json").jqGrid({
    		url: "/Demo/GetStudents",
    		datatype: "json",
    		colNames: ["Student ID", "Name", "Course", "Year"],
    		colModel: [
    					{ name: "StudentID", index: "StudentID" },
    					{ name: "Name", index: "Name" },
    					{ name: "Course", index: "Course" },
    					{ name: "Year", index: "Year", sorttype: "int" }
    				],
    		rowNum: 50,
    		rowList: [20, 50, 100],
    		pager: "#pager-json",
    		sortname: "StudentID",
    		sortorder: "ASC",
    		viewrecords: true,
    		caption: "Student List - Loading via JSON"
    	});
    
    	$("#student-grid-array").navGrid("#pager-json", { edit: false, add: false, del: false, search: false, refresh: false });
    
    	$("#student-grid-virtual-scrolling").jqGrid({
    		url: "/Demo/GetStudents",
    		datatype: "json",
    		colNames: ["Student ID", "Name", "Course", "Year"],
    		colModel: [
    					{ name: "StudentID", index: "StudentID" },
    					{ name: "Name", index: "Name" },
    					{ name: "Course", index: "Course" },
    					{ name: "Year", index: "Year", sorttype: "int" }
    				],
    		rowNum: 50,
    		rownumbers: true,
    		rownumWidth: 40,
    		scroll: 1,
    		pager: "#pager-virtual-scrolling",
    		sortname: "StudentID",
    		sortorder: "ASC",
    		gridview: true,
    		viewrecords: true,
    		caption: "Student List - Virtual Scrolling"
    	});
    
    	$("#student-grid-virtual-scrolling").navGrid("#pager-virtual-scrolling", { edit: false, add: false, del: false, search: false, refresh: false });
    
    	ResizeJqGrids();
    
    	var resizeTimer = null;
    	$(window).resize(function () {
    		if (resizeTimer) clearTimeout(resizeTimer);
    		resizeTimer = setTimeout(ResizeJqGrids, 100);
    	});
    });
    
    function ResizeJqGrids() {
    	var gridWidth = $("#content").width();
    
    	$("#student-grid-array").setGridWidth(gridWidth);
    	$("#student-grid-json").setGridWidth(gridWidth);
    	$("#student-grid-virtual-scrolling").setGridWidth(gridWidth);
    }
    http://stackoverflow.com/questions/5982973/jqgrid-multiselect-checked-box-persist-when-move-to-the-next-page
    Monday, April 28, 2014 4:53 PM
  • loadComplete: function (response) //Incase you want to perform some action once data is loaded
                {
                     var currentPage = $(this).getGridParam('page').toString();
                     //debugger;
                    //retrieve any previously stored rows for this page and re-select them
                    var retrieveSelectedRows = $(this).data(currentPage);
                    if (retrieveSelectedRows) {
                        $.each(retrieveSelectedRows, function (index, value) {
                            $('#jq-grid').setSelection(value, false);
                        });
                    }   
                },

                onPaging: function (a) {
                //debugger;        
                var pagerId = this.p.pager.substr(1); 
                // ger paper id like "pager"            
                var pageValue = $('input.ui-pg-input', "#pg_" + $.jgrid.jqID(pagerId)).val();           
                 var saveSelectedRows = $(this).getGridParam('selarrrow');            
                 //Store any selected rows            
                 $(this).data(pageValue.toString(), saveSelectedRows);       
                  }
    Monday, April 28, 2014 5:24 PM