| Comments

i did a quick refresh on my windows vista sidebar gadget templates for visual studio.  it is a simple refresh that accomplishes the following:

  • puts both the VB and C# web project templates in the same visual studio content installer
  • moves the structure around to demonstrate how to use locale folders within gadgets (see image below)

i get questions on the first one (VB/C# templates) a lot.  really there is no difference between the templates, the only reason i created two is so that when you choose "new web site" it will show up under both language options.  that's it.  gadget development itself is mostly html/javascript (unless you are using something like script#), so the templates are there for convenience only.

new structure:


i've refreshed the old download links, but here is the link to the updated single VSI file as well:

file: VistaSidebarGadget.vsi

| Comments

thanks to those who joined us for my learn2asp.net session on interoperability with php and windows.  i apologize for the rescheduling (if you even knew about it) that had occurred, but glad you could make it to the session.  in the session i stated that i'd post the information and sample code i referred to on to my blog so here it is :-).

in the session i mentioned a few things, so i'll dump them to you here:

in the session (which is still available on-demand for you to watch -- and if you watch 3 webcasts i think you get some swag as well) we demonstrated some simple methods of integrating with .net applications using two primary methods: com interop and web services.  below are some of the samples i demonstrated as is the sample code for them is at the bottom of this post as an attached file download.

com interop
the com interop scenario allows us to directly interact (okay, well obviously not directly, but via com) with a .net class library that someone may have created.  a few best practices should be followed (and some required) for this to occur.  this isn't php-specific, but rather com interop specific.  first when building the .net class library, you have to make sure that you mark it ready for com interop.  in visual studio, you can view the project properties to do this and look at the "build" tab in c# and the "compile" tab in visual basic.

samples: build tab in c# (the output section is near the bottom of the info on this tab):


the second thing you have to do is make the class library "com visible."  in visual basic, you'll attribute the class like this:

<ComClass()> _
<Runtime.InteropServices.ComVisible(True)> _
Public Class RegClass

in c# you can again use the project properties window under the application tab, there is a setting for "assembly information":


which basically adds this to the AssemblyInfo.cs file in the project:

[assembly: ComVisible(true)]

the next thing you have to ensure is that the assembly is signed with a strong name.  the reason for this is that when the assembly (dll file) is going to be registered, it will need to have a reference to the codebase or alternatively will be placed in the global assembly cache (GAC) both of which require assemblies to be signed.  once you have those steps complete, you can register the .net assembly with com, using the regasm.exe tool that comes with the .net sdk.  to sign the assembly, visual studio makes this easy through the project properties options in the "signing" tab, allowing you to create a new strong name key file at that time as well:


once you have this you are ready to use the regasm.exe tool using the command seen here (note the highlighted portion):


i prefer to use the /codebase option as it allows me to not require it be in the GAC and gives me flexibility of where the assembly may physically reside.

after you have done this you can start calling the com object.  using the sample code (available at the end of this download) you would do something like this in php:

$com_app = new COM("PHPInteropCSharpClass.SimpleClass");
$result_var = $com_app->SayHello("Woodingo");
echo $result_var;

and when requesting the page it will call your com object.  i hope this helps.  for further explanation, you can view the webcast on-demand to see it all in action before you try it out for yourself.

soap interop
the second thing we demonstrated was using web services and soap.  i've included a sample file (phpSoap.php) in the zip file that uses the native PHP5 SOAP extension.  i won't go in detail here as that is well documented.  other options are to use the NuSOAP extension as well that provides similar functionality, but know that in PHP5 there is a native extension for creating a SoapClient object using a WSDL file.

i hope this helps, let me know if you have any questions.

file: PHPInterop

| Comments

the update for visual studio on windows vista is now available.  dubbed "VS2005 SP1 Update for Vista" is available for download on the microsoft.com downloads site.

here's the kb article with the release notes: KB929470

here's the download of the bits: VS2005 SP1 Update for Vista

note: you must first have VS2005 SP1 installed to run this.

| Comments

thanks to all who attended my on creating mash-ups with php on windows and using microsoft web api's.  whew, that was a mouthful.  anyway, i said i'd post the sample code i used, so here it is (at the end of this post).  in the zip file there is an index.php file describing the APIs used.  I stripped out my personal application id's from some of the services, so you'll have to obtain your own.

there are plenty of other sessions going on the site so i'd encourage you to take a look at them and register.  also, the previous sessions are available on-demand for your viewing as well.  whenever you complete one, please be sure to complete the evaluation for a chance to win some more swag and give the organizers valuable feedback.

to recap, here are some of the things we used/demonstrated:

  • flickr
  • virtual earth
  • live.com search
  • microsoft ajax on php

there is, of course, more things you can do than mapping, etc. but with limited time i wanted to show some of the more simple ones.  be sure to check out for more APIs you can use (for example, the Amazon services are a cool one).

also, the tool i was using to write PHP within visual studio was from .  it's a great little add-in.

at we'll be showing some other mashup technologies (http://www.visitmix.com/about/) from microsoft, so if you aren't registered, consider going to ...it will be a great time and conference...and each attendee will get windows vista ultimate as well!

File: PHP Mash-up Samples

| Comments

do you ever wonder how some of the extensions or send down their javascript code that it handles?  have you ever sat back and said, "wait a minute, i'm not adding any scripts here"?  well, if you haven't, then move along, there is nothing to see here.

but if you have, read along.  i know i have as i think i've always taken for granted the feature of how this is being accomplished in both the ajax tools as well as some things that asp.net 2.0 uses as well...so let's see what's going on here.

if you have no idea what i'm talking about, basically load up an page and look at the source, you'll see something like this:

<script src="/ScriptResource/ScriptResource.axd?d=cOVC9K4WK3DoOci8poj2gEx1D9Jpq5e-
t=633051597837658400" type="text/javascript"></script>

keep adding some controls, toolkit controls, etc. and you'll see more web resource references pushing down javascript.  if you use a tool like fiddler or web development helper, you'll see that this request results in javascript being pushed down to the browser.  so how do you do this in your own assemblies?

first, why would you want to do this?  well, good question -- i don't think you'd want to do this for everything, but i think it is a good idea for reusable components...and i think we'll see this trend more and more from component vendors -- it reduces the installation woes for some of the client-side script deployment.

anyhow, i'm babbling...here's the goods.

first, have your javascript file (my example here has a single function SayHello() that throws an alert('hello world')) as a part of your class library for your control/component.  change the build action from "content" to "embedded resource" in the properties of the .js file.  what this will do is essentially, well, make it an embedded resource.


after that go into your class file that would render your control/component or wherever you'll want the embedded script to "reside."  the easiest thing here is to add this to your code:

   1:  [assembly: System.Web.UI.WebResource("ScriptResourceClass.HelloWorld.js", "text/javascript")]
   3:  namespace ScriptResourceClass
   4:  {
   5:      public class Class1
   6:      {
   7:          public string SayHelloServer()
   8:          {
   9:              return "Hello World from server";
  10:          }
  11:      }
  12:  }

once that is there (you may have to add a reference to System.Web.dll) then you are ready to go.  now consuming (or should i say exposing) this is VERY simple using asp.net ajax and the wonderful do-all-the-heavy-lifting-management-for-me scriptmanager component.  in our page where we want to consume this and add a script reference to the scriptmanager like this:

   1:  <asp:ScriptManager ID="ScriptManager1" runat="server">
   2:      <Scripts>
   3:          <asp:ScriptReference Assembly="ScriptResourceClass" 
   4:          Name="ScriptResourceClass.HelloWorld.js" IgnoreScriptPath="true" />
   5:      </Scripts>
   6:  </asp:ScriptManager>

when rendered you'll see some line that looks like this:

<script src="/ScriptResource/WebResource.axd?d=jiqWbcneAVORXcafmWglIA2&amp;t=632968784944906146" 

i'm not going to pretend that i know what/how the webresource.axd url is generated and formatted, but i trust it is something super cool and important.  note you aren't limited to using scripts for embedded resource...you can just as easily put a dependent image into this format and have your control reference it in the image path using WebResource("name") and then it will get it from the embedded resource.  once this webresource.axd url is there, now my SayHello() function from *script* works fine when called from anywhere.

so what if you don't use asp.net ajax?  well, shame on you then.  but seriously, you can still accomplish this, but you just have to write a bit more code in your control rendering to retrieve the resource and ensure it is registered on the page.  you can use something like the Page.ClientScript.GetWebResourceUrl function.