<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>Developer Barn - Blogs - richyrich</title>
		<link>http://www.developerbarn.com/blogs/richyrich/</link>
		<description>Developer Barn is an ASP, ASP.NET, PHP, Javascript, SQL and MySQL and Programming Help Forum. Get ASP, ASP.NET, PHP and JavaScript help and sample code.</description>
		<language>en</language>
		<lastBuildDate>Fri, 10 Feb 2012 08:37:29 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>http://www.developerbarn.com/images/misc/rss.jpg</url>
			<title>Developer Barn - Blogs - richyrich</title>
			<link>http://www.developerbarn.com/blogs/richyrich/</link>
		</image>
		<item>
			<title>Setting up Cisco RV042 load balanced dual WAN with UK ADSL PPPoA</title>
			<link>http://www.developerbarn.com/blogs/richyrich/41-setting-up-cisco-rv042-load-balanced-dual-wan-uk-adsl-pppoa.html</link>
			<pubDate>Thu, 07 Jul 2011 08:13:46 GMT</pubDate>
			<description>So, we decided to go for a load balancer in the office and after a fair amount of head scratching, finally got it setup. As it was a little...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">So, we decided to go for a load balancer in the office and after a fair amount of head scratching, finally got it setup. As it was a little complicated, I thought I'd post a blog on it.<br />
<br />
We went for the Cisco RV042, mainly down to cost reasons. But it is confusing because none of the WAN options allow PPPoA (as used by alot of UK ISPs). I also went for two new modems (Zoom X4) but I believe any modem / router that can be setup in full bridged mode would be sufficient. We already had a BT ADSL line and ordered our second broadband with BeThere (LLU). We wanted to offer as much resilience as we could, hence going for an LLU provider and keeping our existing BT line.<br />
<br />
The two Zoom modems were setup in full bridged mode, giving them static IPs two above the load balancer's IP. So, ended up with the load balancer at 192.168.1.1, and the two modems at 192.168.1.2 and 192.168.1.3. Each modem needs to be given the correct VCI and VPI settings dependant on the provider (BeThere VPI=0, VCI=101; BT VPI=0, VCI=38).<br />
<br />
Going for the BeThere line as our WAN 1, this was reasonably straightforward to setup as we used the static IP setup. This may be different if you don't order the Pro package with static IP. You literally select Static IP from the options for WAN1 and then enter the details they email you. You can also get the details from <a href="http://www.beusergroup.co.uk/technotes/index.php?title=Connection_settings" target="_blank">here</a>.<br />
<br />
The BT line was a little more complicated. Once the modem is configured for full bridge and the VCI and VPI settings are entered, you need to select PPPoE for WAN2 (assuming this will be the secondary line). Enter the username and password provided by your ADSL ISP to enable you to &quot;dial up&quot; to broadband. Then click Save Settings.<br />
<br />
The Cisco RV042 comes defaulted to Smart Link Backup. In this mode WAN2 is disabled until it is required, so clicking the Connect button on the summary screen will not cause it to dial up. You need to go into System Management -&gt; Dual-WAN and then select the Load Balance option. I leave the Network Detection setting ticked and the Default Gateway boxes both ticked. This tells the router what it should ping to check it's still up. The default gateway for both should be fine.<br />
<br />
The max bandwidth settings tell the router how it should split the traffic. So if one has a max download of 100, for example and the other has a max download of 66.666, the traffic should be split in this proportion.<br />
<br />
Protocol Binding allows you to tell a specific protocol from a specific IP or group of IPs on your network to use a specified WAN connection. I include a setting in here to tell all the HTTPS traffic for all IPs on the network to be directed down the WAN specified, in my case WAN1. I believe splitting HTTPS traffic between lines can cause issues. So the Source IPs are 192.168.1.0 to 192.168.1.0 (all IPs), destination IPs are 0.0.0.0 to 0.0.0.0 (all IPs) and protocol is HTTPS (Port: 443)<br />
<br />
When you make changes to the setup on the load balancer, be sure to click the Save Settings link at the bottom of the screen.<br />
<br />
Once all of this is setup, it's normally a good idea to reboot the load balancer and both modems. And once back up, everything should be online and working. You can check if the lines are connected by seeing if both WANs have an IP on the System Summary page or by clicking Log -&gt; System Statistics.<br />
<br />
Hope that helps someone.</blockquote>

 ]]></content:encoded>
			<dc:creator>richyrich</dc:creator>
			<guid isPermaLink="true">http://www.developerbarn.com/blogs/richyrich/41-setting-up-cisco-rv042-load-balanced-dual-wan-uk-adsl-pppoa.html</guid>
		</item>
		<item>
			<title>JQuery Plugin to include commas when formatting numbers</title>
			<link>http://www.developerbarn.com/blogs/richyrich/40-jquery-plugin-include-commas-when-formatting-numbers.html</link>
			<pubDate>Thu, 07 Apr 2011 13:15:55 GMT</pubDate>
			<description>I wanted to be able to format numbers to include commas every 3 numbers and then fix them to a certain number of decimals. There are a few different...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">I wanted to be able to format numbers to include commas every 3 numbers and then fix them to a certain number of decimals. There are a few different format functions out there and also JQuery plugins, but couldn't seem to find one that did exactly what I wanted, so ended up writing my own.<br />
<br />
Here's the code for anyone else looking for something that will format numbers to include commas using JQuery:-<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:372px;">(function ($) {
    $.fn.formatNumber = function (seperator, every, precision) {
        var val = '';
        if(this.is(&quot;span&quot;)||this.is(&quot;div&quot;)){
            val += this.text();
        }else{
            val += this.val();
        }
        val = parseFloat(val).toFixed(precision);
        val += '';
        var arr = val.split('.',2);
        var i = parseInt(arr[0]);
        if(isNaN(i)) return '';
        i = Math.abs(i);
        var n = new String(i);
        var d = arr.length &gt; 1 ? '.' + arr[1] : '';
        var a = [];
        var nn;
        while(n.length &gt; every)
        {
            nn = n.substr(n.length-every);
            a.unshift(nn);
            n = n.substr(0,n.length-every);
        }
        if(n.length &gt; 0) a.unshift(n);
        n = a.join(seperator);
        if(this.is(&quot;span&quot;)||this.is(&quot;div&quot;)){
            this.text(n + d);
        }else{
            this.val(n + d);
        }
    };
})(jQuery);</pre>
</div> This should work for any span, div or input elements.<br />
<br />
To use the plugin you just attach it to the element like this:-<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:36px;">$(&quot;#spanElement&quot;).text(100).formatNumber(',', 3, 2);</pre>
</div> This will format the number putting a comma every 3 digits on the left side and fix the number to 2 decimal places.<br />
<br />
Hope that helps someone.<br />
<br />
I used this page as a reference for the bulk of the function <a href="http://www.willmaster.com/library/tutorials/currency-formatting-and-putting-commas-in-numbers-with-javascript-and-perl.php" target="_blank">http://www.willmaster.com/library/tu...t-and-perl.php</a></blockquote>

 ]]></content:encoded>
			<dc:creator>richyrich</dc:creator>
			<guid isPermaLink="true">http://www.developerbarn.com/blogs/richyrich/40-jquery-plugin-include-commas-when-formatting-numbers.html</guid>
		</item>
		<item>
			<title>Including Special Characters in your iTextSharp PDF document</title>
			<link>http://www.developerbarn.com/blogs/richyrich/39-including-special-characters-your-itextsharp-pdf-document.html</link>
			<pubDate>Mon, 24 Jan 2011 23:32:20 GMT</pubDate>
			<description>This is a continuation of my blogs regarding generating PDF documents using iTextSharp. 
 
This one really had me stumped for a while and thanks to a...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">This is a continuation of my blogs regarding generating PDF documents using iTextSharp.<br />
<br />
This one really had me stumped for a while and thanks to a couple of members on here, I was able to eventually solve the problem. I read several posts and threads about this issue, but none were solving my problem.<br />
<br />
I was using iTextSharp to generate a number of PDF documents to use in a back office ordering system. The main documents being a PDF invoice and delivery / packing note. The initial problem arose with a weight scale of &amp;micro; grams which I was able to solve by using Convert.ToChar(181). This produced the correct mu greek letter.<br />
<br />
However, within many products were additional greek letters that weren't displaying and the Convert.ToChar workaround wouldn't work with these. After going round the same problem for a while I established that the issue was related to character encoding, specifically on generating a font that could encode the special characters.<br />
<br />
So, this is what I eventually ended up with. You firstly have to declare a base font that uses a specific encoding, namely IDENTITY_H.<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:36px;">protected BaseFont font_ascii = iTextSharp.text.pdf.BaseFont.CreateFont(@&quot;C:/Windows/Fonts/ARIAL.TTF&quot;, BaseFont.IDENTITY_H, iTextSharp.text.pdf.BaseFont.EMBEDDED);</pre>
</div> I also needed to reference the full path to the Font TTF file (this was on my server) and embed the font in the PDF document. Be aware here that embedding the font file will increase the size of the PDF document so try and not use a file that is huge, but also ensure the font contains the characters that you need to use in your PDF. Also note that the filename might be different from the font name, so open the font and click properties to find the filename to embed.<br />
<br />
Once that is done, we use this base font to generate a font object we can reference in our iTextSharp PDF document. This is how I declared mine:-<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:108px;">    protected Font body_ascii
    {
        get
        {
            return new iTextSharp.text.Font(font_ascii, 12, Font.NORMAL, new BaseColor(0, 0, 0));
        }
    }</pre>
</div> You will see the reference to my font_ascii base font.<br />
<br />
Then to use the correct encoding in the iTextSharp code, we simply reference this font in our Phrase declaration:-<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:36px;">orderItemCell.Phrase = new Phrase(&quot;some text that contains special characters&quot;, body_ascii);</pre>
</div> And this should display them correctly.<br />
<br />
I hope that helps anyone having the same problem I encountered.<br />
<br />
&lt;edit&gt;After solving my issue, I did find <a href="http://stackoverflow.com/questions/1727765/itextsharp-international-text" target="_blank">this thread</a> about the same problem.&lt;/edit&gt;</blockquote>

 ]]></content:encoded>
			<dc:creator>richyrich</dc:creator>
			<guid isPermaLink="true">http://www.developerbarn.com/blogs/richyrich/39-including-special-characters-your-itextsharp-pdf-document.html</guid>
		</item>
		<item>
			<title>Adding Page Numbers to your iTextSharp PDF document header and footer</title>
			<link>http://www.developerbarn.com/blogs/richyrich/38-adding-page-numbers-your-itextsharp-pdf-document-header-footer.html</link>
			<pubDate>Thu, 21 Oct 2010 09:54:06 GMT</pubDate>
			<description>Just a quick update on iTextSharp again. In my previous blog...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">Just a quick update on iTextSharp again. In my <a href="http://www.developerbarn.com/blogs/richyrich/32-using-itextsharp-generate-pdf-header-footer.html" target="_blank">previous blog</a> I explained how to add headers and footers to your PDF documents generated using iTextSharp.<br />
<br />
I received a question about including page numbers in the footer of a document. This is very simple to do inside the OnEndPage override method of our PDFPageEventHelper inherited class.<br />
<br />
In my class I include a public property called showPageCount<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:36px;">public bool showPageCount { get; set; }</pre>
</div> So, from my PDF page, I can set whether I want to include the page numbers or not.<br />
<br />
Then inside the OnEndPage method I include this:-<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:132px;">if (showPageCount)
{
   // Add in the current page number using the &quot;footer&quot; font
   Paragraph para = new Paragraph(&quot;Page &quot; + document.PageNumber, footer);
}

// When setting the bottom margin, I just add 5 to it if we are showing page numbers
float botMarg = document.BottomMargin + 10;
if (showPageCount) botMarg += 5;</pre>
</div> Please see my <a href="http://www.developerbarn.com/blogs/richyrich/32-using-itextsharp-generate-pdf-header-footer.html" target="_blank">previous blog</a> for the full code on setting up the headers and footers in the first place.<br />
<br />
Some of you may be wondering if it's possible to have something like &quot;Page 2 of 10&quot; in your footer. I am working on something to try and achieve this. The limitation is that the total number of pages has to be inside a template that is of fixed size. So, if you allow for up to 1,000 pages, it can cause formatting problems if you only have say 9 pages, because the element that the 9 sits in is a fixed width. I will post another blog on this.<br />
<br />
Hope that helps someone...:)</blockquote>

 ]]></content:encoded>
			<dc:creator>richyrich</dc:creator>
			<guid isPermaLink="true">http://www.developerbarn.com/blogs/richyrich/38-adding-page-numbers-your-itextsharp-pdf-document-header-footer.html</guid>
		</item>
		<item>
			<title>Set Initial PDF Document Zoom using iTextSharp</title>
			<link>http://www.developerbarn.com/blogs/richyrich/33-set-initial-pdf-document-zoom-using-itextsharp.html</link>
			<pubDate>Mon, 28 Jun 2010 13:15:37 GMT</pubDate>
			<description><![CDATA[Another iTextSharp blog post, this time on setting the initial zoom for a document. 
 
Couldn't find an exact example of how to do this, but managed...]]></description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">Another iTextSharp blog post, this time on setting the initial zoom for a document.<br />
<br />
Couldn't find an exact example of how to do this, but managed to cobble this together from a variety of code snippets I found.<br />
<br />
You can set the initial zoom of a document using iTextSharp by adding a SetOpenAction method to the PdfWriter object. I found I could only add this once the document had been opened using doc.Open(), otherwise I got an &quot;Object reference&quot; error. This I presumed was referring to the writer object.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:240px;">        PdfWriter writer = PdfWriter.GetInstance(doc, HttpContext.Current.Response.OutputStream);

        //this creates a new destination to send the action to when the document is opened. The zoom in this instance is set to 0.75f (75%). Again I use doc.PageSize.Height to set the y coordinate to the top of the page. PdfDestination.XYZ is a specific PdfDestination Type that allows us to set the location and zoom.
        PdfDestination pdfDest = new PdfDestination(PdfDestination.XYZ, 0, doc.PageSize.Height, 0.75f);

         //open our document
         doc.Open();

         //here you put all the information you want to write to your PDF

        //create a new action to send the document to our new destination.
        PdfAction action = PdfAction.GotoLocalPage(1, pdfDest, writer);

        //set the open action for our writer object
        writer.SetOpenAction(action);

        //finally, close our document
        doc.Close();</pre>
</div> This should set the initial destination of our iTextSharp PDF document to page 1, location 0, page height, with a zoom of 0.75.<br />
<br />
Hope that helps someone.</blockquote>

 ]]></content:encoded>
			<dc:creator>richyrich</dc:creator>
			<guid isPermaLink="true">http://www.developerbarn.com/blogs/richyrich/33-set-initial-pdf-document-zoom-using-itextsharp.html</guid>
		</item>
		<item>
			<title>Using iTextSharp to generate PDF with Header and Footer</title>
			<link>http://www.developerbarn.com/blogs/richyrich/32-using-itextsharp-generate-pdf-header-footer.html</link>
			<pubDate>Sat, 26 Jun 2010 10:03:16 GMT</pubDate>
			<description><![CDATA[This one had me struggling for a while, so I thought I'd post a blog about it to try and help others. 
 
What I was trying to do was create a PDF...]]></description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">This one had me struggling for a while, so I thought I'd post a blog about it to try and help others.<br />
<br />
What I was trying to do was create a PDF including header and footer sections to print documents onto a headed paper style.<br />
<br />
Using iTextSharp V5.0.2.0 DLL in the bin folder you can create PDFs on the fly. My <a href="http://www.developerbarn.com/blogs/richyrich/31-generate-pdf-documents-fly-using-asp-net-itextsharp.html" target="_blank">previous blog</a> explained how to generate a simple PDF. Next I wanted to generate something a bit more complicated.<br />
<br />
It seems previous versions of iTextSharp used a different method for producing headers and footers, but the more recent releases use an event handler to allow you to manipulate the document during various stages of it's production.<br />
<br />
The first thing to do is create a class that will provide the event handler methods. This inherits the PdfPageEventHelper class from iTextSharp, like so:-<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:372px;">using System;
using System.Web;
using iTextSharp.text;
using iTextSharp.text.pdf;

namespace myApp.ns.pages
{
   public class pdfPage : iTextSharp.text.pdf.PdfPageEventHelper
   {
       //I create a font object to use within my footer
      protected Font footer
      {
          get
          {
               // create a basecolor to use for the footer font, if needed.
               BaseColor grey = new BaseColor(128, 128, 128);
               Font font = FontFactory.GetFont(&quot;Arial&quot;, 9, Font.Normal, grey);
               return font;
          }
      }
       //override the OnStartPage event handler to add our header
       public override void OnStartPage(PdfWriter writer, Document doc)
       {
            //I use a PdfPtable with 1 column to position my header where I want it
            PdfPTable headerTbl = new PdfPTable(1);

            //set the width of the table to be the same as the document
            headerTbl.TotalWidth = doc.PageSize.Width;

            //I use an image logo in the header so I need to get an instance of the image to be able to insert it. I believe this is something you couldn't do with older versions of iTextSharp
            Image logo = Image.GetInstance(HttpContext.Current.Server.MapPath(&quot;/images/logo.jpg&quot;));

            //I used a large version of the logo to maintain the quality when the size was reduced. I guess you could reduce the size manually and use a smaller version, but I used iTextSharp to reduce the scale. As you can see, I reduced it down to 7% of original size.
            logo.ScalePercent(7);

            //create instance of a table cell to contain the logo
            PdfPCell cell = new PdfPCell(logo);

            //align the logo to the right of the cell
            cell.HorizontalAlignment = Element.ALIGN_RIGHT;

            //add a bit of padding to bring it away from the right edge
            cell.PaddingRight = 20;

            //remove the border
            cell.border = 0;

            //Add the cell to the table
            headerTbl.AddCell(cell);

            //write the rows out to the PDF output stream. I use the height of the document to position the table. Positioning seems quite strange in iTextSharp and caused me the biggest headache.. It almost seems like it starts from the bottom of the page and works up to the top, so you may ned to play around with this.
            headerTbl.WriteSelectedRows(0,-1, 0, (doc.PageSize.Height-10), writer.DirectContent);
       }

       //override the OnPageEnd event handler to add our footer
       public override void OnEndPage(PdfWriter writer, Document doc)
       {
            //I use a PdfPtable with 2 columns to position my footer where I want it
            PdfPTable footerTbl = new PdfPTable(2);

            //set the width of the table to be the same as the document
            footerTbl.TotalWidth = doc.PageSize.Width;

            //Center the table on the page
            footerTbl.HorizontalAlignment = Element.ALIGN_CENTER;

            //Create a paragraph that contains the footer text
            Paragraph para = new Paragraph(&quot;Some footer text&quot;, footer);

            //add a carriage return
            para.Add(Environment.NewLine);
            para.Add(&quot;Some more footer text&quot;);

            //create a cell instance to hold the text
            PdfPCell cell = new PdfPCell(para);

            //set cell border to 0
            cell.Border = 0;

            //add some padding to bring away from the edge
            cell.PaddingLeft = 10;

            //add cell to table
            footerTbl.AddCell(cell);

            //create new instance of Paragraph for 2nd cell text
            para = new Paragraph(&quot;Some text for the second cell&quot;, footer);

           //create new instance of cell to hold the text
            cell = new PdfPCell(para);

            //align the text to the right of the cell
            cell.HorizontalAlignment = Element.ALIGN_RIGHT;
            //set border to 0
            cell.Border = 0;

            // add some padding to take away from the edge of the page
            cell.PaddingRight = 10;

            //add the cell to the table
            footerTbl.AddCell(cell);

         //write the rows out to the PDF output stream.
         footerTbl.WriteSelectedRows(0,-1, 0, (doc.BottomMargin + 10),  writer.DirectContent);
       }
   }
}</pre>
</div> Then, on your PDF page, you need to add your event handler to the PDF instance. This can be done like this-<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:372px;">using System;
using System.Web;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;

using myApp.ns.pages;

    protected void Page_Load(object sender, EventArgs e)
    {
        //create an instance of a PDF document. You may need to play with the margins to ensure the &quot;look&quot; is right
        Document doc = new Document(PageSize.A4, 42, 53, 70, 46);

        //Change the content type to PDF
        HttpContext.Current.Response.ContentType = &quot;application/pdf&quot;;

        //create an instance of your PDFpage class. This is the class we generated above.
        pdfPage page = new pdfPage();

        //create an instance of the PdfWriter and write to the Response.OutputStream. This will stream it directly to the browser
        PdfWriter pdfWriter = PdfWriter.GetInstance(doc, HttpContext.Current.Response.OutputStream);

        //set the PageEvent of the pdfWriter instance to the instance of our PDFPage class
        pdfWriter.PageEvent = page;

        //open the document
        doc.Open();

        //this is just some default text I used. a Paragraph instance is just repeated 100 times
        Paragraph para;
        for (int x = 1; x &lt;= 100; x++)
        {
            para = new Paragraph(&quot;This is a paragraph&quot;);
            doc.Add(para);
        }

        //close the document
        doc.Close();
    }</pre>
</div> That should be it! You will have your header and footer in the correct place on every page.<br />
<br />
The things you'll have to play around with are the page margins to ensure they don't overlap the header or footer areas. Using the event handlers, our header and footer tables use absolute positioning to put them in the right place, so you may need to make some adjustments where necessary.<br />
<br />
Hope that helps someone.</blockquote>

 ]]></content:encoded>
			<dc:creator>richyrich</dc:creator>
			<guid isPermaLink="true">http://www.developerbarn.com/blogs/richyrich/32-using-itextsharp-generate-pdf-header-footer.html</guid>
		</item>
		<item>
			<title>Generate PDF documents on the fly using ASP.NET and iTextSharp</title>
			<link>http://www.developerbarn.com/blogs/richyrich/31-generate-pdf-documents-fly-using-asp-net-itextsharp.html</link>
			<pubDate>Thu, 13 May 2010 20:53:30 GMT</pubDate>
			<description><![CDATA[As part of a project I'm working on, I have the need to generate PDF documents "on the fly" and then render them back to the browser. 
 
I was...]]></description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">As part of a project I'm working on, I have the need to generate PDF documents &quot;on the fly&quot; and then render them back to the browser.<br />
<br />
I was already aware of a dll module that provided this functionality, available at <a href="http://sourceforge.net/projects/itextsharp/" target="_blank">iTextSharp | Get iTextSharp at SourceForge.net</a> so I thought I'd post a quick blog about how to get it working.<br />
<br />
Firstly, you need to place the .dll file in the bin directory of your application / website.<br />
<br />
I then created a new .aspx page, the content of which was just<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:36px;">&lt;%@ Page Language=&quot;C#&quot; CodeFile=&quot;invoicepdf.aspx.cs&quot; Inherits=&quot;_invoicepdf&quot; %&gt;</pre>
</div> The code behind was like this:-<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:336px;">using System;
using System.Web;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;

public partial class _invoicepdf : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       // Create instance of a new document
        Document doc = new Document(PageSize.A4, 10, 10, 50, 50);
       // Change the content type to application/pdf !Important
       HttpContext.Current.Response.ContentType = &quot;application/pdf&quot;;
       // Get Instance of pdfWriter to be able to create the document in the OutputStream
        PdfWriter.GetInstance(doc, HttpContext.Current.Response.OutputStream);
       // Open the document to be able to write to it
        doc.Open();
       // Create a simple paragraph to add to the document
        Paragraph para = new Paragraph(&quot;This is a paragraph&quot;);
      // Add the paragraph to the document
        doc.Add(para);
      // Close the document, rendering it to the browser
        doc.Close();
    }
}</pre>
</div> Text can be added to the PDF using a variety of methods. They include:-<br />
Chunk<br />
Paragraph<br />
Phrase<br />
<br />
You can also apply fonts and styles to an instance of each of these objects to use italics, underline etc.</blockquote>

 ]]></content:encoded>
			<dc:creator>richyrich</dc:creator>
			<guid isPermaLink="true">http://www.developerbarn.com/blogs/richyrich/31-generate-pdf-documents-fly-using-asp-net-itextsharp.html</guid>
		</item>
		<item>
			<title>Outlook IMAP Error Code 0x800cccdd</title>
			<link>http://www.developerbarn.com/blogs/richyrich/29-outlook-imap-error-code-0x800cccdd.html</link>
			<pubDate>Wed, 07 Apr 2010 14:22:09 GMT</pubDate>
			<description>We have several IMAP accounts setup with 1and1 for shared email accounts and users have recently started having problems where the password box would...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">We have several IMAP accounts setup with 1and1 for shared email accounts and users have recently started having problems where the password box would constantly popup.<br />
<br />
Outlook would also give an error of:-<br />
<i>too many errors.<br />
    Protocol:    IMAP<br />
    Server:     imap.1and1.co.uk<br />
    Port:    143<br />
    Error Code:    0x800CCCDD&quot;</i><br />
<br />
Obviously this was causing lots of problems for users with several IMAP accounts.<br />
<br />
The solution I found was to remove all these IMAP accounts from the Send / Receive group and only have POP accounts set to Send / Receive.<br />
<br />
It seems IMAP keeps the connection open between Outlook and the server and therefore it is not necessary to keep Send / Receive. It also makes Send/Receive run much quicker, as previously it appeared to be syncing all folders for all IMAP accounts, which was taking forever. Now, new messages automatically appear in the IMAP inbox without any need to Send / Receive.<br />
<br />
This may only be relevant for host 1and1, but this seems to have resolved the issue for us.<br />
<br />
Hope this helps someone else.</blockquote>

 ]]></content:encoded>
			<dc:creator>richyrich</dc:creator>
			<guid isPermaLink="true">http://www.developerbarn.com/blogs/richyrich/29-outlook-imap-error-code-0x800cccdd.html</guid>
		</item>
		<item>
			<title>Using ASP.NET AJAX Library</title>
			<link>http://www.developerbarn.com/blogs/richyrich/27-using-asp-net-ajax-library.html</link>
			<pubDate>Tue, 09 Mar 2010 13:47:22 GMT</pubDate>
			<description>ASP.NET AJAX library is currently Version 0911 Beta. The toolkit can be downloaded from ASP.NET Ajax Library (http://ajax.codeplex.com/) 
 
I have...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">ASP.NET AJAX library is currently Version 0911 Beta. The toolkit can be downloaded from <a href="http://ajax.codeplex.com/" target="_blank">ASP.NET Ajax Library</a><br />
<br />
I have previously used the AJAX Toolkit extensions in my ASP.NET projects and thought on my current project I'd see if there was an update.<br />
<br />
Finding the ASP.NET AJAX library beta, I thought I'd give this a go. However, I did come across a couple of trip-ups that I thought I'd post here as I couldn't find much info when I googled it.<br />
<br />
So, to get the AJAX Library to work, I did the following.<br />
<br />
1) Copy the AjaxControlToolkit.dll AND System.Web.Ajax.dll to your bin folder.<br />
<br />
2) Reference the AjaxControlToolkit in your web.config<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:108px;">    &lt;pages&gt;
      &lt;controls&gt;
        &lt;add tagPrefix=&quot;asp&quot; namespace=&quot;System.Web.UI&quot; assembly=&quot;System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35&quot;/&gt;
        &lt;add tagPrefix=&quot;asp&quot; namespace=&quot;System.Web.UI.WebControls&quot; assembly=&quot;System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35&quot;/&gt;
        <font color="red">&lt;add tagPrefix=&quot;asp&quot; assembly=&quot;AjaxControlToolkit&quot; namespace=&quot;AjaxControlToolkit&quot; /&gt;</font>
      &lt;/controls&gt;
    &lt;/pages&gt;</pre>
</div> I used the same &quot;asp&quot; prefix.<br />
<br />
3) In either your master page (or your content page) remove any &lt;asp:ScriptManager /&gt; reference and change it to<br />
&lt;asp:ToolkitScriptManager /&gt;. I kept the other properties identical, so ended up with:-<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:48px;">&lt;asp:ToolkitScriptManager ID=&quot;MasterScripts&quot; runat=&quot;server&quot; EnablePartialRendering=&quot;true&quot;&gt;
    &lt;/asp:ToolkitScriptManager&gt;</pre>
</div> I include mine on my master page, but you could just include it on any pages you want to use the toolkit.<br />
<br />
From here you should be good to go. For example, to use the calendar extender, just have:-<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:36px;">&lt;asp:CalendarExtender ID=&quot;ceDateField&quot; runat=&quot;server&quot; TargetControlID=&quot;txtDateField&quot; Format=&quot;dd/MM/yyyy&quot; PopupButtonID=&quot;imgMyCalImage&quot; CssClass=&quot;mycalendar&quot; Animated=&quot;false&quot; /&gt;</pre>
</div> If I find any other problems with using the new beta version, I'll post some more info in my blog.<br />
<br />
Hope that helps someone.</blockquote>

 ]]></content:encoded>
			<dc:creator>richyrich</dc:creator>
			<guid isPermaLink="true">http://www.developerbarn.com/blogs/richyrich/27-using-asp-net-ajax-library.html</guid>
		</item>
		<item>
			<title>Convert .asmx file to WCF .svc file to create simple API web service</title>
			<link>http://www.developerbarn.com/blogs/richyrich/26-convert-asmx-file-wcf-svc-file-create-simple-api-web-service.html</link>
			<pubDate>Tue, 20 Oct 2009 02:12:36 GMT</pubDate>
			<description>3) Converting a .asmx file to WCF .svc file 
 
This is part of a series of blogs. The others are:- 
1) Introduction...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore"><font face="Arial">3) Converting a .asmx file to WCF .svc file<br />
<br />
This is part of a series of blogs. The others are:-<br />
1) <a href="http://www.developerbarn.com/blogs/richyrich/24-convert-asmx-file-wcf-svc-file-create-simple-api-web-service.html" target="_blank">Introduction</a><br />
2) <a href="http://www.developerbarn.com/blogs/richyrich/25-convert-asmx-file-wcf-svc-file-create-simple-api-web-service.html" target="_blank">A simple .asmx file and calling a function</a><br />
<br />
</font>      <font face="Arial">The next section to cover is converting our .asmx file to a WCF web service. This is placed in a .svc file and uses Contracts to define what can be consumed in the web service and endpoints in the web.config of your application define how the service will be exposed.<br />
<br />
</font>      <font face="Arial">I guess the first question is, why go to the trouble of converting your web services?<br />
</font>   <font face="Arial">I found this on Rick Strahl’s Web log[1], which made a lot of sense to me:-<br />
<i>“A valid question to ask though is: Do I need to use WCF or should I continue to use ASMX?</i><br />
<br />
<i>If ASMX services are working fine for you as is with MS AJAX you probably don't have to switch. In fact if your services are purely based on making AJAX callbacks from a pure Web app and you don't plan on reusing existing services, there's not much of an advantage using  WCF over ASMX services. ASMX services continue to be easier to set up and work with and maybe more importantly they don't require .NET 3.5.</i><br />
<br />
<i>WCF REST services however provide features that ASMX does not, such as the ability to serve raw non-ASP.NET AJAX formatted data in 'bare' format. If you're working with non-ASP.NET AJAX clients like jQuery or Prototype this can be a bonus and lets you avoid using the MS AJax client libraries and ScriptManager. WCF REST also supports raw XML based access to services which is also useful and can't be directly accomplished with ASMX.</i><br />
<br />
<i>Another consideration: If you have existing services that rely on HttpContext, realize that WCF by default doesn't support access to the underlying 'host platform'. WCF is supposed to be host agnostic and WCF services can in fact be running outside of IIS. If you have existing code that relies on HttpContext access to the Request or Session object which is common , it's probably best to leave it in ASMX (although WCF has a way to do that as well).</i><br />
<br />
<i>But if you're starting a new app and you're using .NET 3.5 on the server anyway you might as well take advantage of WCF's REST/Ajax features and the wider range of options available to publish data.”</i><br />
<br />
</font>                                 <font face="Arial">So, assuming you want to have a go at converting your asmx web service to WCF, read on. A lot of the coding below is based on a couple of excellent screen casts I found from Rob Bagby[2,3,4]<br />
<br />
</font>      <font face="Arial">In the web service you have [ServiceContract] attribute that defines the Interface between the server and the client, an [OperationContract] attribute that defines the functions that are available inside the web service, a [DataContract] attribute that exposes a class object in the web service and the [DataMember] attribute that defines which properties of the class will be available.<br />
<br />
</font>      <font face="Arial">Using the example from the previous blogs, this is how I have created the .svc file<br />
</font><div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:48px;">   <font face="Arial">&lt;%</font><font face="Arial"><font color="blue">@</font></font><font face="Arial"> <font color="#a31515">ServiceHost</font> <font color="red">Language</font><font color="blue">=&quot;C#&quot;</font> <font color="red">Debug</font><font color="blue">=&quot;true&quot;</font> <font color="red">Service</font><font color="blue">=&quot;services.RESTEmailService&quot;</font> <font color="red">CodeBehind</font><font color="blue">=&quot;~/App_Code/emailing.cs&quot;</font> %&gt;
</font></pre>
</div> <font face="Arial"><br />
</font>   <font face="Arial">The relevant piece of information for us is the Service attribute. This is how we will reference the service in our web.config I have called this file RESTEmail.svc<br />
<br />
</font>      <font face="Arial">And the emailing.cs code behind<br />
</font><div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:372px;">   <font face="Arial"><font color="blue">using</font></font><font face="Arial"> System;
</font>   <font face="Arial"><font color="blue">using</font></font><font face="Arial"> System.Collections.Generic;
</font>   <font face="Arial"><font color="blue">using</font></font><font face="Arial"> System.Linq;
</font>   <font face="Arial"><font color="blue">using</font></font><font face="Arial"> System.Runtime.Serialization;
</font>   <font face="Arial"><font color="blue">using</font></font><font face="Arial"> System.ServiceModel;
</font>   <font face="Arial"><font color="blue">using</font></font><font face="Arial"> System.ServiceModel.Web;
</font>   <font face="Arial"><font color="blue">using</font></font><font face="Arial"> System.Net;
</font>   <font face="Arial"><font color="blue">using</font></font><font face="Arial"> System.Text;
</font>   <font face="Arial"><font color="blue">using</font></font><font face="Arial"> w3d.App.BLL.Emails;


</font>         <font face="Arial"><font color="blue">namespace</font></font><font face="Arial"> services
</font>   <font face="Arial">{

</font>      <font face="Arial">    [DataContract]
</font>   <font face="Arial">    <font color="blue">public</font> <font color="blue">class</font> <font color="#2b91af">response</font>
</font>   <font face="Arial">    {
</font>   <font face="Arial">        <font color="blue">public</font> <font color="blue">bool</font> error { <font color="blue">get</font>; <font color="blue">set</font>; }
</font>   <font face="Arial">        [DataMember]
</font>   <font face="Arial">        <font color="blue">public</font> <font color="blue">string</font> message { <font color="blue">get</font>; <font color="blue">set</font>; }
</font>   <font face="Arial">    }

</font>      <font face="Arial">    [DataContract]
</font>   <font face="Arial">    <font color="blue">public</font> <font color="blue">class</font> <font color="#2b91af">iEmail</font>
</font>   <font face="Arial">    {
</font>   <font face="Arial">        [DataMember]
</font>   <font face="Arial">        <font color="blue">public</font> <font color="blue">string</font> emailTo { <font color="blue">get</font>; <font color="blue">set</font>; }
</font>   <font face="Arial">        [DataMember]
</font>   <font face="Arial">        <font color="blue">public</font> <font color="blue">string</font> emailFrom { <font color="blue">get</font>; <font color="blue">set</font>; }

</font>      <font face="Arial">        <font color="blue">public</font> <font color="blue">string</font> emailCc { <font color="blue">get</font>; <font color="blue">set</font>; }

</font>      <font face="Arial">        <font color="blue">public</font> <font color="blue">string</font> emailBcc { <font color="blue">get</font>; <font color="blue">set</font>; }
</font>   <font face="Arial">        [DataMember]
</font>   <font face="Arial">        <font color="blue">public</font> <font color="blue">string</font> subject { <font color="blue">get</font>; <font color="blue">set</font>; }
</font>   <font face="Arial">        [DataMember]
</font>   <font face="Arial">        <font color="blue">public</font> <font color="blue">string</font> message { <font color="blue">get</font>; <font color="blue">set</font>; }
</font>   <font face="Arial">        [DataMember]
</font>   <font face="Arial">        <font color="blue">public</font> <font color="blue">string</font> priority { <font color="blue">get</font>; <font color="blue">set</font>; }
</font>   <font face="Arial">        [DataMember]
</font>   <font face="Arial">        <font color="blue">public</font> <font color="blue">bool</font> read { <font color="blue">get</font>; <font color="blue">set</font>; }
</font>   <font face="Arial">        [DataMember]
</font>   <font face="Arial">        <font color="blue">public</font> <font color="blue">bool</font> own { <font color="blue">get</font>; <font color="blue">set</font>; }

</font>      <font face="Arial">        <font color="blue">public</font> <font color="blue">string</font> filepath { <font color="blue">get</font>; <font color="blue">set</font>; }

</font>      <font face="Arial">    }

</font>      <font face="Arial">    [<font color="#2b91af">ServiceContract</font>]
</font>   <font face="Arial">    <font color="blue">public</font> <font color="blue">interface</font> <font color="#2b91af">iRESTEmailService</font>
</font>   <font face="Arial">    {
</font>   <font face="Arial">        [<font color="#2b91af">OperationContract</font>]
</font>   <font face="Arial">        [<font color="#2b91af">WebGet</font>(UriTemplate=<font color="#a31515">&quot;get&quot;</font>, ResponseFormat=<font color="#2b91af">WebMessageFormat</font>.Xml)]
</font>   <font face="Arial">        <font color="#2b91af">iEmail</font> GetEmail();

</font>      <font face="Arial">        [<font color="#2b91af">OperationContract</font>]
</font>   <font face="Arial">        [<font color="#2b91af">WebInvoke</font>(Method = <font color="#a31515">&quot;PUT&quot;</font>, UriTemplate = <font color="#a31515">&quot;get&quot;</font>, ResponseFormat = <font color="#2b91af">WebMessageFormat</font>.Xml, RequestFormat = <font color="#2b91af">WebMessageFormat</font>.Xml)]
</font>   <font face="Arial">        <font color="green">//[WebGet]</font>
</font>   <font face="Arial">        <font color="#2b91af">response</font> SendEmail(<font color="#2b91af">iEmail</font> iEmail);
</font>   <font face="Arial">    }

</font>      <font face="Arial">    <font color="blue">public</font> <font color="blue">class</font> <font color="#2b91af">RESTEmailService</font> : <font color="#2b91af">emailingBase</font>, <font color="#2b91af">iRESTEmailService</font>
</font>   <font face="Arial">    { }

</font>      <font face="Arial">    <font color="blue">public</font> <font color="blue">class</font> <font color="#2b91af">emailingBase</font>
</font>   <font face="Arial">    {
</font>   <font face="Arial">        <font color="blue">public</font> <font color="#2b91af">response</font> SendEmail(<font color="#2b91af">iEmail</font> iEmail)
</font>   <font face="Arial">        {
</font>   <font face="Arial">            <font color="#2b91af">OutgoingWebResponseContext</font> outResponse = <font color="#2b91af">WebOperationContext</font>.Current.OutgoingResponse;
</font>   <font face="Arial">            <font color="#2b91af">IncomingWebRequestContext</font> inRequest = <font color="#2b91af">WebOperationContext</font>.Current.IncomingRequest;

</font>      <font face="Arial">            <font color="#2b91af">response</font> response = <font color="blue">new</font> <font color="#2b91af">response</font>();

</font>      <font face="Arial">            <font color="#2b91af">email</font> newEmail = <font color="blue">new</font> <font color="#2b91af">email</font>();
</font>   <font face="Arial">            newEmail.emailTo.Add(<font color="blue">new</font> <font color="#2b91af">emailAdd</font>(iEmail.emailTo));
</font>   <font face="Arial">            newEmail.emailFrom.Add(<font color="blue">new</font> <font color="#2b91af">emailAdd</font>(iEmail.emailFrom));
</font>   <font face="Arial">            newEmail.subject = iEmail.subject;
</font>   <font face="Arial">            newEmail.message = iEmail.message;
</font>   <font face="Arial">            newEmail.priority = iEmail.priority;
</font>   <font face="Arial">            newEmail.read = iEmail.read;
</font>   <font face="Arial">            newEmail.filepath = <font color="#a31515">&quot;&quot;</font>;

</font>      <font face="Arial">            newEmail.seperate = <font color="blue">false</font>;
</font>   <font face="Arial">            newEmail.isHTML = <font color="blue">true</font>;
</font>   <font face="Arial">            newEmail.sendAsync = <font color="blue">false</font>;

</font>      <font face="Arial">            <font color="blue">if</font> (!<font color="#2b91af">email</font>.SendEmail(newEmail))
</font>   <font face="Arial">            {
</font>   <font face="Arial">                outResponse.StatusCode = <font color="#2b91af">HttpStatusCode</font>.InternalServerError;
</font>   <font face="Arial">                response.message = newEmail.err;
</font>   <font face="Arial">                <font color="green">//return null;</font>
</font>   <font face="Arial">            }<font color="blue">else</font>{
</font>   <font face="Arial">                response.message = <font color="#a31515">&quot;Your email has been sent&quot;</font>;
</font>   <font face="Arial">            }
</font>   <font face="Arial">            <font color="blue">return</font> response;
</font>   <font face="Arial">        }

</font>      <font face="Arial">        <font color="blue">public</font> <font color="#2b91af">iEmail</font> GetEmail()
</font>   <font face="Arial">        {
</font>   <font face="Arial">            <font color="#2b91af">iEmail</font> iEmail = <font color="blue">new</font> <font color="#2b91af">iEmail</font>();
</font>   <font face="Arial">            iEmail.emailBcc = <font color="#a31515">&quot;emailBcc&quot;</font>;
</font>   <font face="Arial">            iEmail.emailCc = <font color="#a31515">&quot;emailCc&quot;</font>;
</font>   <font face="Arial">            iEmail.emailFrom = <font color="#a31515">&quot;emailFrom&quot;</font>;
</font>   <font face="Arial">            iEmail.emailTo = <font color="#a31515">&quot;emailTo&quot;</font>;
</font>   <font face="Arial">            iEmail.filepath = <font color="#a31515">&quot;filepath&quot;</font>;
</font>   <font face="Arial">            iEmail.message = <font color="#a31515">&quot;message&quot;</font>;
</font>   <font face="Arial">            iEmail.own = <font color="blue">false</font>;
</font>   <font face="Arial">            iEmail.priority = <font color="#a31515">&quot;Normal&quot;</font>;
</font>   <font face="Arial">            iEmail.read = <font color="blue">false</font>;
</font>   <font face="Arial">            iEmail.subject = <font color="#a31515">&quot;subject&quot;</font>;

</font>      <font face="Arial">            <font color="blue">return</font> iEmail;
</font>   <font face="Arial">        }
</font>   <font face="Arial">    }
</font>   <font face="Arial">}
</font></pre>
</div> <font face="Arial"><br />
<br />
</font>            <font face="Arial">The main points to note are:-<br />
</font>   <font face="Arial">1)</font><font face="Arial">The System.ServiceModel reference.<br />
<br />
</font>   <font face="Arial">2)</font><font face="Arial">DataContracts (iEmail and response)<br />
</font>   <font face="Arial"><br />
3)</font><font face="Arial">ServiceContract which defines the interface between server and client<br />
</font>   <font face="Arial"><br />
4)</font><font face="Arial">OperationContract that defines the methods exposed to the client<br />
<br />
1)</font><font face="Arial"> The ServiceModel namespace handles web services<br />
<br />
</font>      <font face="Arial">2) I have defined two DataContracts. One is a response that we will use to send a message back to our client. The second is an email contract that defines the parameters we require in order to process the request to the web service.<br />
</font>   <font face="Arial">You will notice there are a couple of properties that do not have the DataMember attribute. These properties will not be exposed to the client, which will become clear when we move on to the get request<br />
</font>   <font face="Arial"><br />
3) We have one ServiceContract that is our interface between the client and our web service. I have kept mine very simple, but you can add attributes to each, such as a namespace and the like. I haven’t included anything like that in mine<br />
<br />
</font>   <font face="Arial">4) The ServiceContract has two OperationContracts, ie two functions exposed to our clients.<br />
<br />
</font>      <font face="Arial">One is a GET request which returns our iEmail DataContact object. It is decorated with the WebGetAttribute, meaning it will be called by way of a GET request like in a browser address bar. It has been given a UriTemplate attribute of “get”. The UriTemplate allows you to define how this operation will be called by the client. The UriTemplate refers to anything you have after a filename.ext/  So in our case, a client would use RESTEmail.svc/get to call this operation, using a GET request. I have also defined the ResponseFormat as XML.<br />
</font>   <font face="Arial">I’ll come onto the reason for this operation in a moment.<br />
<br />
</font>      <font face="Arial">The other is a PUT request that will actually be used to send our email and return a response to the client. This has a WebInvokeAttribute that allows us to define how the operation will be called. You’ll notice that it has exactly the same UriTemplate as our GET operation, but we have defined the METHOD as PUT. So any PUT requests sent to RESTEmail.svc/get will be handled by this operation. There is a fair amount of debate over the use of HTTP verbs and what operations each should handle. You could, for example, decide to use a POST request for this operation. I have also defined the Request and Response formats as XML.<br />
<br />
</font>      <font face="Arial">So, if you want a service to be accessed by a GET request, use the WebGetAttribute. If you want to use a different method, use the WebInvokeAttribute.<br />
<br />
</font>      <font face="Arial">These OperationContracts are interfaces with the client which are used to call functions and routines contained in our base class that actually deal with the requests.<br />
<br />
</font>      <font face="Arial">The above example is set up slightly differently to how you may see other examples, in that there is a holding class called </font><font face="Arial"><font color="#2b91af">RESTEmailService</font></font><font face="Arial"> that contains no code. It inherits the interface class and a base class that contains all our main functions. This is due to a restriction in WCF regarding handling different request types and formats in the same service[1] I will go into this in more detail in another article.<br />
<br />
</font>      <font face="Arial">Our SendEmail function expects an iEmail object as a parameter and returns a response object. The first thing we done is define a </font><font face="Arial"><font color="#2b91af">OutgoingWebResponseContext </font></font><font face="Arial">object to enable us to send back a response status code to our client and we have an  </font><font face="Arial"><font color="#2b91af">IncomingWebRequestContext</font></font><font face="Arial"> object to provide access to the request from the client. We then process the email details and use a standard emailing function in our emails namespace to send the email. If our SendEmail function[5] returns false then we set the status code to InternalServerError and return the excepton text in our response.message property. Otherwise the status code remains at 200 (OK) and returns a message saying the email has been sent.<br />
<br />
<br />
<u>Web.Config</u><br />
</font>            <font face="Arial">We also need to define an endpoint in our web.config to describe how the service is accessed. This is contained in the &lt;system.serviceModel&gt; tag.<br />
</font>   <font face="Arial">To configure the above web service we would have something like:-<br />
</font><div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:300px;">   <font face="Arial"><font color="blue">      &lt;</font></font><font face="Arial"><font color="#a31515">system.serviceModel</font></font><font face="Arial"><font color="blue">&gt;</font></font><font face="Arial">
</font>   <font face="Arial"><font color="blue">    &lt;</font></font><font face="Arial"><font color="#a31515">serviceHostingEnvironment</font></font><font face="Arial"><font color="blue">&gt;</font></font><font face="Arial">
</font>   <font face="Arial"><font color="blue">      &lt;</font></font><font face="Arial"><font color="#a31515">baseAddressPrefixFilters</font></font><font face="Arial"><font color="blue">&gt;</font></font><font face="Arial">
</font>   <font face="Arial"><font color="blue">        &lt;</font></font><font face="Arial"><font color="#a31515">add </font></font><font face="Arial"><font color="red">prefix</font></font><font face="Arial"><font color="blue">=</font></font><font face="Arial">&quot;<font color="blue">http://www.yourdomain.com/webservices</font>&quot;<font color="blue"> /&gt;</font>
</font>   <font face="Arial"><font color="blue">      &lt;/</font></font><font face="Arial"><font color="#a31515">baseAddressPrefixFilters</font></font><font face="Arial"><font color="blue">&gt;</font></font><font face="Arial">
</font>   <font face="Arial"><font color="blue">    &lt;/</font></font><font face="Arial"><font color="#a31515">serviceHostingEnvironment</font></font><font face="Arial"><font color="blue">&gt;</font></font><font face="Arial">
</font>   <font face="Arial"><font color="blue">    &lt;</font></font><font face="Arial"><font color="#a31515">behaviors</font></font><font face="Arial"><font color="blue">&gt;</font></font><font face="Arial">
</font>   <font face="Arial"><font color="blue">                  &lt;</font></font><font face="Arial"><font color="#a31515">endpointBehaviors</font></font><font face="Arial"><font color="blue">&gt;</font></font><font face="Arial">
</font>   <font face="Arial"><font color="blue">                        &lt;</font></font><font face="Arial"><font color="#a31515">behavior</font></font><font face="Arial"><font color="red"> name</font></font><font face="Arial"><font color="blue">=</font></font><font face="Arial">&quot;<font color="blue">REST</font>&quot;<font color="blue">&gt;</font>
</font>   <font face="Arial"><font color="blue">                              &lt;</font></font><font face="Arial"><font color="#a31515">webHttp</font></font><font face="Arial"><font color="blue"> /&gt;</font></font><font face="Arial">
</font>   <font face="Arial"><font color="blue">                        &lt;/</font></font><font face="Arial"><font color="#a31515">behavior</font></font><font face="Arial"><font color="blue">&gt;</font></font><font face="Arial">
</font>   <font face="Arial"><font color="blue">                        &lt;</font></font><font face="Arial"><font color="#a31515">behavior </font></font><font face="Arial"><font color="red">name</font></font><font face="Arial"><font color="blue">=</font></font><font face="Arial">&quot;<font color="blue">AJAX</font>&quot;<font color="blue">&gt;</font>
</font>   <font face="Arial"><font color="blue">                              &lt;</font></font><font face="Arial"><font color="#a31515">enableWebScript</font></font><font face="Arial"><font color="blue"> /&gt;</font></font><font face="Arial">
</font>   <font face="Arial"><font color="blue">                        &lt;/</font></font><font face="Arial"><font color="#a31515">behavior</font></font><font face="Arial"><font color="blue">&gt;</font></font><font face="Arial">
</font>   <font face="Arial"><font color="blue">                  &lt;/</font></font><font face="Arial"><font color="#a31515">endpointBehaviors</font></font><font face="Arial"><font color="blue">&gt;</font></font><font face="Arial">
</font>   <font face="Arial"><font color="blue">            &lt;/</font></font><font face="Arial"><font color="#a31515">behaviors</font></font><font face="Arial"><font color="blue">&gt;</font></font><font face="Arial">
</font>   <font face="Arial"><font color="blue">            &lt;</font></font><font face="Arial"><font color="#a31515">services</font></font><font face="Arial"><font color="blue">&gt;</font></font><font face="Arial">
</font>   <font face="Arial"><font color="blue">      &lt;</font></font><font face="Arial"><font color="#a31515">service </font></font><font face="Arial"><font color="red">name</font></font><font face="Arial"><font color="blue">=</font></font><font face="Arial">&quot;<font color="blue">services.RESTEmailService</font>&quot;<font color="blue">&gt;</font>
</font>   <font face="Arial"><font color="blue">        &lt;</font></font><font face="Arial"><font color="#a31515">endpoint</font></font><font face="Arial"><font color="red"> address</font></font><font face="Arial"><font color="blue">=</font></font><font face="Arial">&quot;&quot; <font color="red">binding</font><font color="blue">=</font>&quot;<font color="blue">webHttpBinding</font>&quot;<font color="red"> behaviorConfiguration</font><font color="blue">=</font>&quot;<font color="blue">REST</font>&quot;<font color="red"> contract</font><font color="blue">=</font>&quot;<font color="blue">services.iRESTEmailService</font>&quot;<font color="blue"> /&gt;</font>
</font>   <font face="Arial"><font color="blue">      &lt;/</font></font><font face="Arial"><font color="#a31515">service</font></font><font face="Arial"><font color="blue">&gt;</font></font><font face="Arial">
</font>   <font face="Arial"><font color="blue">    &lt;/</font></font><font face="Arial"><font color="#a31515">services</font></font><font face="Arial"><font color="blue">&gt;</font></font><font face="Arial">
</font>   <font face="Arial"><font color="blue">      &lt;/</font></font><font face="Arial"><font color="#a31515">system.serviceModel</font></font><font face="Arial"><font color="blue">&gt;</font></font><font face="Arial">
</font></pre>
</div> <font face="Arial"><br />
</font>   <font face="Arial">This is defined in the &lt;configuration&gt; tag.<br />
</font>   <font face="Arial">I won’t go into huge detail here as the screencasts I suggested give a better explanation of what goes where and why. The basic details to note are the name attribute of our &lt;service&gt; tag is the same as the Service attribute in the ServiceHost declaration and the contract on the endpoint is the namespace (services) and the name of our interface ServiceContract in our code behind file.<br />
<br />
<u>Testing the web service</u><br />
</font>         <font face="Arial">To test the service, I would suggest downloading Fiddler[6] which enables us to examine the HTTP requests and responses. Once installed and Open, find and click on the Request Builder tab. If not there already, in the Request Headers box add a separate line with the following code:-<br />
</font>   <font face="Arial">Content-Type: text/xml<br />
<br />
</font>      <font face="Arial">Change the dropdown to GET and then type in the textbox <a href="http://www.yourdomain.com/pathtowebservice/RESTEmail.svc/get" target="_blank">http://www.yourdomain.com/pathtowebs...TEmail.svc/get</a><br />
<br />
</font>      <font face="Arial">In the left column (WebSessions) you should see a request to your webservice. It should be the last one in the list as the most recent. Once a response has been received, hopefully with a 200 status code, double click on it. This should take you to the Inspectors tab. In the bottom box, you should see the response received from the server which should be an XML format of our iEmail DataContract. Click on the Raw view to see the raw data returned from our GET service. You will notice that only the properties decorated with the [DataMember] attribute in our DataContract are returned. Highlight the body of the response (just the XML part starting &lt;iEmail) and copy that into an XML file in Visual Studio. This just makes it easier to format it and change the values. Put each element on a new line and then change the values of each element to make a valid simple email to yourself.<br />
<br />
</font>      <font face="Arial">Something like:-<br />
</font><div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:144px;">   <font face="Arial"><font color="blue">&lt;</font></font><font face="Arial"><font color="#a31515">iEmail</font></font><font face="Arial"><font color="red"> xmlns</font></font><font face="Arial"><font color="blue">=</font></font><font face="Arial">&quot;<font color="blue">http://schemas.datacontract.org/2004/07/services</font>&quot; <font color="red">xmlns:i</font><font color="blue">=</font>&quot;<font color="blue">http://www.w3.org/2001/XMLSchema-instance</font>&quot;<font color="blue">&gt;</font>
</font>   <font face="Arial"><font color="blue">  &lt;</font></font><font face="Arial"><font color="#a31515">emailFrom</font></font><font face="Arial"><font color="blue">&gt;</font></font><font face="Arial">anotheremail@domain.com<font color="blue">&lt;/</font><font color="#a31515">emailFrom</font><font color="blue">&gt;</font>
</font>   <font face="Arial"><font color="blue">  &lt;</font></font><font face="Arial"><font color="#a31515">emailTo</font></font><font face="Arial"><font color="blue">&gt;</font></font><font face="Arial">youremail@yourdomain.com<font color="blue">&lt;/</font><font color="#a31515">emailTo</font><font color="blue">&gt;</font>
</font>   <font face="Arial"><font color="blue">  &lt;</font></font><font face="Arial"><font color="#a31515">message</font></font><font face="Arial"><font color="blue">&gt;</font></font><font face="Arial">test message<font color="blue">&lt;/</font><font color="#a31515">message</font><font color="blue">&gt;</font>
</font>   <font face="Arial"><font color="blue">  &lt;</font></font><font face="Arial"><font color="#a31515">own</font></font><font face="Arial"><font color="blue">&gt;</font></font><font face="Arial">false<font color="blue">&lt;/</font><font color="#a31515">own</font><font color="blue">&gt;</font>
</font>   <font face="Arial"><font color="blue">  &lt;</font></font><font face="Arial"><font color="#a31515">priority</font></font><font face="Arial"><font color="blue">&gt;</font></font><font face="Arial">Normal</font><font face="Arial"><font color="blue">&lt;/</font></font><font face="Arial"><font color="#a31515">priority</font></font><font face="Arial"><font color="blue">&gt;</font></font><font face="Arial">
</font>   <font face="Arial"><font color="blue">  &lt;</font></font><font face="Arial"><font color="#a31515">read</font></font><font face="Arial"><font color="blue">&gt;</font></font><font face="Arial">false<font color="blue">&lt;/</font><font color="#a31515">read</font><font color="blue">&gt;</font>
</font>   <font face="Arial"><font color="blue">  &lt;</font></font><font face="Arial"><font color="#a31515">subject</font></font><font face="Arial"><font color="blue">&gt;</font></font><font face="Arial">test subject<font color="blue">&lt;/</font><font color="#a31515">subject</font><font color="blue">&gt;</font>
</font>   <font face="Arial"><font color="blue">&lt;/</font></font><font face="Arial"><font color="#a31515">iEmail</font></font><font face="Arial"><font color="blue">&gt;</font></font><font face="Arial">
</font></pre>
</div> <font face="Arial"><br />
</font>      <font face="Arial">Highlight this XML code, go back into Fiddler, click on the Request Builder tab again and paste the XML into the Request Body box. Again, make sure the Request Headers contains the Content-Type: text/xml line and the address is <a href="http://www.yourdomain.com/pathtowebservice/RESTEmail.svc/get" target="_blank">http://www.yourdomain.com/pathtowebs...TEmail.svc/get</a><br />
<br />
</font>      <font face="Arial">You also need to make sure you change the dropdown to PUT as we are going to use the PUT request to send our email.<br />
<br />
</font>      <font face="Arial">Click Execute and you should see the session appear in the left hand list. If all is well, you should get a response status code of 200, which means it has been successful. If you receive anything other than 200, double click on the session to examine the Raw response and to see any error message that may have been returned.<br />
<br />
<u>Consuming the web service</u><br />
</font>         <font face="Arial">The service above is not AJAX enabled at the moment, so you couldn’t call it from the same domain using a client script at the moment. I will come onto that in the next article.<br />
<br />
<u>Calling the service from a different domain</u><br />
</font>         <font face="Arial">You can call this service from an external domain, either via an aspx or PHP page.<br />
<br />
</font>      <font face="Arial">As we are using webHttp to define the service, we need to make HttpRequests to it and handle the HttpResponses that are returned. To do this in an ASP.NET page, I used the following code:-<br />
</font><div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:372px;">      <font face="Arial"><font color="blue">using</font></font><font face="Arial"> System;
</font>   <font face="Arial"><font color="blue">using</font></font><font face="Arial"> System.Text;
</font>   <font face="Arial"><font color="blue">using</font></font><font face="Arial"> System.Xml;
</font>   <font face="Arial"><font color="blue">using</font></font><font face="Arial"> Microsoft.VisualBasic;
</font>   <font face="Arial"><font color="blue">using</font></font><font face="Arial"> System.Web;
</font>   <font face="Arial"><font color="blue">using</font></font><font face="Arial"> System.Net;
</font>   <font face="Arial"><font color="blue">using</font></font><font face="Arial"> System.IO;


</font>         <font face="Arial"><font color="blue">partial</font></font><font face="Arial"> <font color="blue">class</font> <font color="#2b91af">testc</font> : System.Web.UI.<font color="#2b91af">Page</font>
</font>   <font face="Arial">{

</font>      <font face="Arial">    <font color="blue">public</font> <font color="blue">void</font> Page_Load()
</font>   <font face="Arial">    {
</font>   <font face="Arial"><font color="green">//create an instance of an HttpWebRequest (from System.Net </font></font><font face="Arial">
</font>   <font face="Arial"><font color="green">  //namespace) and create a WebRequest to our PUT service</font></font><font face="Arial">
</font>   <font face="Arial">        <font color="#2b91af">HttpWebRequest</font> myRequest = (<font color="#2b91af">HttpWebRequest</font>)<font color="#2b91af">WebRequest</font>.Create(<font color="#a31515">&quot;http://www.domain.com/webservices/RESTEmail.svc/get&quot;</font>);
</font>   <font face="Arial"><font color="green">  //set the request method to PUT</font></font><font face="Arial">
</font>   <font face="Arial">        myRequest.Method = <font color="#a31515">&quot;PUT&quot;</font>;
</font>   <font face="Arial"><font color="green">  //set the ContentType to text/xml</font></font><font face="Arial">
</font>   <font face="Arial">        myRequest.ContentType = <font color="#a31515">&quot;text/xml&quot;</font>;
</font>   <font face="Arial"><font color="green">  //Build our XML request body using a stringbuilder</font></font><font face="Arial">
</font>   <font face="Arial">        <font color="#2b91af">StringBuilder</font> xmlRequest = <font color="blue">new</font> <font color="#2b91af">StringBuilder</font>();

</font>      <font face="Arial">  <font color="green">//Always run web service calls inside Try…Catch just incase</font>
</font>   <font face="Arial"><font color="green">  //the server handling the web service is down or not responding</font></font><font face="Arial">
</font>   <font face="Arial">        <font color="blue">try</font>
</font>   <font face="Arial">        {
</font>   <font face="Arial">            xmlRequest.Append(<font color="#a31515">&quot;&lt;iEmail xmlns=\&quot;http://schemas.datacontract.org/2004/07/services\&quot; xmlns:i=\&quot;http://www.w3.org/2001/XMLSchema-instance\&quot;&gt;&quot;</font>);
</font>   <font face="Arial">            xmlRequest.Append(<font color="#a31515">&quot;&lt;emailFrom&gt;yourname@domain1.com&lt;/emailFrom&gt;&quot;</font>);
</font>   <font face="Arial">            xmlRequest.Append(<font color="#a31515">&quot;&lt;emailTo&gt;person@domain.com&lt;/emailTo&gt;&quot;</font>);
</font>   <font face="Arial">            xmlRequest.Append(<font color="#a31515">&quot;&lt;message&gt;test message&lt;/message&gt;&quot;</font>);
</font>   <font face="Arial">            xmlRequest.Append(<font color="#a31515">&quot;&lt;own&gt;false&lt;/own&gt;&quot;</font>);
</font>   <font face="Arial">            xmlRequest.Append(<font color="#a31515">&quot;&lt;priority&gt;Normal&lt;/priority&gt;&quot;</font>);
</font>   <font face="Arial">            xmlRequest.Append(<font color="#a31515">&quot;&lt;read&gt;false&lt;/read&gt;&quot;</font>);
</font>   <font face="Arial">            xmlRequest.Append(<font color="#a31515">&quot;&lt;subject&gt;test subject&lt;/subject&gt;&quot;</font>);
</font>   <font face="Arial">            xmlRequest.Append(<font color="#a31515">&quot;&lt;/iEmail&gt;&quot;</font>);

</font>      <font face="Arial"><font color="green">// As we’re using a PUT request we must define the </font></font><font face="Arial">
</font>   <font face="Arial"><font color="green">      // ContentLength which we get by checking the length of our </font></font><font face="Arial">
</font>   <font face="Arial"><font color="green">// StringBuilder</font></font><font face="Arial">
</font>   <font face="Arial">            myRequest.ContentLength = xmlRequest.Length;
</font>   <font face="Arial">            //<font color="green">Set a Stream object as the HttpRequest.GetRequestStream</font>
</font>   <font face="Arial">            <font color="#2b91af">Stream</font> mystream = myRequest.GetRequestStream();
</font>   <font face="Arial"><font color="green">// Create a new writer to pass our request to the web </font></font><font face="Arial">
</font>   <font face="Arial"><font color="green">// service</font></font><font face="Arial">
</font>   <font face="Arial">            <font color="#2b91af">StreamWriter</font> myRequestStream = <font color="blue">new</font> <font color="#2b91af">StreamWriter</font>(mystream);
</font>   <font face="Arial">            <font color="green">// Write the XML to the stream</font>
</font>   <font face="Arial">            myRequestStream.Write(xmlRequest.ToString());
</font>   <font face="Arial">            <font color="green">// Flush out the data in our Stream</font>
</font>   <font face="Arial">            myRequestStream.Flush();
</font>   <font face="Arial">            myRequestStream.Close();

</font>      <font face="Arial">            <font color="green">// Create an instance of an HttpWebResponse to receive the</font>
</font>   <font face="Arial"><font color="green">// result from our webservice</font></font><font face="Arial">
</font>   <font face="Arial">            <font color="#2b91af">HttpWebResponse</font> myResponse = (<font color="#2b91af">HttpWebResponse</font>)myRequest.GetResponse();
</font>   <font face="Arial">            <font color="green">// Write the statuscode to the screen. Should be “OK”</font>
</font>   <font face="Arial">            <font color="#2b91af">HttpContext</font>.Current.Response.Write(myResponse.StatusCode);
</font>   <font face="Arial">        }
</font>   <font face="Arial">        <font color="blue">catch</font>(<font color="#2b91af">Exception</font> ex)
</font>   <font face="Arial">        {
</font>   <font face="Arial">            <font color="#2b91af">HttpContext</font>.Current.Response.Write(ex.ToString());
</font>   <font face="Arial">;        }

</font>      <font face="Arial">    }

</font>      <font face="Arial">}
</font></pre>
</div> <font face="Arial"><br />
</font>      <font face="Arial">I found making an HTTP call using PHP to be a lot harder, but I then managed to find an XMLHttpRequest class[7] that uses cURL to send and receive requests. I also located a StringBuilder class[8] to make it easier to build the XML request body. So, the PHP page I constructed was something like this:-<br />
<div class="bbcode_container">
	<div class="bbcode_description">PHP Code:</div>
	<div class="bbcode_code"style="height:372px;"><code><code><span style="color: #000000">
&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">&lt;?php<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">include_once(</span><span style="color: #DD0000">'class.StringBuilder.php'</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;include_once(</span><span style="color: #DD0000">'class.XMLHttpRequest.php'</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try<br />&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$xmlRequest&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">StringBuilder</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$xmlRequest</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">Append</span><span style="color: #007700">(</span><span style="color: #DD0000">"&lt;iEmail&nbsp;xmlns='http://schemas.datacontract.org/2004/07/services'&nbsp;xmlns:i='http://www.w3.org/2001/XMLSchema-instance'&gt;"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$xmlRequest</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">Append</span><span style="color: #007700">(</span><span style="color: #DD0000">"&lt;emailFrom&gt;yourname@domain1.com&lt;/emailFrom&gt;"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$xmlRequest</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">Append</span><span style="color: #007700">(</span><span style="color: #DD0000">"&lt;emailTo&gt;person@domain.com&lt;/emailTo&gt;"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$xmlRequest</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">Append</span><span style="color: #007700">(</span><span style="color: #DD0000">"&lt;message&gt;test&nbsp;message&lt;/message&gt;"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$xmlRequest</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">Append</span><span style="color: #007700">(</span><span style="color: #DD0000">"&lt;own&gt;false&lt;/own&gt;"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$xmlRequest</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">Append</span><span style="color: #007700">(</span><span style="color: #DD0000">"&lt;priority&gt;Normal&lt;/priority&gt;"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$xmlRequest</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">Append</span><span style="color: #007700">(</span><span style="color: #DD0000">"&lt;read&gt;false&lt;/read&gt;"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$xmlRequest</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">Append</span><span style="color: #007700">(</span><span style="color: #DD0000">"&lt;subject&gt;test&nbsp;subject&lt;/subject&gt;"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$xmlRequest</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">Append</span><span style="color: #007700">(</span><span style="color: #DD0000">"&lt;/iEmail&gt;"</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$request&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">XMLHttpRequest</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$request</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">open</span><span style="color: #007700">(</span><span style="color: #DD0000">"PUT"</span><span style="color: #007700">,</span><span style="color: #DD0000">"http://www.domain.com/webservices/RESTEmail.svc/get"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$request</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setRequestHeader</span><span style="color: #007700">(</span><span style="color: #DD0000">"Content-Type"</span><span style="color: #007700">,</span><span style="color: #DD0000">"text/xml"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$request</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setRequestHeader</span><span style="color: #007700">(</span><span style="color: #DD0000">"Content-Length"</span><span style="color: #007700">,</span><span style="color: #0000BB">$xmlRequest</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">Length</span><span style="color: #007700">());<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$request</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">send</span><span style="color: #007700">(</span><span style="color: #0000BB">$xmlRequest</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">ToString</span><span style="color: #007700">());<br />&nbsp;&nbsp;&nbsp;print&nbsp;</span><span style="color: #0000BB">$request</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">statusText</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;catch(</span><span style="color: #0000BB">HttpException&nbsp;$ex</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;print&nbsp;</span><span style="color: #0000BB">$ex</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">?&gt;</span>
</span>
</code></code></div>
</div> </font>   <font face="Arial">I’m not a PHP expert so this is a very simple example. You could include references to form elements etc. to populate the object<br />
<br />
</font><font face="Arial">The next article will cover making this web service AJAX enabled and providing different request and response formats.<br />
<br />
</font>      <font face="Arial"><u>References</u><br />
<br />
</font>      <font face="Arial">1) </font><font face="Arial"><a href="http://www.west-wind.com/WebLog/posts/310747.aspx" target="_blank"><font color="#000000">http://www.west-wind.com/WebLog/posts/310747.aspx</font></a><br />
</font>   <font face="Arial">2) </font><font face="Arial"><a href="http://channel9.msdn.com/posts/RobBagby/" target="_blank">RobBagby | Posts | Channel 9</a><br />
</font>   <font face="Arial">3) </font><font face="Arial"><a href="http://channel9.msdn.com/posts/RobBagby/deCast-Creating-a-HI-REST-GET-Service-with-WCF-35/" target="_blank">deCast - Creating a HI-REST GET Service with WCF 3.5 | RobBagby | Channel 9</a><br />
</font>   <font face="Arial">4) </font><font face="Arial"><a href="http://channel9.msdn.com/posts/RobBagby/deCast-Creating-a-HI-REST-PUT-Service-That-Exposes-Insert-and-Update/" target="_blank">deCast - Creating a HI-REST PUT Service That Exposes Insert and Update | RobBagby | Channel 9</a><br />
</font>   <font face="Arial">5) </font><font face="Arial"><a href="http://www.developerbarn.com/net-code-samples/1453-email-class.html" target="_blank">http://www.developerbarn.com/net-cod...ail-class.html</a><br />
</font>   <font face="Arial">6) </font><font face="Arial"><a href="http://www.fiddlertool.com/Fiddler2/version.asp" target="_blank">Fiddler Web Debugger - Freeware HTTP(S) debugging tool</a><br />
</font>   <font face="Arial">7) </font><font face="Arial"><a href="http://www.moonlight21.com/class-XMLHttpRequest-php" target="_blank">PHP Class XMLHttpRequest (XMLHttpRequest emulator using cURL) | Moonlight21</a><br />
</font>   <font face="Arial">8) </font><font face="Arial"><a href="http://www.pedrocorreia.net/mySnippets/php/PHPStringBuilder" target="_blank">A Basic PHP StringBuilder - pedrocorreia.net</a><br />
</font></blockquote>

 ]]></content:encoded>
			<dc:creator>richyrich</dc:creator>
			<guid isPermaLink="true">http://www.developerbarn.com/blogs/richyrich/26-convert-asmx-file-wcf-svc-file-create-simple-api-web-service.html</guid>
		</item>
		<item>
			<title>Convert .asmx file to WCF .svc file to create simple API web service</title>
			<link>http://www.developerbarn.com/blogs/richyrich/25-convert-asmx-file-wcf-svc-file-create-simple-api-web-service.html</link>
			<pubDate>Tue, 20 Oct 2009 02:01:11 GMT</pubDate>
			<description>2) A simple .asmx file and calling a function 
 
This is part of a series of blogs. The others are:- 
1) Introduction...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore"><font face="Arial"><font size="2">2) A simple .asmx file and calling a function<br />
<br />
</font></font><font face="Arial">This is part of a series of blogs. The others are:-<br />
1) <a href="http://www.developerbarn.com/blogs/richyrich/24-convert-asmx-file-wcf-svc-file-create-simple-api-web-service.html" target="_blank">Introduction</a><br />
3) <a href="http://www.developerbarn.com/blogs/richyrich/26-convert-asmx-file-wcf-svc-file-create-simple-api-web-service.html" target="_blank">Converting a .asmx file to WCF .svc file</a><br />
<br />
</font>     <font face="Arial"><font size="2">The .asmx file I started with probably isn’t a great example of something you’d want as a web service, but it was just something I was working on at the time and I think it’s complicated enough to enable you to develop a variety of different applicable WCF services. What I have is an asmx file that sends an email based on parameters passed to it; who it’s to, who it’s from, subject, message etc.<br />
<br />
</font></font>      <font face="Arial"><font size="2">.asmx code behind<br />
</font></font><div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:372px;">   <font face="Arial"><font size="2"><font color="blue">using</font></font></font><font face="Arial"><font size="2"> System;
</font></font>   <font face="Arial"><font size="2"><font color="blue">using</font></font></font><font face="Arial"><font size="2"> System.Collections.Generic;
</font></font>   <font face="Arial"><font size="2"><font color="blue">using</font></font></font><font face="Arial"><font size="2"> System.Linq;
</font></font>   <font face="Arial"><font size="2"><font color="blue">using</font></font></font><font face="Arial"><font size="2"> System.Web;
</font></font>   <font face="Arial"><font size="2"><font color="blue">using</font></font></font><font face="Arial"><font size="2"> System.Web.Services;
</font></font>   <font face="Arial"><font size="2"><font color="green">//this next namespace is my own.It basically just contains a function to wire up an email and send it</font></font></font><font face="Arial"><font size="2">
</font></font>   <font face="Arial"><font size="2"><font color="green">//It accepts an email class object as a parameter. This class just mirrors the iEmail class here.</font></font></font><font face="Arial"><font size="2">
</font></font>   <font face="Arial"><font size="2"><font color="blue">using</font></font></font><font face="Arial"><font size="2"> mynamespace.App.BLL.Emails;

</font></font>      <font face="Arial"><font size="2"><font color="gray">///</font></font></font><font face="Arial"><font size="2"><font color="gray">&lt;summary&gt;</font></font></font><font face="Arial"><font size="2">
</font></font>   <font face="Arial"><font size="2"><font color="gray">///</font></font></font><font face="Arial"><font size="2"><font color="green"> Summary description for emailing</font></font></font><font face="Arial"><font size="2">
</font></font>   <font face="Arial"><font size="2"><font color="gray">///</font></font></font><font face="Arial"><font size="2"><font color="gray">&lt;/summary&gt;</font></font></font><font face="Arial"><font size="2">
</font></font>   <font face="Arial"><font size="2">[<font color="#2b91af">WebService</font>(Namespace = <font color="#a31515">&quot;http://tempuri.org/&quot;</font>)]
</font></font>   <font face="Arial"><font size="2">[<font color="#2b91af">WebServiceBinding</font>(ConformsTo = <font color="#2b91af">WsiProfiles</font>.BasicProfile1_1)]
</font></font>   <font face="Arial"><font size="2"><font color="green">// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. </font></font></font><font face="Arial"><font size="2">
</font></font>   <font face="Arial"><font size="2">[System.Web.Script.Services.<font color="#2b91af">ScriptService</font>]
</font></font>   <font face="Arial"><font size="2"><font color="blue">public</font></font></font><font face="Arial"><font size="2"> <font color="blue">class</font> <font color="#2b91af">emailingService</font> : System.Web.Services.<font color="#2b91af">WebService</font> {

</font></font>      <font face="Arial"><font size="2">    <font color="blue">public</font> emailingService () {

</font></font>      <font face="Arial"><font size="2">        <font color="green">//Uncomment the following line if using designed components </font>
</font></font>   <font face="Arial"><font size="2">        <font color="green">//InitializeComponent(); </font>
</font></font>   <font face="Arial"><font size="2">    }
</font></font>   <font face="Arial"><font size="2">    <font color="green">//We have one simple function that accepts an emailTo, emailFrom, Subject and Message parameter</font>
</font></font>   <font face="Arial"><font size="2">    [<font color="#2b91af">WebMethod</font>(MessageName=<font color="#a31515">&quot;SendEmailStr&quot;</font>)]
</font></font>   <font face="Arial"><font size="2">    <font color="blue">public</font> <font color="#2b91af">response</font> SendEmailStr(<font color="blue">string</font> loc, <font color="blue">string</font> emailTo, <font color="blue">string</font> emailFrom, <font color="blue">string</font> subject, <font color="blue">string</font> message)
</font></font>   <font face="Arial"><font size="2">    {
</font></font>   <font face="Arial"><font size="2">        <font color="#2b91af">response</font> response = <font color="blue">new</font> <font color="#2b91af">response</font>();
</font></font>   <font face="Arial"><font size="2">        response.loc = loc;

</font></font>      <font face="Arial"><font size="2">        <font color="#2b91af">email</font> newEmail = <font color="blue">new</font> <font color="#2b91af">email</font>();
</font></font>   <font face="Arial"><font size="2">        newEmail.emailTo.Add(<font color="blue">new</font> <font color="#2b91af">emailAdd</font>(emailTo));
</font></font>   <font face="Arial"><font size="2">        newEmail.emailFrom.Add(<font color="blue">new</font> <font color="#2b91af">emailAdd</font>(emailFrom));
</font></font>   <font face="Arial"><font size="2">        newEmail.subject = subject;
</font></font>   <font face="Arial"><font size="2">        newEmail.message = message;
</font></font>   <font face="Arial"><font size="2">        newEmail.priority = <font color="#a31515">&quot;Normal&quot;</font>;
</font></font>   <font face="Arial"><font size="2">        newEmail.read = <font color="blue">false</font>;
</font></font>   <font face="Arial"><font size="2">        newEmail.filepath = <font color="#a31515">&quot;&quot;</font>;

</font></font>      <font face="Arial"><font size="2">        newEmail.seperate = <font color="blue">false</font>;
</font></font>   <font face="Arial"><font size="2">        newEmail.isHTML = <font color="blue">true</font>;
</font></font>   <font face="Arial"><font size="2">        newEmail.sendAsync = <font color="blue">false</font>;

</font></font>      <font face="Arial"><font size="2">        <font color="blue">if</font> (!<font color="#2b91af">email</font>.SendEmail(newEmail))
</font></font>   <font face="Arial"><font size="2">        {
</font></font>   <font face="Arial"><font size="2">            response.error = <font color="blue">true</font>;
</font></font>   <font face="Arial"><font size="2">            response.message = <font color="#a31515">&quot;An error occurred whilst sending the email&lt;br /&gt;&quot;</font> + newEmail.err;
</font></font>   <font face="Arial"><font size="2">        }
</font></font>   <font face="Arial"><font size="2">        <font color="blue">else</font>
</font></font>   <font face="Arial"><font size="2">        {
</font></font>   <font face="Arial"><font size="2">            response.error = <font color="blue">false</font>;
</font></font>   <font face="Arial"><font size="2">            response.message = <font color="#a31515">&quot;Your email has been sent&quot;</font>;
</font></font>   <font face="Arial"><font size="2">        }
</font></font>   <font face="Arial"><font size="2">        <font color="blue">return</font> response;
</font></font>   <font face="Arial"><font size="2">    }

</font></font>      <font face="Arial"><font size="2">    <font color="green">//And another function that accepts an iEmail object as a parameter</font>
</font></font>   <font face="Arial"><font size="2">    [<font color="#2b91af">WebMethod</font>(MessageName=<font color="#a31515">&quot;SendEmailObj&quot;</font>)]
</font></font>   <font face="Arial"><font size="2">    <font color="blue">public</font> <font color="#2b91af">response</font> SendEmailObj(<font color="blue">string</font> loc, <font color="#2b91af">iEmail</font> oEmail)
</font></font>   <font face="Arial"><font size="2">    {
</font></font>   <font face="Arial"><font size="2">        <font color="#2b91af">response</font> response = <font color="blue">new</font> <font color="#2b91af">response</font>();
</font></font>   <font face="Arial"><font size="2">        response.loc = loc;

</font></font>      <font face="Arial"><font size="2">        <font color="#2b91af">email</font> newEmail = <font color="blue">new</font> <font color="#2b91af">email</font>();
</font></font>   <font face="Arial"><font size="2">        newEmail.emailTo.Add(<font color="blue">new</font> <font color="#2b91af">emailAdd</font>(oEmail.emailTo));
</font></font>   <font face="Arial"><font size="2">        newEmail.emailFrom.Add(<font color="blue">new</font> <font color="#2b91af">emailAdd</font>(oEmail.emailFrom));
</font></font>   <font face="Arial"><font size="2">        newEmail.subject = oEmail.subject;
</font></font>   <font face="Arial"><font size="2">        newEmail.message = oEmail.message;
</font></font>   <font face="Arial"><font size="2">        newEmail.priority = oEmail.priority;
</font></font>   <font face="Arial"><font size="2">        newEmail.read = oEmail.read;
</font></font>   <font face="Arial"><font size="2">        newEmail.filepath = <font color="#a31515">&quot;&quot;</font>;

</font></font>      <font face="Arial"><font size="2">        newEmail.seperate = <font color="blue">false</font>;
</font></font>   <font face="Arial"><font size="2">        newEmail.isHTML = <font color="blue">true</font>;
</font></font>   <font face="Arial"><font size="2">        newEmail.sendAsync = <font color="blue">false</font>;

</font></font>      <font face="Arial"><font size="2">        <font color="blue">if</font> (!<font color="#2b91af">email</font>.SendEmail(newEmail))
</font></font>   <font face="Arial"><font size="2">        {
</font></font>   <font face="Arial"><font size="2">            response.error = <font color="blue">true</font>;
</font></font>   <font face="Arial"><font size="2">            response.message = <font color="#a31515">&quot;An error occurred whilst sending the email&lt;br /&gt;&quot;</font> + newEmail.err;
</font></font>   <font face="Arial"><font size="2">        }
</font></font>   <font face="Arial"><font size="2">        <font color="blue">else</font>
</font></font>   <font face="Arial"><font size="2">        {
</font></font>   <font face="Arial"><font size="2">            response.error = <font color="blue">false</font>;
</font></font>   <font face="Arial"><font size="2">            response.message = <font color="#a31515">&quot;Your email has been sent&quot;</font>;
</font></font>   <font face="Arial"><font size="2">        }
</font></font>   <font face="Arial"><font size="2">        <font color="blue">return</font> response;
</font></font>   <font face="Arial"><font size="2">    }

</font></font>      <font face="Arial"><font size="2">}

</font></font>      <font face="Arial"><font size="2"><font color="green">//This class will be exposed to our client once we wire up the web service to our page</font></font></font><font face="Arial"><font size="2">
</font></font>   <font face="Arial"><font size="2"><font color="blue">public</font></font></font><font face="Arial"><font size="2"> <font color="blue">class</font> <font color="#2b91af">iEmail</font>
</font></font>   <font face="Arial"><font size="2">{
</font></font>   <font face="Arial"><font size="2">    <font color="blue">public</font> iEmail()
</font></font>   <font face="Arial"><font size="2">    {
</font></font>   <font face="Arial"><font size="2">    }

</font></font>      <font face="Arial"><font size="2">    <font color="blue">public</font> <font color="blue">string</font> emailTo { <font color="blue">get</font>; <font color="blue">set</font>; }
</font></font>   <font face="Arial"><font size="2">    <font color="blue">public</font> <font color="blue">string</font> emailFrom { <font color="blue">get</font>; <font color="blue">set</font>; }
</font></font>   <font face="Arial"><font size="2">    <font color="blue">public</font> <font color="blue">string</font> emailCc { <font color="blue">get</font>; <font color="blue">set</font>; }
</font></font>   <font face="Arial"><font size="2">    <font color="blue">public</font> <font color="blue">string</font> emailBcc { <font color="blue">get</font>; <font color="blue">set</font>; }
</font></font>   <font face="Arial"><font size="2">    <font color="blue">public</font> <font color="blue">string</font> subject { <font color="blue">get</font>; <font color="blue">set</font>; }
</font></font>   <font face="Arial"><font size="2">    <font color="blue">public</font> <font color="blue">string</font> message { <font color="blue">get</font>; <font color="blue">set</font>; }
</font></font>   <font face="Arial"><font size="2">    <font color="blue">public</font> <font color="blue">string</font> priority { <font color="blue">get</font>; <font color="blue">set</font>; }
</font></font>   <font face="Arial"><font size="2">    <font color="blue">public</font> <font color="blue">bool</font> read { <font color="blue">get</font>; <font color="blue">set</font>; }
</font></font>   <font face="Arial"><font size="2">    <font color="blue">public</font> <font color="blue">bool</font> own { <font color="blue">get</font>; <font color="blue">set</font>; }
</font></font>   <font face="Arial"><font size="2">    <font color="blue">public</font> <font color="blue">string</font> filepath { <font color="blue">get</font>; <font color="blue">set</font>; }

</font></font>      <font face="Arial"><font size="2">}

</font></font>      <font face="Arial"><font size="2"><font color="green">// A simple response class that will be returned to the client</font></font></font><font face="Arial"><font size="2">
</font></font>   <font face="Arial"><font size="2"><font color="blue">public</font></font></font><font face="Arial"><font size="2"> <font color="blue">class</font> <font color="#2b91af">response</font>
</font></font>   <font face="Arial"><font size="2">{
</font></font>   <font face="Arial"><font size="2">    <font color="blue">public</font> <font color="blue">bool</font> error { <font color="blue">get</font>; <font color="blue">set</font>; } <font color="green">//boolean value to return if an error occurs or not</font>
</font></font>   <font face="Arial"><font size="2">    <font color="blue">public</font> <font color="blue">string</font> loc { <font color="blue">set</font>; <font color="blue">get</font>; } <font color="green">//just enables the passing of the naming container that holds the various form objects</font>
</font></font>   <font face="Arial"><font size="2">    <font color="blue">public</font> <font color="blue">string</font> message { <font color="blue">get</font>; <font color="blue">set</font>; } <font color="green">//a message to return to the client</font>
</font></font>   <font face="Arial"><font size="2">}
</font></font></pre>
</div> <font face="Arial"><font size="2"><br />
</font></font>      <font face="Arial"><font size="2">I guess you wouldn’t really want to expose an emailing function as a web service due to potential issues with spammers highjacking etc. I just used this as an example as it provides for a number of different scenarios with web services and Windows Communication Foundation (WCF) You would also validate the values received into the functions to ensure they were valid etc. prior to the email being sent, but this is just meant as a simple example.<br />
<br />
</font></font>      <font face="Arial"><font size="2">Exposing the Web Service<br />
</font></font>   <font face="Arial"><font size="2">To wire this up to your page you need to include a ScriptManager control in your page.<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:36px;">  &lt;asp:ScriptManager id=”myScriptManager” runat=”server” EnablePartialRendering=”true” /&gt;</pre>
</div> </font></font>       <font face="Arial"><font size="2">If you use a master page, what you can do is include this control in your master page and then expose a public function to allow you to include a service from your page code. Something like:-<br />
</font></font>   <font face="Arial"><font size="2">Master Page<br />
</font></font><div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:84px;">   <font face="Arial"><font size="2"><font color="blue">public void</font></font></font><font face="Arial"><font size="2"> setService(</font></font><font face="Arial"><font size="2"><font color="#2b91af">ServiceReference</font></font></font><font face="Arial"><font size="2">item)
  {
     this.myScriptManager.Services.Add(item);
  }
</font></font></pre>
</div> <font face="Arial"><font size="2"><br />
<br />
 Your .aspx Page<br />
</font></font><div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:96px;">   <font face="Arial"><font size="2">    <font color="blue">void</font> Page_PreRender()
</font></font>   <font face="Arial"><font size="2">    {
</font></font>   <font face="Arial"><font size="2">        <font color="#2b91af">ServiceReference</font> service = <font color="blue">new</font> <font color="#2b91af">ServiceReference</font>(<font color="#a31515">&quot;/services/emailing.asmx&quot;</font>);
</font></font>   <font face="Arial"><font size="2">        Master.setService(service);
</font></font>   <font face="Arial"><font size="2">    }
</font></font></pre>
</div> <font face="Arial"><font size="2"><br />
</font></font>   <font face="Arial"><font size="2">Once this is done, your web service is exposed to the client.<br />
<br />
<br />
<u>Consuming the web service</u><br />
</font></font>            <font face="Arial"><font size="2">Suppose we had a page setup like this:-<br />
</font></font>   <font face="Arial"><font size="2">email.aspx<br />
</font></font><div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:372px;">      <font face="Arial"><font size="2"><font color="blue">&lt;</font></font></font><font face="Arial"><font size="2"><font color="#a31515">div</font></font></font><font face="Arial"><font size="2"> <font color="red">id</font><font color="blue">=&quot;mainHolder&quot;</font> <font color="red">style</font><font color="blue">=&quot;</font><font color="red">text-align</font>: <font color="blue">center</font>; <font color="red">margin-left</font>: <font color="blue">auto</font>; <font color="red">margin-right</font>: <font color="blue">auto</font>;<font color="red">width</font>: <font color="blue">100%</font>; <font color="red">overflow</font>: <font color="blue">hidden</font>;<font color="blue">&quot;&gt;</font>
</font></font>   <font face="Arial"><font size="2"><font color="blue">   &lt;</font></font></font><font face="Arial"><font size="2"><font color="#a31515">ul</font></font></font><font face="Arial"><font size="2"> <font color="red">class</font><font color="blue">=&quot;input-fields&quot;&gt;</font>
</font></font>   <font face="Arial"><font size="2">      <font color="blue">&lt;</font><font color="#a31515">li</font><font color="blue">&gt;</font>
</font></font>   <font face="Arial"><font size="2"><font color="blue">          &lt;</font></font></font><font face="Arial"><font size="2"><font color="#a31515">asp</font></font></font><font face="Arial"><font size="2"><font color="blue">:</font></font></font><font face="Arial"><font size="2"><font color="#a31515">Label</font></font></font><font face="Arial"><font size="2"> <font color="red">ID</font><font color="blue">=&quot;lblEmailTo&quot;</font> <font color="red">runat</font><font color="blue">=&quot;server&quot;</font> <font color="red">Text</font><font color="blue">=&quot;To:&quot;</font> <font color="red">CssClass</font><font color="blue">=&quot;blue336799_9&quot;</font> <font color="blue">/&gt;</font>
</font></font>   <font face="Arial"><font size="2"><font color="blue">          &lt;</font></font></font><font face="Arial"><font size="2"><font color="#a31515">asp</font></font></font><font face="Arial"><font size="2"><font color="blue">:</font></font></font><font face="Arial"><font size="2"><font color="#a31515">TextBox</font></font></font><font face="Arial"><font size="2"> <font color="red">ID</font><font color="blue">=&quot;txtEmailTo&quot;</font> <font color="red">runat</font><font color="blue">=&quot;server&quot;</font> <font color="red">CssClass</font><font color="blue">=&quot;textbox8&quot;</font> <font color="red">style</font><font color="blue">=&quot;</font><font color="red">color</font>:<font color="blue">#CCCCCC</font>;<font color="blue">&quot;</font> <font color="red">Width</font><font color="blue">=&quot;200px&quot;</font> <font color="red">MaxLength</font><font color="blue">=&quot;255&quot;</font> <font color="blue">/&gt;</font>
</font></font>   <font face="Arial"><font size="2">      <font color="blue">&lt;/</font><font color="#a31515">li</font><font color="blue">&gt;</font>
</font></font>   <font face="Arial"><font size="2">      <font color="blue">&lt;</font><font color="#a31515">li</font><font color="blue">&gt;</font>
</font></font>   <font face="Arial"><font size="2">          <font color="blue">&lt;</font><font color="#a31515">asp</font><font color="blue">:</font><font color="#a31515">Label</font> <font color="red">ID</font><font color="blue">=&quot;lblEmailFrom&quot;</font> <font color="red">runat</font><font color="blue">=&quot;server&quot;</font> <font color="red">Text</font><font color="blue">=&quot;From:&quot;</font> <font color="red">CssClass</font><font color="blue">=&quot;blue336799_9&quot;</font> <font color="blue">/&gt;</font>
</font></font>   <font face="Arial"><font size="2">          <font color="blue">&lt;</font><font color="#a31515">asp</font><font color="blue">:</font><font color="#a31515">TextBox</font> <font color="red">ID</font><font color="blue">=&quot;txtEmailFrom&quot;</font> <font color="red">runat</font><font color="blue">=&quot;server&quot;</font> <font color="red">CssClass</font><font color="blue">=&quot;textbox8&quot; </font><font color="red">Width</font><font color="blue">=&quot;200px&quot;</font> <font color="red">MaxLength</font><font color="blue">=&quot;255&quot;</font> <font color="blue">/&gt;</font>
</font></font>   <font face="Arial"><font size="2">      <font color="blue">&lt;/</font><font color="#a31515">li</font><font color="blue">&gt;</font>
</font></font>   <font face="Arial"><font size="2">      <font color="blue">&lt;</font><font color="#a31515">li</font><font color="blue">&gt;</font>
</font></font>   <font face="Arial"><font size="2">          <font color="blue">&lt;</font><font color="#a31515">asp</font><font color="blue">:</font><font color="#a31515">Label</font> <font color="red">ID</font><font color="blue">=&quot;lblSubject&quot;</font> <font color="red">runat</font><font color="blue">=&quot;server&quot;</font> <font color="red">Text</font><font color="blue">=&quot;Subject:&quot;</font> <font color="red">CssClass</font><font color="blue">=&quot;blue336799_9&quot;</font> <font color="blue">/&gt;</font>
</font></font>   <font face="Arial"><font size="2">          <font color="blue">&lt;</font><font color="#a31515">asp</font><font color="blue">:</font><font color="#a31515">TextBox</font> <font color="red">ID</font><font color="blue">=&quot;txtSubject&quot;</font> <font color="red">runat</font><font color="blue">=&quot;server&quot;</font> <font color="red">CssClass</font><font color="blue">=&quot;textbox8&quot;</font> <font color="red">Width</font><font color="blue">=&quot;200px&quot;</font> <font color="red">MaxLength</font><font color="blue">=&quot;255&quot;</font> <font color="blue">/&gt;</font>
</font></font>   <font face="Arial"><font size="2">      <font color="blue">&lt;/</font><font color="#a31515">li</font><font color="blue">&gt;</font>
</font></font>   <font face="Arial"><font size="2">      <font color="blue">&lt;</font><font color="#a31515">li</font><font color="blue">&gt;</font>
</font></font>   <font face="Arial"><font size="2">          <font color="blue">&lt;</font><font color="#a31515">fckEditor</font><font color="blue">:</font><font color="#a31515">FCKeditor</font> <font color="red">ID</font><font color="blue">=&quot;txtMessage&quot;</font> <font color="red">runat</font><font color="blue">=&quot;server&quot;</font> <font color="red">HtmlEncodeOutput</font><font color="blue">=&quot;true&quot;</font> <font color="red">UseBROnCarriageReturn</font><font color="blue">=&quot;true&quot; </font><font color="red">ToolbarSet</font><font color="blue">=&quot;myToolbar&quot;</font> <font color="red">BaseHref</font><font color="blue">=&quot;http://www.mydomain.com&quot;</font> <font color="red">Height</font><font color="blue">=&quot;350px&quot;</font> <font color="blue">/&gt;</font>
</font></font>   <font face="Arial"><font size="2">      <font color="blue">&lt;/</font><font color="#a31515">li</font><font color="blue">&gt;</font>
</font></font>   <font face="Arial"><font size="2">   <font color="blue">&lt;/</font><font color="#a31515">ul</font><font color="blue">&gt;</font>
</font></font>   <font face="Arial"><font size="2"><font color="blue"> &lt;/</font></font></font><font face="Arial"><font size="2"><font color="#a31515">div</font></font></font><font face="Arial"><font size="2"><font color="blue">&gt;</font></font></font><font face="Arial"><font size="2">
</font></font>   <font face="Arial"><font size="2"> <font color="blue">&lt;</font><font color="#a31515">div</font> <font color="red">id</font><font color="blue">=&quot;optionsHolder&quot;</font> <font color="red">style</font><font color="blue">=&quot;</font><font color="red">text-align</font>: <font color="blue">center</font>; <font color="red">margin-left</font>: <font color="blue">auto</font>; <font color="red">margin-right</font>: <font color="blue">auto</font>; <font color="red">width</font>: <font color="blue">100%</font>; <font color="red">overflow</font>: <font color="blue">hidden</font>;<font color="blue">&quot;&gt;</font>
</font></font>   <font face="Arial"><font size="2">   <font color="blue">&lt;</font><font color="#a31515">ul</font> <font color="red">class</font><font color="blue">=&quot;input-fields&quot;&gt;</font>
</font></font>   <font face="Arial"><font size="2">      <font color="blue">&lt;</font><font color="#a31515">li</font><font color="blue">&gt;</font>
</font></font>   <font face="Arial"><font size="2">          <font color="blue">&lt;</font><font color="#a31515">asp</font><font color="blue">:</font><font color="#a31515">Label</font> <font color="red">ID</font><font color="blue">=&quot;lblImportance&quot;</font> <font color="red">runat</font><font color="blue">=&quot;server&quot;</font> C<font color="red">ssClass</font><font color="blue">=&quot;blue336799_8&quot;</font> <font color="red">Text</font><font color="blue">=&quot;Importance:&quot;</font> <font color="blue">/&gt;</font>
</font></font>   <font face="Arial"><font size="2">          <font color="blue">&lt;</font><font color="#a31515">asp</font><font color="blue">:</font><font color="#a31515">DropDownList</font> <font color="red">ID</font><font color="blue">=&quot;ddlImportance&quot;</font> <font color="red">runat</font><font color="blue">=&quot;server&quot;</font> <font color="red">CssClass</font><font color="blue">=&quot;textbox8&quot;&gt;</font>
</font></font>   <font face="Arial"><font size="2">             <font color="blue">&lt;</font><font color="#a31515">asp</font><font color="blue">:</font><font color="#a31515">ListItem</font> <font color="red">Text</font><font color="blue">=&quot;Normal&quot;</font> <font color="red">Value</font><font color="blue">=&quot;normal&quot;</font> <font color="blue">/&gt;</font>
</font></font>   <font face="Arial"><font size="2">             <font color="blue">&lt;</font><font color="#a31515">asp</font><font color="blue">:</font><font color="#a31515">ListItem</font> <font color="red">Text</font><font color="blue">=&quot;Low&quot;</font> <font color="red">Value</font><font color="blue">=&quot;low&quot;</font> <font color="blue">/&gt;</font>
</font></font>   <font face="Arial"><font size="2">             <font color="blue">&lt;</font><font color="#a31515">asp</font><font color="blue">:</font><font color="#a31515">ListItem</font> <font color="red">Text</font><font color="blue">=&quot;High&quot;</font> <font color="red">Value</font><font color="blue">=&quot;high&quot;</font> <font color="blue">/&gt;</font>
</font></font>   <font face="Arial"><font size="2">          <font color="blue">&lt;/</font><font color="#a31515">asp</font><font color="blue">:</font><font color="#a31515">DropDownList</font><font color="blue">&gt;</font>
</font></font>   <font face="Arial"><font size="2">      <font color="blue">&lt;/</font><font color="#a31515">li</font><font color="blue">&gt;</font>
</font></font>   <font face="Arial"><font size="2">      <font color="blue">&lt;</font><font color="#a31515">li</font><font color="blue">&gt;</font>
</font></font>   <font face="Arial"><font size="2">          <font color="blue">&lt;</font><font color="#a31515">asp</font><font color="blue">:</font><font color="#a31515">Label</font> <font color="red">ID</font><font color="blue">=&quot;lblReadReceipt&quot;</font> <font color="red">runat</font><font color="blue">=&quot;server&quot;</font> <font color="red">CssClass</font><font color="blue">=&quot;blue336799_8&quot;</font> <font color="red">Text</font><font color="blue">=&quot;Read Receipt:&quot;</font> <font color="blue">/&gt;</font>
</font></font>   <font face="Arial"><font size="2">          <font color="blue">&lt;</font><font color="#a31515">asp</font><font color="blue">:</font><font color="#a31515">CheckBox</font> <font color="red">ID</font><font color="blue">=&quot;chkReadReceipt&quot;</font> <font color="red">runat</font><font color="blue">=&quot;server&quot;</font> <font color="blue">/&gt;</font>
</font></font>   <font face="Arial"><font size="2">      <font color="blue">&lt;/</font><font color="#a31515">li</font><font color="blue">&gt;</font>
</font></font>   <font face="Arial"><font size="2">      <font color="blue">&lt;</font><font color="#a31515">li</font><font color="blue">&gt;</font>
</font></font>   <font face="Arial"><font size="2">          <font color="blue">&lt;</font><font color="#a31515">asp</font><font color="blue">:</font><font color="#a31515">Label</font> <font color="red">ID</font><font color="blue">=&quot;lblOwn&quot;</font> <font color="red">runat</font><font color="blue">=&quot;server&quot;</font> <font color="red">CssClass</font><font color="blue">=&quot;blue336799_8&quot;</font> <font color="red">Text</font><font color="blue">=&quot;Copy to own email:&quot;</font> <font color="blue">/&gt;</font>
</font></font>   <font face="Arial"><font size="2">          <font color="blue">&lt;</font><font color="#a31515">asp</font><font color="blue">:</font><font color="#a31515">CheckBox</font> <font color="red">ID</font><font color="blue">=&quot;chkOwn&quot;</font> <font color="red">runat</font><font color="blue">=&quot;server&quot;</font> <font color="blue">/&gt;</font>
</font></font>   <font face="Arial"><font size="2">      <font color="blue">&lt;/</font><font color="#a31515">li</font><font color="blue">&gt;</font>
</font></font>   <font face="Arial"><font size="2">   <font color="blue">&lt;/</font><font color="#a31515">ul</font><font color="blue">&gt;</font>
</font></font>   <font face="Arial"><font size="2"><font color="blue">&lt;/</font></font></font><font face="Arial"><font size="2"><font color="#a31515">div</font></font></font><font face="Arial"><font size="2"><font color="blue">&gt;</font></font></font><font face="Arial"><font size="2">
</font></font>   <font face="Arial"><font size="2"><font color="blue">&lt;</font></font></font><font face="Arial"><font size="2"><font color="#a31515">div</font></font></font><font face="Arial"><font size="2"> <font color="red">id</font><font color="blue">=&quot;emailSendButton&quot;</font> <font color="red">class</font><font color="blue">=&quot;center_button&quot;</font> <font color="red">style</font><font color="blue">=&quot;</font><font color="red">padding-top</font>: <font color="blue">10px</font>;<font color="blue">&quot;&gt;</font>
</font></font>   <font face="Arial"><font size="2">   &lt;<font color="#a31515">button</font> <font color="red">id</font><font color="blue">=&quot;btnEmailSend&quot;</font> <font color="red">class</font><font color="blue">=&quot;button_25px_green&quot;</font> <font color="red">title</font><font color="blue">=&quot;Send Email&quot;</font> <font color="red">onclick</font><font color="blue">=&quot;return SendEmail('</font>&lt;%=this.txtEmailTo.NamingContainer.ClientID %&gt;<font color="blue">_');&quot;&gt;</font>Send Email<font color="blue">&lt;/</font><font color="#a31515">button</font><font color="blue">&gt;</font>
</font></font>   <font face="Arial"><font size="2"><font color="blue">&lt;/</font></font></font><font face="Arial"><font size="2"><font color="#a31515">div</font></font></font><font face="Arial"><font size="2"><font color="blue">&gt;</font></font></font><font face="Arial"><font size="2">
</font></font></pre>
</div> <font face="Arial"><font size="2"><br />
</font></font>   <font face="Arial"><font size="2"><font color="blue">This is just the relevant form code. You’ll need to add the page declarations etc.</font></font></font><font face="Arial"><font size="2"><br />
<br />
</font></font>      <font face="Arial"><font size="2"><font color="blue">Code Behind (email.aspx.cs)</font></font></font><font face="Arial"><font size="2"><br />
</font></font><div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:228px;">   <font face="Arial"><font size="2">    <font color="blue">void</font> Page_PreRender()
</font></font>   <font face="Arial"><font size="2">    {
</font></font>   <font face="Arial"><font size="2">        //Add the service reference to our master page, as shown above
</font></font>   <font face="Arial"><font size="2">        //This assumes the .asmx file is in a sub folder of our webroot
</font></font>   <font face="Arial"><font size="2">        //called services
</font></font>   <font face="Arial"><font size="2">        <font color="#2b91af">ServiceReference</font> service = <font color="blue">new</font> <font color="#2b91af">ServiceReference</font>(<font color="#a31515">&quot;/services/emailing.asmx&quot;</font>);
</font></font>   <font face="Arial"><font size="2">        Master.set_services(service);
</font></font>   <font face="Arial"><font size="2">    }

</font></font>      <font face="Arial"><font size="2">    <font color="blue">protected</font> <font color="blue">void</font> Page_Load(<font color="blue">object</font> sender, <font color="#2b91af">EventArgs</font> e)
</font></font>   <font face="Arial"><font size="2">    {
</font></font>   <font face="Arial"><font size="2">        //we also need to register our Javascript that will handle the calls to the webservice
</font></font>   <font face="Arial"><font size="2">        //This assumes the .js file is in a sub folder of our webroot
</font></font>   <font face="Arial"><font size="2">        //called js
</font></font>   <font face="Arial"><font size="2">        Page.ClientScript.RegisterClientScriptInclude(<font color="#a31515">&quot;sendemail.js&quot;</font>, <font color="#a31515">&quot;/js/sendemail.js&quot;</font>);
</font></font>   <font face="Arial"><font size="2">    }
</font></font></pre>
</div> <font face="Arial"><font size="2"><br />
</font></font>      <font face="Arial"><font size="2"><font color="blue">Our Javascript File</font></font></font><font face="Arial"><font size="2"><br />
</font></font><div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:372px;">   <font face="Arial"><font size="2"><font color="blue">//Function that is called by our button click. The parameter is the</font></font></font><font face="Arial"><font size="2">
</font></font>   <font face="Arial"><font size="2"><font color="blue">//naming container client id, which makes it easier to reference the</font></font></font><font face="Arial"><font size="2">
</font></font>   <font face="Arial"><font size="2"><font color="blue">//form elements</font></font></font><font face="Arial"><font size="2">
</font></font>   <font face="Arial"><font size="2"><font color="blue">function</font></font></font><font face="Arial"><font size="2"> SendEmail(loc) {
</font></font>   <font face="Arial"><font size="2">    <font color="blue">var</font> email = <font color="blue">new</font> iEmail();
</font></font>   <font face="Arial"><font size="2">    <font color="blue">var</font> emailto = document.getElementById(loc + <font color="#a31515">'txtEmailTo'</font>).value;
</font></font>   <font face="Arial"><font size="2">    email.emailTo = emailto;
</font></font>   <font face="Arial"><font size="2">    <font color="blue">var</font> emailfrom = document.getElementById(loc + <font color="#a31515">'txtEmailFrom'</font>).value;
</font></font>   <font face="Arial"><font size="2">    email.emailFrom = emailfrom;
</font></font>   <font face="Arial"><font size="2">    <font color="blue">var</font> subject = document.getElementById(loc + <font color="#a31515">'txtSubject'</font>).value;
</font></font>   <font face="Arial"><font size="2">    email.subject = subject;
</font></font>   <font face="Arial"><font size="2">    <font color="blue">var</font> oEditor = FCKeditorAPI.GetInstance(loc + <font color="#a31515">'txtMessage'</font>);
</font></font>   <font face="Arial"><font size="2">    <font color="blue">var</font> message = oEditor.GetXHTML();
</font></font>   <font face="Arial"><font size="2">    email.Message = message;
</font></font>   <font face="Arial"><font size="2">    <font color="blue">var</font> priority = document.getElementById(loc + <font color="#a31515">'ddlImportance'</font>).value;
</font></font>   <font face="Arial"><font size="2">    email.priority = priority;
</font></font>   <font face="Arial"><font size="2">    <font color="blue">var</font> read = document.getElementById(loc + <font color="#a31515">'chkReadReceipt'</font>).checked;
</font></font>   <font face="Arial"><font size="2">    email.read = read;
</font></font>   <font face="Arial"><font size="2">    <font color="blue">var</font> own = document.getElementById(loc + <font color="#a31515">'chkOwn'</font>).checked;
</font></font>   <font face="Arial"><font size="2">    email.own = own;
</font></font>   <font face="Arial"><font size="2">    //Call to our web service function SendEmailObj
</font></font>   <font face="Arial"><font size="2">    emailingService.SendEmailObj(loc, email, OnSendEmailComplete, OnError, OnTimeout);
</font></font>   <font face="Arial"><font size="2">    <font color="blue">return</font> <font color="blue">false</font>;
</font></font>   <font face="Arial"><font size="2">}

</font></font>      <font face="Arial"><font size="2"><font color="blue">function</font></font></font><font face="Arial"><font size="2"> OnSendEmailComplete(result) {
</font></font>   <font face="Arial"><font size="2">    
</font></font>   <font face="Arial"><font size="2">    <font color="blue">var</font> pgErr = document.getElementById(result.loc + <font color="#a31515">'pgError'</font>);
</font></font>   <font face="Arial"><font size="2">    <font color="blue">if</font> (result.error) {
</font></font>   <font face="Arial"><font size="2">        <font color="blue">var</font> pgErrHolder = document.getElementById(result.loc + <font color="#a31515">'pgErrorHolder'</font>);
</font></font>   <font face="Arial"><font size="2">        pgErr.style.display = <font color="#a31515">''</font>;
</font></font>   <font face="Arial"><font size="2">        <font color="blue">if</font> (result.message.indexOf(<font color="#a31515">'&lt;br /&gt;'</font>) != -1) {
</font></font>   <font face="Arial"><font size="2">            pgErrHolder.style.lineHeight = <font color="#a31515">'15px'</font>;
</font></font>   <font face="Arial"><font size="2">        } <font color="blue">else</font> {
</font></font>   <font face="Arial"><font size="2">            pgErrHolder.style.lineHeight = <font color="#a31515">'30px'</font>;
</font></font>   <font face="Arial"><font size="2">        }
</font></font>   <font face="Arial"><font size="2">        pgErrHolder.innerHTML = result.message;
</font></font>   <font face="Arial"><font size="2">    } <font color="blue">else</font> {
</font></font>   <font face="Arial"><font size="2">        pgErr.style.display = <font color="#a31515">'none'</font>;
</font></font>   <font face="Arial"><font size="2">        <font color="blue">var</font> pgNoErr = document.getElementById(result.loc + <font color="#a31515">'pgNoError'</font>);
</font></font>   <font face="Arial"><font size="2">        <font color="blue">var</font> pgNoErrHolder = document.getElementById(result.loc + <font color="#a31515">'pgNoErrorHolder'</font>);
</font></font>   <font face="Arial"><font size="2">        pgNoErr.style.display = <font color="#a31515">''</font>;
</font></font>   <font face="Arial"><font size="2">        pgNoErrHolder.innerHTML = result.message;
</font></font>   <font face="Arial"><font size="2">        document.getElementById(result.loc + <font color="#a31515">'txtEmailFrom'</font>).value = <font color="#a31515">''</font>;
</font></font>   <font face="Arial"><font size="2">        document.getElementById(result.loc + <font color="#a31515">'txtSubject'</font>).value = <font color="#a31515">''</font>;
</font></font>   <font face="Arial"><font size="2">        <font color="blue">var</font> oEditor = FCKeditorAPI.GetInstance(result.loc + <font color="#a31515">'txtMessage'</font>);
</font></font>   <font face="Arial"><font size="2">        oEditor.SetHTML(<font color="#a31515">''</font>);
</font></font>   <font face="Arial"><font size="2">        document.getElementById(result.loc + <font color="#a31515">'ddlImportance'</font>).selectedIndex = 0;
</font></font>   <font face="Arial"><font size="2">        document.getElementById(result.loc + <font color="#a31515">'chkReadReceipt'</font>).checked = <font color="blue">false</font>;
</font></font>   <font face="Arial"><font size="2">        document.getElementById(result.loc + <font color="#a31515">'chkOwn'</font>).checked = <font color="blue">false</font>;
</font></font>   <font face="Arial"><font size="2">    }
</font></font>   <font face="Arial"><font size="2">}

</font></font>      <font face="Arial"><font size="2"><font color="blue">function</font></font></font><font face="Arial"><font size="2"> OnError(result) {
</font></font>   <font face="Arial"><font size="2">    alert(<font color="#a31515">'An error occurred: '</font> + result);
</font></font>   <font face="Arial"><font size="2">    <font color="blue">return</font> <font color="blue">false</font>;
</font></font>   <font face="Arial"><font size="2">}

</font></font>      <font face="Arial"><font size="2"><font color="blue">function</font></font></font><font face="Arial"><font size="2"> OnTimeout(result) {
</font></font>   <font face="Arial"><font size="2">    alert(<font color="#a31515">'You were timed out'</font>);
</font></font>   <font face="Arial"><font size="2">    <font color="blue">return</font> <font color="blue">false</font>;
</font></font>   <font face="Arial"><font size="2">}
</font></font></pre>
</div> <font face="Arial"><font size="2"><br />
</font></font>      <font face="Arial"><font size="2">Our SendEmail JS function creates an instance of our web service iEmail object (var email = new iEmail(); ) and then we retrieve the values from our form elements to populate this object.<br />
</font></font>   <font face="Arial"><font size="2">The call to the web service function is referenced using the class . function name<br />
</font></font>   <font face="Arial"><font size="2">You must include the name of the JS function to handle the response from the web service after the parameters. In our case the JS function to handle the response is called OnSendEmailComplete. I have also included functions to handle OnError and OnTimeout.<br />
<br />
</font></font>   <font face="Arial"><font size="2">The OnSendEmailComplete function receives a parameter from the webservice that contains our response object (the return type of our web service function). To access the properties of the object we just use parameterName.PropertyName. In our case I’ve called the parameter result. So our 3 properties are error (boolean), loc(string) and message(string).<br />
</font></font>   <font face="Arial"><font size="2">We firstly check if an error occurred; if(result.error) and then display the relevant message. Our loc property just makes it easier to access the form elements again. I then just tidy up the form for the next call to the web service<br />
<br />
</font></font>      <font face="Arial"><font size="2"><u>Calling the service from a different domain</u><br />
</font></font>   <font face="Arial"><font size="2">You can also call this service from an external domain, either via an aspx or PHP page.<br />
<br />
</font></font>      <font face="Arial"><font size="2">To use the service in another ASP.NET site, you first need to add a reference to the serviceon your new site, in Visual Studio / Web Developer. Go to Solution Explorer, right click on the top level node and select Add Web Reference. In the URL box type the path to your web service <a href="http://www.yourdomain.com/services/yourservice.asmx" target="_blank"><font color="#000000">http://www.yourdomain.com/services/yourservice.asmx</font></a> and click Go. The web services it finds will be listed. Add a Web reference name. It normally defaults to com.yourdomain.www. I just changed mine to mynamespace.asmx.emailing<br />
</font></font>   <font face="Arial"><font size="2">You use this in your .aspx page by having a using / imports statement to your web reference. So, an example page might look something like:-<br />
</font></font><div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:372px;">   <font face="Arial"><font size="2"><font color="blue">using</font></font></font><font face="Arial"><font size="2"> System;
</font></font>   <font face="Arial"><font size="2"><font color="blue">using</font></font></font><font face="Arial"><font size="2"> System.Web;
</font></font>   <font face="Arial"><font size="2"><font color="blue">using</font></font></font><font face="Arial"><font size="2"> System.Web.UI;
</font></font>   <font face="Arial"><font size="2"><font color="blue">using</font></font></font><font face="Arial"><font size="2"> w3d.asmx.emailing;


</font></font>         <font face="Arial"><font size="2"><font color="blue">partial</font></font></font><font face="Arial"><font size="2"> <font color="blue">class</font> test : System.Web.UI.Page
</font></font>   <font face="Arial"><font size="2">{
</font></font>   <font face="Arial"><font size="2">    <font color="blue">public</font> <font color="blue">void</font> btnClick(<font color="blue">object s</font>, EventArgs e)
</font></font>   <font face="Arial"><font size="2">    {
</font></font>   <font face="Arial"><font size="2">        <font color="blue">emailingService </font>soapemail = n<font color="blue">ew</font> emailingService();
</font></font>   <font face="Arial"><font size="2">        <font color="blue">iEmail </font>iEmail = <font color="blue">New</font> iEmail();
</font></font>   <font face="Arial"><font size="2">        iEmail.emailTo = <font color="#a31515">&quot;youremail@domain.com&quot;;</font>
</font></font>   <font face="Arial"><font size="2">        iEmail.emailFrom = <font color="#a31515">&quot;anotheremail@anotherdomain.com&quot;;</font>
</font></font>   <font face="Arial"><font size="2">        iEmail.subject = <font color="#a31515">&quot;Your Subject&quot;;</font>
</font></font>   <font face="Arial"><font size="2">        iEmail.message = <font color="#a31515">&quot;Your  Message&quot;;</font>

</font></font>      <font face="Arial"><font size="2">        <font color="blue">response</font> response <font color="blue">=</font> <font color="blue">New</font> response();
</font></font>   <font face="Arial"><font size="2">        response = soapemail.SendEmailObj(<font color="#a31515">&quot;&quot;</font>, iEmail);

</font></font>      <font face="Arial"><font size="2">        <font color="blue">if(</font>response.error)
</font></font>   <font face="Arial"><font size="2">  {
</font></font>   <font face="Arial"><font size="2">            Label1.Text = <font color="#a31515">&quot;An error occurred&lt;br /&gt;&quot;</font> &amp; response.message;
</font></font>   <font face="Arial"><font size="2">        } <font color="blue">else {</font>
</font></font>   <font face="Arial"><font size="2">            Label1.Text = response.message;
</font></font>   <font face="Arial"><font size="2">        <font color="blue">}</font>


</font></font>         <font face="Arial"><font size="2">    <font color="blue">}</font>

</font></font>      <font face="Arial"><font size="2"><font color="blue">}</font></font></font><font face="Arial"><font size="2">
</font></font></pre>
</div> <font face="Arial"><font size="2"><br />
<br />
</font></font>         <font face="Arial"><font size="2">The PHP page can be constructed something like this, using PHP5 and the PHP_SOAP extension.[1]<br />
</font></font><div class="bbcode_container">
	<div class="bbcode_description">PHP Code:</div>
	<div class="bbcode_code"style="height:324px;"><code><code><span style="color: #000000">
&nbsp;&nbsp;&nbsp;&lt;html&gt;<br />&nbsp;&nbsp;&nbsp;&lt;head&gt;<br />&nbsp;&nbsp;&nbsp;&lt;/head&gt;<br />&nbsp;&nbsp;&nbsp;&lt;body&gt;<br />&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">&lt;?php<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$client&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SoapClient</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://www.mydomain.com/services/soapEmail.svc?wsdl'</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$obj&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">StdClass</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$obj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">oEmail&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">StdClass</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$obj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">oEmail</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">emailTo&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"youremail@domain.com"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$obj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">oEmail</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">emailFrom&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"anotheremail@anotherdomain.com"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$obj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">oEmail</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">emailCc&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$obj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">oEmail</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">emailBcc&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$obj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">oEmail</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">subject&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Your&nbsp;Subject"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$obj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">oEmail</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">message&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Your&nbsp;Message"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$obj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">oEmail</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">priority&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Normal"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$obj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">oEmail</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">read&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$obj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">oEmail</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">own&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$obj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">oEmail</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">filepath&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$retval&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$client</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">SendEmailObj</span><span style="color: #007700">(</span><span style="color: #0000BB">$obj</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;</span><span style="color: #DD0000">"&lt;p&gt;Returned&nbsp;Message:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$retval</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">SendEmailObjResult</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">message&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"&lt;/p&gt;"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">?&gt;<br /></span>&nbsp;&nbsp;&nbsp;&lt;/body&gt;<br />&nbsp;&nbsp;&nbsp;&lt;/html&gt;</span>
</code></code></div>
</div>    <font face="Arial"><font size="2">I’m not a PHP expert so this is a very simple example. You could include references to form elements etc. to populate the object<br />
<br />
</font></font>      <font face="Arial"><font size="2">Due to the security restrictions on Javascript, it is much more difficult to do cross domain calls using pure Javascript. There are several hacks available to achieve it, including the dynamic script tag and flash hack. You can google these for further information. I may post a separate blog about this once I have played around with it a bit more. The easiest way to achieve this is to make a proxy web service on your client site (a .asmx file, for example) that can be called by Javascript and then the proxy service makes the call to the remote web service.<br />
<br />
</font></font>      <font face="Arial"><font size="2">In the <a href="http://www.developerbarn.com/blogs/richyrich/26-convert-asmx-file-wcf-svc-file-create-simple-api-web-service.html" target="_blank">next example</a> I’ll show how to start <a href="http://www.developerbarn.com/blogs/richyrich/26-convert-asmx-file-wcf-svc-file-create-simple-api-web-service.html" target="_blank">changing your .asmx file into a WCF .svc file</a><br />
<br />
</font></font>      <font face="Arial"><font size="2">References<br />
<br />
</font></font>      <font face="Arial"><font size="2">1) </font></font><font face="Arial"><font size="2"><a href="http://leifmadsen.wordpress.com/2009/08/04/consuming-soap-complextype-webservice-with-php/" target="_blank"><font color="#000000">http://leifmadsen.wordpress.com/2009/08/04/consuming-soap-complextype-webservice-with-php/</font></a></font></font></blockquote>

 ]]></content:encoded>
			<dc:creator>richyrich</dc:creator>
			<guid isPermaLink="true">http://www.developerbarn.com/blogs/richyrich/25-convert-asmx-file-wcf-svc-file-create-simple-api-web-service.html</guid>
		</item>
		<item>
			<title>Convert .asmx file to WCF .svc file to create simple API web service</title>
			<link>http://www.developerbarn.com/blogs/richyrich/24-convert-asmx-file-wcf-svc-file-create-simple-api-web-service.html</link>
			<pubDate>Tue, 20 Oct 2009 01:50:04 GMT</pubDate>
			<description>1) Introduction 
   
This is part of a series of blogs. The others are:- 
2) A simple .asmx file and calling a function...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore"><font face="Arial">1) Introduction</font><br />
  <br />
<font face="Arial">This is part of a series of blogs. The others are:-<br />
2) <a href="http://www.developerbarn.com/blogs/richyrich/25-convert-asmx-file-wcf-svc-file-create-simple-api-web-service.html" target="_blank">A simple .asmx file and calling a function</a><br />
3) <a href="http://www.developerbarn.com/blogs/richyrich/26-convert-asmx-file-wcf-svc-file-create-simple-api-web-service.html" target="_blank">Converting a .asmx file to WCF .svc file</a></font><br />
<br />
  <font face="Arial">I had some time on my hands recently and for one reason or another starting looking into web services and WCF. It was about a week ago and I can&#8217;t remember the exact reason why I started, but I thought I&#8217;d detail the pitfalls, hair pulling, shouting and swearing moments into a blog to help others out.</font><br />
  <br />
  <font face="Arial">I&#8217;ve previously used .asmx web services within my ASP.NET applications, called them using Javascript and then handled the response using a Javascript function. There are a variety of ways of utilising .asmx services in ASP.NET applications. I just happened down this particular route as I found it very fast.</font><br />
  <br />
  <font face="Arial">I&#8217;ve always been interested in cross internet communicating, sending and receiving messages between domains and all that sort of thing. Specifically coming from a Financial Advice background there is an industry standard communication schema that is used to updates details between systems and I was interested to know how this worked.</font><br />
  <br />
  <font face="Arial">I was reading up on Windows Communication Foundation (WCF) [1,2,3] and, as it seemed WCF is designed to replace a number of different web services, I thought I&#8217;d have a go at converting one of my .asmx files to a WCF file just as a bit of a test. Here starts a long and treacherous path!!</font><br />
  <br />
  <font face="Arial">I don&#8217;t know if my terminology is right here, but I wanted to develop it as an API so that the service can be called from a variety of clients.</font><br />
  <br />
  <font face="Arial">This process involved a lot of playing around with code and testing and, frankly, I can&#8217;t remember all the various elements I tried, but have tried to detail, as clearly as possible, what I have done.</font><br />
  <br />
  <font face="Arial">These articles aren&#8217;t meant as a technical exposé of WCF, more a practical example of getting a service to work.</font><br />
  <br />
  <font face="Arial">I&#8217;ve broken the process down into some distinct areas that should, hopefully, follow through the process so you can see the changes that are made and how it&#8217;s constructed. The first thing we&#8217;ll start with is a simple .asmx file and calling a function within it.</font><br />
  <br />
  <font face="Arial">Next: <a href="http://www.developerbarn.com/blogs/richyrich/25-convert-asmx-file-wcf-svc-file-create-simple-api-web-service.html" target="_blank">A simple .asmx file</a></font><br />
  <br />
  <u><font face="Arial">References</font></u><br />
  <br />
  <font face="Arial">1) </font><font face="Arial"><a href="http://keithelder.net/blog/archive/2008/10/17/WCF-vs-ASMX-WebServices.aspx" target="_blank">WCF vs ASMX WebServices</a></font><br />
  <font face="Arial">2) </font><font face="Arial"><a href="http://www.infoq.com/news/2006/12/AMSX-WCF" target="_blank">InfoQ: ASMX or WCF Web Services?</a></font><br />
  <font face="Arial">3) </font><font face="Arial"><a href="http://blogs.msdn.com/trobbins/archive/2006/12/02/integrating-wcf-with-your-existing-asmx-services.aspx" target="_blank">Thom Robbins .NET Weblog : Integrating WCF with your existing ASMX Services</a></font></blockquote>

 ]]></content:encoded>
			<dc:creator>richyrich</dc:creator>
			<guid isPermaLink="true">http://www.developerbarn.com/blogs/richyrich/24-convert-asmx-file-wcf-svc-file-create-simple-api-web-service.html</guid>
		</item>
		<item>
			<title>Preventing Form Submit with button element in Firefox</title>
			<link>http://www.developerbarn.com/blogs/richyrich/19-preventing-form-submit-button-element-firefox.html</link>
			<pubDate>Wed, 11 Mar 2009 13:17:01 GMT</pubDate>
			<description><![CDATA[I had an issue in Firefox where I wanted a <button> element to fire a Javascript function onclick. 
  
However, I found in Firefox that the button...]]></description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">I had an issue in Firefox where I wanted a &lt;button&gt; element to fire a Javascript function onclick.<br />
 <br />
However, I found in Firefox that the button also performed a submit on the form, which I didn't want.<br />
 <br />
After a little investigation I discovered that the default type for a button element is submit. Apparently a bug in IE prevents it from firing.<br />
 <br />
So, how to fix?<br />
 <br />
Add a type=&quot;button&quot; property to your &lt;button&gt; element<br />
 <br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:36px;">&lt;button id=&quot;button1&quot; <b><font color="red">type=&quot;button&quot;</font></b> onclick=&quot;JS_Function()&quot;&gt;Click&lt;/button&gt;</pre>
</div> I would also include return false as the last line of your JS function, just to be on the safe side.</blockquote>

 ]]></content:encoded>
			<dc:creator>richyrich</dc:creator>
			<guid isPermaLink="true">http://www.developerbarn.com/blogs/richyrich/19-preventing-form-submit-button-element-firefox.html</guid>
		</item>
		<item>
			<title>Making Money Online - My Project</title>
			<link>http://www.developerbarn.com/blogs/richyrich/5-making-money-online-my-project.html</link>
			<pubDate>Tue, 26 Aug 2008 07:52:45 GMT</pubDate>
			<description><![CDATA[I own a few domain names at the moment that are just holding pages and so I thought I'd try and find a way of using these sites to generate some...]]></description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">I own a few domain names at the moment that are just holding pages and so I thought I'd try and find a way of using these sites to generate some income (enough to cover renewal and hosting costs) and maybe some extra on top.<br />
 <br />
This also got me looking into some &quot;money making&quot; internet schemes. This is something that has interested me for some time now (hasn't it for everyone?!) and I've been reading various articles about making money as an affiliate etc.<br />
 <br />
It appears to me that most of this articles are trying to entice you to sign up for something using there own affiliation with a money making scheme (not what I'm after).<br />
 <br />
So, what I want to try and do is find a method, if one exists!, of making a secondary source of income that pays me regularly and for which I don't have to:-<br />
a) invest much money in<br />
b) spend much time on<br />
c) do much for<br />
 <br />
Sounds like a mission impossible to me, but I'm going to see if something like this exists.<br />
 <br />
Like I say above, I'm looking for something that can generate a regular secondary income, so I won't be looking for those (make $100,000 in 2 week type ads).<br />
 <br />
What I thought is that my findings and exploits might make a few interesting blog articles.<br />
 <br />
So, I've been doing some investigating today and have signed up to 1 scheme so far, with another possible that I'm looking into a bit more.<br />
 <br />
I will look to post genuinely honest reviews of the schemes I find and what results, if any, I find.<br />
 <br />
PS. This isn't an advertisement for ideas! I'll be googling and searching around myself for these.<br />
 <br />
I will post additional blogs on the results I get from the schemes I try.</blockquote>

 ]]></content:encoded>
			<dc:creator>richyrich</dc:creator>
			<guid isPermaLink="true">http://www.developerbarn.com/blogs/richyrich/5-making-money-online-my-project.html</guid>
		</item>
	</channel>
</rss>

