-
Thursday, April 29, 2010
Previously, I had thought I found a way to speed up discovery by limiting the search time. It turns out that there are better ways to achieve the same goal. When limiting duration, you are trying to find all endpoints implementing a given contract within a specific period of time. However, you may have other criteria, like you just want an endpoint that implements a contract. As soon as you find that endpoint, you are happy. This is pretty simple to do as well. On your FindCriteria object, just tell it you want it to stop when it finds 1 instance OR times out. Instead of setting the duration, set the MaxResults property to 1: FindCriteria criteria = new FindCriteria(typeof(ITest));
criteria.MaxResults = 1; That’s all there is to it!
Full story
WCF
.NET
-
Wednesday, April 28, 2010
I was digging into WCF’s implementation of WS-Discovery today and was somewhat appalled by how long it took to discover a service from a client when both endpoints lived on the same machine. I setup tracing and message logging to dig into why things were taking so long. Inside the messages, I found this nugget in the WS-Discovery probe messages:<s:Body>
<Probe xmlns="http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01">
<d:Types xmlns:d="http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01" xmlns:dp0="http://tempuri.org/">dp0:ITest</d:Types>
<Duration xmlns="http://schemas.microsoft.com/ws/2008/06/discovery"> PT20S</Duration>
</Probe>
</s:Body>
I thought to myself, “That looks like a TimeSpan. I wonder how I can set it.” If you haven’t used WS-Discovery on the client in WCF, let me walk you through the basic few lines of code that get things set up. You need a DiscoveryClient which knows how to send ...
Full story
WCF
.NET
-
Sunday, January 24, 2010
html, body {
height: 100%;
overflow: auto;
}
body {
padding: 0;
margin: 0;
}
#silverlightcontrolhost {
height: 100%;
text-align:center;
}
Over the past week, I spent some time with Silverlight 4. I’m really impressed by how easy it is to incorporate video into an application. This post shows how to capture video from the camera and display the video on the screen. The post also handles grabbing single frames of video. You might use this type of arrangement to allow users to upload images, hold impromptu web casts, and to do video conferencing. I’ve uploaded a barebones application that turns on video capture and displays the video: To understand how this works, you need to be familiar with the following objects: CaptureSource CaptureDeviceConfiguration VideoBrush The CaptureSource type encapsulates the methods needed to interact with audio and video devices. CaptureDeviceConfiguration acts as gatekeeper to the webcam and microphone. ...
Full story
.NET
Silverlight
-
Wednesday, January 13, 2010
Tonight, I was writing some code that made use of transactional WCF bindings. I wanted to do some experimentation with all the bindings available to see which ones support flowing transactions. The pre-built bindings that do this will create a TransactionFlowBindingElement when you ask them to call CreateBindingElements(). The types I’m interested are concrete (no abstract methods) and have a zero-argument constructor. A few years ago, I would have done a bunch of looping constructs to look at each element. However, I’ve been doing a lot more work with F#. While doing this experiment in C# for a project, I wound up writing the following instead: static void Main(string[] args)
{
var bindings = from bindingType in typeof (MessageContractAttribute).
Assembly.GetTypes()
where typeof (Binding).IsAssignableFrom(bindingType) &&
!bindingType.IsAbstract &&
(from constructorInfo in bindingType.GetConstructors()
where constructorInfo.GetParameters().Length == 0
select constructorInfo).Count() > 0
select bindingType;
var ...
Full story
.NET
-
Thursday, December 17, 2009
Today I was reading an article in The Onion, Conquerors You May Have Missed, and noticed that the number for the ant looked like it might be a big old prime, or at least have a large prime divisor. (For reference, the ant is # 43,168,974,563,247.) There are a number of algorithms for finding this answer, but my favorite is a little brute force algorithm that keeps dividing the big number by some other value until the two numbers are equal. Yes, I know I can short circuit a bunch of testing via a square root function, but BigInteger doesn’t have a sqrt function (yet…). Anyhow, I cobbled this together and it worked right out of the gate: let rec largestFactor x y =
if (x = y) then y
else
let z = x % y
if z = 0I then largestFactor (x/y) y
else largestFactor x ...
Full story
F#
.NET
-
Wednesday, September 30, 2009
My article on programming REST services with F# and WCF went up at InformIT. Please go read it! http://www.informit.com/articles/article.aspx?p=1394625
Full story
F#
WCF
.NET
-
Friday, July 17, 2009
One of the things that many people are still doing is making use of old COM objects that run in STA (single threaded apartment) threads. Back in October, 2006, Jeff Prosise wrote how to do this from ASMX. Not too long after that, I had a chance to teach for Wintellect and Jeff asked me to show him how to do the same in WCF. That information went up on a post for a consulting company that didn’t make it through the latest recession. For better or worse, that post was referenced a fair number of times and now, folks are writing to me, asking for the code again. In general, any time you receive a message via WCF, the message itself will be processed on a MTA (multi-threaded apartment) thread. Normally, this is just fine. Sometimes, you might be calling out to a COM object. COM objects will ...
Full story
WCF
.NET
-
Monday, June 08, 2009
This is day #3 of my journey through the .NET 4.0 assemblies. I’m planning to split up large assemblies over several days so that I give bigger assemblies proper treatment. Today, that won’t be happening! By the way, this is actually turning out to be pretty neat. .NET ships with a lot of interesting pieces, and the assemblies that sort early in the alphabet (because they don’t start with System) are pretty interesting glimpses into how .NET does things. Today, we look at IEExecRemote. This assembly contains a single type: IEExecRemote, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a FullTrust: True In GAC: True Number of types: 1 Number of namespaces: 1 Types: Class IEHost.Execute.IEExecuteRemote So, what does this IEExecuteRemote do? Reading the docs, we see that this is another class that “supports the .NET Framework infrastructure and is not intended to be used directly from your code.” So what? What ...
Full story
.NET
-
Friday, June 05, 2009
I’m on day 2 of going through assemblies in .NET 4.0. I may miss a day here and there, but I want to find out what is in all the libraries. For some of the bigger libraries, I think I’ll do a namespace breakdown over several days. The assembly today is CustomMarshalers, and it has very few classes; 4 to be exact. CustomMarshalers, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a FullTrust: True In GAC: True Number of types: 4 Number of namespaces: 1 Types: Class System.Runtime.InteropServices.CustomMarshalers.ExpandoToDispatchExMarshaler Class System.Runtime.InteropServices.CustomMarshalers.EnumeratorToEnumVariantMarshaler Class System.Runtime.InteropServices.CustomMarshalers.TypeToTypeInfoMarshaler Class System.Runtime.InteropServices.CustomMarshalers.EnumerableToDispatchMarshaler These classes all handle special scenarios for interacting with COM. Since there are only 4 classes, I’ll cover each. ExpandoToDispatchExMarshaler The CLR will not use this marshaler automatically. You need to know when it is needed. When P/Invoking a function or declaring a CLR wrapper for a COM object, you may have an object that only implements IDispatchEx...
Full story
.NET
-
Thursday, June 04, 2009
In the spirit of DNRs “Better Know a Namespace”, I’m going to go ahead and try to understand what the 140 assemblies on my machine that appear to be part of .NET 4.0 actually do. I’ll go through these as I can, just as a way to know what exists. Here is the first one: Accessibility, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a FullTrust: True In GAC: True Number of types: 10 Number of namespaces: 1 Types: Interface Accessibility.IAccPropServices Interface Accessibility.IAccPropServer Enum Accessibility.AnnoScope Value type Accessibility._RemotableHandle Interface Accessibility.CAccPropServices Class Accessibility.CAccPropServicesClass Value type Accessibility.__MIDL_IWinTypes_0009 Interface Accessibility.IAccessible Interface Accessibility.IAccessibleHandler Interface Accessibility.IAccIdentity This assembly provides the interfaces and struct definitions needed to interact with the Windows Accessibility system. The assembly is a managed wrapper for the COM accessibility interface. This interface helps assistive technology products work with applications. It also provides a way to access, identify, and ...
Full story
.NET
-
Wednesday, April 22, 2009
With SimpleDB, you need to create a domain to store any data. Domain creation is a unique event in the life of an application, happening at install or some other infrequent event (addition of a new product line, client, etc. depending on how you partition data). 99+% of the time, the code will need to use the domain to Create, Retrieve, Update, or Delete data. These are more commonly known as CRUD operations. AWS stores the data as name-value pairs called attributes. The attributes have an additional value indicating if the value is replaceable/updatable or if the value can only be set of creation. Each item in the database has a name and a set of 1 or more attributes. In this post, I walk through how MembershipUser records are created and updated. This post uses Amazon’s SimpleDB C# library. The example has the following ...
Full story
F#
Amazon Web Services
SimpleDB
.NET
-
Friday, April 17, 2009
Before you can access data in SimpleDB, you have to have a domain. Domain creation is fairly expensive in terms of time—up to 1/2 a second. Listing domains is really cheap—especially since you will normally have a maximum of 100 domains. When the application starts up, we want to check if the domains we need exist—if not, create them. Otherwise, mark an all clear so that the check doesn’t happen again. To handle all this work, we have a module named PhotoWebInit. The module instantiates a client capable of communicating with SimpleDB by reading the key and secret from configuration. Using that client, the code then checks to see if the domain we want, friseton_com, exists. OK—this code really looks to see if we have 0 domains or more. friseton_com is the first domain we need because if a user needs to be able to log in before any ...
Full story
F#
Amazon Web Services
SimpleDB
.NET
-
Monday, March 30, 2009
Here’s a small gotcha that I didn’t see covered via the normal Google coverage. So, I’m adding the information and the solution so that I can find the answer when I need it again. I’m sharing via my blog to help you out too. If this helps you, click on a link and send some change my way:) Symptom: You follow the rules and ran “Create Test Storage Tables” from Visual Studio on your dev box. All your testing locally seems to work. When you deploy, you see an error like this (leaving in lots of Google discovery goodness in here. If this saves your bacon, send me a thank you!): <?xml version="1.0" encoding="utf-8" standalone="yes"?> <error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"> <code>TableNotFound</code> <message xml:lang="en-US">The table specified does not exist.</message> </error> Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error ...
Full story
Azure
Utility Computing
.NET
-
Monday, March 23, 2009
One of the LCNUG members, Kurt Schroeder, has volunteered to present at this month’s regular meeting. We’re a typical INETA group: food/tech/discussion during the 2 hour meeting. Kurt’s talk is definitely technical, but his talk focuses on the lessons learned while constructing a system quickly and then rebuilding it to make the system better (easier to maintain, enhance, and comprehend). Kurt will be spending a lot of time in code, showing the original implementation and showing how it morphed over time. We all have bad code in our systems that we want to make better. See how Kurt evolved the ever so sexy sounding “stock market system based on point and figure charting.” Trust me—it’ll be interesting. Join us: Sign up at: http://www.eventbrite.com/event/300902006 When: March 26, 2009 6:30 PM – 8:30 PM Where: College of Lake County: Technology Building in room T326-328. Directions Campus map
Full story
Miscellaneous
.NET
-
Friday, March 20, 2009
As I continue to build more F# code, I keep finding interesting usage of the language and its features. Today, I’m going to talk about Seq.find. Seq.find loops through a sequence (an IEnumerable in .NET speak) looking for some item that satisfies a function that returns a boolean. As soon as the function returns true, the iteration stops and the found item is returned. Maybe it will just be easier to show what the code looks like: #light let thelist = [|("joe", 1); ("jim", 3); ("scott", 6); ("kenn", 29)|] let scottsNumber = thelist |> Seq.find(fun (a, b) -> a = "scott") |> (fun (a,b) -> b) printfn "%d" scottsNumber The code has an array of tuples. It then pipes that list into Seq.find. Because our tuple has two values, the function will also take a two value tuple. ...
Full story
F#
.NET
-
Monday, March 16, 2009
I was busy working on the Amazon Web Services version of my Photo Sharing application (the App Engine version appeared in February 2008). I was able to create a domain with the name friseton.com. I then wrote a simple query against this domain: select * from friseton.com where email=’dude@example.com’ SimpleDB responded and told me that the select query had an invalid format. On a wild guess, I thought it might be the dot (.) in friseton.com. Sure enough, it was. I deleted the friseton.com domain, added friseton_com, and the query started working. select * from friseton_com where email=’dude@example.com’ I don’t know if there is any syntax around allowing the dot in the domain name, but I found this, it works, and I’m moving on with the demo. I’ll learn the ins and outs as I go.
Full story
Amazon Web Services
SimpleDB
.NET
-
Friday, March 06, 2009
In my goal to learn F# better, I'm doing all of my recreational development in the language. This gives me lots of learning opportunities (better known as WTF moments). I was implementing a MembershipProvider for an ASP.NET web site where the datastore is not SQL. By and large, MembershipProvider requires that you implement uniquely named methods. It does exposes a pair of abstract methods that one must implement. In C#, they look like this: public abstract MembershipUser GetUser( string username, bool userIsOnline); public abstract MembershipUser GetUser( Object providerUserKey, bool userIsOnline); These two methods seemed pretty natural to overload in F#. I just wrote these stubs: override this.GetUser(providerUserKey: obj, userIsOnline: bool) : MembershipUser = null override this.GetUser(userName: string, userIsOnline: bool) : MembershipUser = null The compiler didn't like this, telling me Duplicate definition of value 'AwsMembershipProvider.GetUser.3.override' No amount ...
Full story
F#
.NET
-
Wednesday, March 04, 2009
At work, I had a need for a line of business monitoring application to figure out server health. Due to the nature of the monitoring, it made sense to write this as a MySpace Developer Platform application, hosted in the browser. The display needs required a Rich Internet Application interface, meaning Flash, Silverlight, or heavy AJAX. I chose Silverlight, just because. Now, MySpace doesn't allow one to publish a Silverlight application, but that didn't stop me from writing an app for my own personal consumption. Given the nature of the application, I needed to host the Silverlight XAP file on a server separated from the JavaScript and web page that displayed the application. Silverlight doesn't like having JavaScript call into it unless the application manifest says that it is OK. It took me several hours to figure out the nature of why my scriptable objects, which worked fine in my ...
Full story
Microsoft
.NET
Silverlight
-
Monday, March 02, 2009
Recently, I needed a place to store a compiled Silverlight assembly in a highly available environment. Ideally, the location needed to be free or on some web site that I owned. Since I've been getting comfortable with App Engine lately, I figured I would try setting up app-engine to host my file. The one thing that you need to do when return a Silverlight XAP file is make sure that it comes back with the MIME type set to application/x-silverlight-app. It turns out that this is pretty simple. I just added this to my app.yaml file: handlers: - url: /SilverlightApp.xap static_files: SilverlightApp.xap upload: SilverlightApp.xap mime_type: application/x-silverlight-app With this, I have App Engine reliably serving up my page with Silverlight embedded.
Full story
Google App Engine
.NET
Silverlight
-
Friday, February 13, 2009
In my quest to learn F# better so that I might figure out when this tool makes sense, I have been trying to use the language whenever possible/feasible. Just such an opportunity happened while delving into Google App Engine. I found I could get rid of a little warning in the GAE development environment by converting all files from Windows style CRLF (\r\n) to a more Unix like LF (\n). Out came F# to solve this little problem! This application was moderately frustrating to write because of the puzzling syntax errors. I'm still working on getting the feel for F# and am trying to use it as my preferred hammer (realizing full well that "when all you have is a hammer, everything looks like a nail"). I have to admit, it was a fun little application to write! 1 #light 2 open System 3...
Full story
F#
.NET