July 2008 - Posts
Close the Current File in Visual Studio

I spend many hours a day working with Visual Studio 2008 and the Office Product. What I most like from the user experience perspective is to have the same shortcuts and key-bindings, no matter which application I am currently using.
In Office Applications I use the shortcut Ctrl + W to close the current window and I have always wanted this shortcut to work inside Visual Studio.
Today I created this key-binding for my self.
If you want to create yours:
- Go to Tools -> Options.
- Expand the Environment node and select the Keyboard node.
- Search for the command which you are trying to kind keys to (in this example File.Close). The list will display the commands the match your search criteria.
- Press the Shortcut Keys you want to bind to this command (Ctrl + W).
- Press Apply (don't forget to do that, otherwise the shortcut will not bind).
Enjoy!
How To: Call Java EE Web Service from Silverlight Client
I have already posted about How To: Call a Java EE Web Service from a .Net Client, but if Silverlight is the .Net client application that consumes that service, there are several issues you should be aware of.
Only asynchronous operations
When adding a service reference from a Silverlight application to any web service, the generated proxy has only async operations. This means that instead of calling the operation and get the result:
CalculatorServiceClient proxy = new CalculatorServiceClient();
int result = proxy.Add(2, 3);
Console.WriteLine("Calculator Service returned: " + result.ToString());
what you have to do is call the async version of this method, and register to the completed event:
CalculatorServiceClient proxy = new CalculatorServiceClient();
proxy.AddCompleted += proxy_AddCompleted;
proxy.AddAsync(a, b);
and as the implementation of the proxy_AddCompleted method, get the result:
void proxy_AddCompleted(object sender, AddCompletedEventArgs e)
{
int result = e.Result;
...
}
Cross Domain Calls
Since the Java service is probably hosted on another domain, calling it is considered as a cross domain access. I have posted about the HTTP 404 error when calling a service from a Silverlight Client across domains, and this solution applies here too.
The thing is that since the Java EE is hosted on another web server than IIS, you should place the clientaccesspolicy.xml file on the root of your domain. On my machine, I have GlassFish V2 installed, and the file should be placed at: C:\Users\guyb\.personalDomain\personalDomain\docroot\ folder.
Hope this helps!
How To: Call a Java EE Web Service from a .Net Client
Many organizations have server side investments in Java technologies. While they want to build a compelling UI with Microsoft’s latest technologies, such as WPF and Silverlight, they still want to benefit from those existing investments instead of rewriting them. In order to do so, we have to bridge between those technologies and allow client side technologies consume Java web services.
This post is a step by step guide for building a Java EE Web Service, and a .Net client application that consumes it.
Before we get started with this walkthrough, make sure you have the following installed on your machine:
Create a Java Web Service (Java EE, JAX-WS)
1. Create a new Web Application
In the NetBeans 6.1 IDE, choose File –> New Project. In the New Project Dialog select the Web category, and choose Web Application from the projects list. Then, Click Next.
* If the web category is not available in this dialog, it means that the NetBeans version you have installed isn’t the Web and Java EE package.
In the Name and Location page, set the location where you want to create the web application, and provide a name for the project. Click Next.
In the Server and Settings page, leave the default settings (Java EE 5, Use GlassFish V2) and Click Finish.
This creates the initial web application and opens the project for editing.
2. Create the Web Service
Add a new web service to the project. Right click the project node and choose New –> Web Service.
* Notice that the location of the Web Service option in the menu may change from this image and your IDE.
In the New Web Service dialog, provide the Web Service Name, and the Package. The name of the service will affect the final URL for calling the service, and the package name will be the namespace of the service contract. Click Finish.
The Web Service now appears in the project tree.
To implement the service, double click the service node in the project tree (in the figure above – CalculatorService). This will open the Web Service in Design mode, that lets you graphically design your service.
Change to Source View by clicking on the Source button in the upper toolbar, and this will open the CalculatorService.Java file for editing. Here is a sample implementation of the service. Notice how Java Annotations are similar to .Net Attributes, especially how similar they are to the Web Services attributes we know…
package org.bursteg.calculator;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService
public class CalculatorService
{
@WebMethod
public int Add(@WebParam(name="a") int a,
@WebParam(name="b") int b)
{
return a + b;
}
}
Deploy the web service to the web application server. From the NetBeans IDE this is done by right clicking the project node, and choosing Undeploy and Deploy.
After the web application has been deployed, just to make sure the web service works as expected, you can right click the web service node, and choose Test Web Service.
This will open the browser and navigate to a test page with the url of the service (http://localhost:9232/Calculator/CalculatorServiceService) with a ?Tester suffix.
Call the Java Web Service from a .Net Client
In Visual Studio 2008, create a new console application.
This creates a new solution with a single Console Application project in it.
Right click the project node and choose Add Service Reference.
In the Add Service Reference Dialog, paste the address of the service metadata endpoint (service address + ?wsdl suffix: http://localhost:9232/Calculator/CalculatorServiceService?wsdl), and click Go. The dialog will get the service metadata and understand the service contract.
Provide a namespace for the service reference, and click OK.
This will generate the client side proxy that lets you consume the service easily, and the required configuration settings into the configuration file.
To call the service using the generated client side proxy, open Program.cs and use the following code:
static void Main(string[] args)
{
CalculatorServiceClient proxy = new CalculatorServiceClient();
int result = proxy.Add(2, 3);
Console.WriteLine("Calculator Service returned: " + result.ToString());
}
Run the program and see that the web service is being called and the result is correct.
Conclusion
Since Java EE Web Services (JAX-WS) are standard SOAP services, they are easily interoperable from a .Net client application with only several clicks. Visual Studio generated a .Net client proxy that makes it very easy to connect and call the service.
Enjoy!
Silverlight WCF Returns HTTP 404
Today I ran into something weird. I created a WCF Service and tested it with simple .Net client application and it worked fine. Than, I build a Silverlight application and tried to call the same service, but kept getting: System.ServiceModel.ProtocolException: "The remote server returned an unexpected response: (404) Not Found."
What I found out was that since the WCF call was made to a service that is not under the same domain as my Silverlight application (or different ports in local development machine). This situation turns out to be a cross domain call, and Silverlight required the domain that hosts the WCF service to allow such calls. This can be done by placing a file called clientaccesspolicy.xml in the root directory of that domain.
So, in order to get your Silverlight make a successful call to a WCF service without getting HTTP 404 back, you should put the clientaccesspolicy.xml in c:\inetpub\wwwroot\.
The file should look like:
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="*">
<domain uri="*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
Of course, you should customize it according to your settings.
This is all it takes to get rid of Silverlight application WCF calls that returns HTTP 404…
Enjoy!
ALT.Net Israel is Live and Open for Registration
Ken Egozi, has announced today that the first Israeli ALT.Net conference will take place in Ramat Gan, on August 7th and 8th.
If you haven't heard of Alt.Net yet, read David Laribee's post to better understand the term - What's ALT.NET.
All the details, on Ken’s Blog:
Enjoy!
How To: Host Your Screencasts on Silverlight Streaming
Are you familiar with Silverlight Streaming? If you’re not here is a good reason to start using it. Generally, Silverlight Streaming lets you host Silverlight applications on Microsoft servers for free. With some of the latest updates to this service, you can now upload and host your videos. If you are recording screeencasts as I do, this post can be very useful for you. In this post I will show how to create a new Silverlight Streaming Account, upload a new video and embed it into an HTML page.
You can check out the blog post I have posted with the embedded video.
Creating a Silverlight Streaming Account
1. Navigate to Silverlight Streaming Home Page at http://silverlight.live.com, and sign in with your Windows Live ID.
The Silverlight logo on the left side bar is actually a Silverlight animation. If you don’t have Silverlight plug-in installed, you will see the “Get Silverlight Image” and you should click on it in order to get the latest plug-in.
2. Click on the Get it free to create a new account.
After your account is created, it will associated a unique Account ID with your Windows Live ID. This ID (shown in the image below) will be part of the URL for the video we’ll upload, so you should notice it.
Upload a Video to Silverlight Streaming
3. Click on the Manage Videos link on the left side bar in order to view and manage your videos, and upload new ones.
4. Click on Upload a video.
5. Browse and locate the .WMV file you want to upload and provide a friendly name for it. Notice the checkbox called “The video is a Silverlight compliant WMV file”. If your video is a standard WMV file, this checkbox should not be checked. If you have encoded this video with Expression Encoder and it is in VC-1 format, you should check it.
6. Click the Upload button to start uploading the file.
Once the video is uploaded, you will see it on the Recently Uploaded Videos, with Processing Video status.
The server processes the video, converting it to a Silverlight Compliant format that can be streamed efficiently via Silverlight players.
After a while (it depends how long of the video file size), if you refresh this page, you will see that the video processing was done, and you should acknowledge it.
Embedding the Video in your Site
Once your video is available in Silverlight compliant format, you can embed in into a page in your site. I will embed a Silverlight player playing this video into a blog post and also provide a direct link for downloading it.
7. Click the video link to go the preview page. In this page you’ll see a standard Silverlight player that plays your video. If you scroll to the button of this page, you can see the HTML snippet for embedding this player into your blog, and the direct link to the video. Notice how the URL of the video contains the your Account ID.
To embed this in my blog post, I simply copy the HTML snippet to the HTML editor in Windows Live Writer, and provide a download link for users who may want to download the video on watch offline.
<!-- HTML snippet taken from Silverlight Streaming -->
<iframe src="http://silverlight.services.live.com/invoke/72395/EntityDataSource/iframe.html" scrolling="no" frameborder="0" style="width:500px; height:375px">
</iframe>
<p>
<a href="http://silverlight.services.live.com/72395/EntityDataSource/video.wmv" title="EntityDataSource Screencast">Download the video</a>
</p>
You can check out the blog post I have posted with the embedded video.
Enjoy!
אירועים למפתחים בחודש יולי 2008
דרכים ושיטות לביצוע Security Code Review
1 ביולי, 17:30-20:30, רעננה.
מה חדש ב- SQL Server 2008 למפתחים?
2 ביולי, 18:00-20:30, רעננה.
עבודה מקבילית בסביבת חלונות
9 ביולי, 08:30-13:00, הרצליה.
VSTS for Database Professionals: Why & How?
14 ביולי, 08:30-12:30, הרצליה.
ASP.Net Internals
20 ביולי, 17:00-20:00, רעננה.
היכרות עם Silverlight 2 לבניית אפליקציות Web עשירות
23 ביולי, 08:30-12:30, הרצליה.
MSDN Pulse - העדכון החודשי שלך!
תהנו!
גליון יולי 2008 של MSDN Pulse נשלח הבוקר רק למפתחים שנרשמו
הגליון הרביעי של MSDN Pulse - העדכון החודשי למפתחים בישראל נשלח היום ומכיל את רשימת הדברים החמים שהיו בחודש האחרון, וכן את רשימת האירועים המתוכננים לחודש הקרוב. בין היתר, תוכלו למצוא בגליון מאמר שיחזיר לכם את החיוך לפנים, טיפ שיאפשר לכם לדבג טוב יותר את האפליקציות שלכם והנחות על כנסים שכדאי לכם לבקר בהם. כנסו לגליון יולי 2008 של MSDN Pulse.
לראשונה, לאחר פיילוט של 3 חודשים, הופץ היום ה- MSDN Pulse ללקוחות רשומים בלבד. אם לא קיבלתם את הגליון הזה בדוא"ל ממיקרוסופט ואתם מעוניינים לקבל את הגליונות הבאים, עדכנו את הפרופיל שלך בקהילת המפתחים והרשמו לקבלת MSDN Pulse בדוא"ל החל מהחודש הבא.
תהנו!