Windows Phone Developer Tools

On 03/15/2010, at Mix 2010, ScottGu announced the availability of Windows Phone Developer Tools CTP for free download. It can be downloaded from here

http://www.microsoft.com/downloads/details.aspx?FamilyID=2338b5d1-79d8-46af-b828-380b0f854203&displaylang=en

And more information about the download can be found here on the Windows Phone Developer Blog.

Also the developer home for Windows Phone is here

http://developer.windowsphone.com

While installing the download package, I ran into an error that VC 10.0 was already installed. Turned out that I had Visual Studio 2010 Beta 1 installed on my machine, and the Windows Phone Developer CTP was not OK with that. Uninstalling the VS 2010 Beta 1 fixed the issue.

A bunch of other new technology that has been announced in Mix 2010 include

– oData – Open Data Protocol. A new protocol built on HTTP and ATOM for sharing data based on REST principles. It was earlier known as ADO.NET Data Services. There’s a feed for that!

Dallas – A market place for web API providing access to data sets using oData. Many datasets already available. Again more information about this here, on the Dev Blog.

– Houston – A tool built in Silverlight that allows manipulation of SQL Azure. Again this is not something new but things are coming together nicely for developers working with Microsoft technologies.

Advertisements
Posted in Mobile | Tagged , , , , , , | 1 Comment

Quickly finding WCF Serialization/Deserialization Issues

Once control leaves your code, and heads into the land of WCF serialization, or before it hits your code, when it is in the land of WCF deserialization, you usually don’t have much insight into what’s going on. Yes, you can write your own handlers and step into the process but in most cases, there is no need for that. All you need is a little bit of logging and some error messages to help you catch issues.

Fortunately, Visual Studio comes with a handy little tool called SvcTraceViewer.exe that can help you quickly find issues with serialization or deserialization of your DataContracts.

You need to do the following two steps to quickly find the issue:

Step 1

Tell WCF to start logging out into a file. You can do this by adding the following diagnostic section as a child of the <configuration> tag. But be careful, it has to be after the end of the <congifSections> tag. There are a lot of options and flexibility WCF provides around this tracing, and you can read all about it here. The section below will cause WCF to log out its activity to the file c:\wcf.svclog

<system.diagnostics>
    <sources>
        <source     name="System.ServiceModel"
                    switchValue="Information, ActivityTracing"
                    propagateActivity="true">
            <listeners>
                <add    name="traceListener"
                        type="System.Diagnostics.XmlWriterTraceListener"
                        initializeData= "c:\wcf.svclog" />
            </listeners>
        </source>
    </sources>
</system.diagnostics>
Source: http://msdn.microsoft.com/en-us/library/ms733025.aspx

Step 2

Now that you have set WCF to log out all its activity into c:\wcf.svclog, all you need to do it open that file using the utility SvcTraceViewer.exe. It ships along with Visual Studio (atleast VS 2008 Professional Edition that I have), and it lives in the following folder on my machine.

C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin

Once you open the trace file in SvcTraceViewer.exe, you will see the log entries (activities). Something like this:

image

Here you can see that a number of activities are logged and also a couple of errors are pointed out in red.

When I click on one of those error entries, this is what I see on the right side of my SvcTraceViewer window:

image

As you can see, all the steps for processing that particular request are listed, and the step that failed is logged out in red. When I click on the step that failed, this is what I see in the bottom pane of my SvcTraceViewer window:

image

As you can tell from the “Message” field under the “Exception Information” section, the error is pretty clear. While attempting to fulfill a request, WCF ran into an interface that was actually implemented by a type it did not recognize (WLogicTree). I need to tell it about the type. I can do this by adding it to the ServiceKnownTypes list.

In short, once you know how to use tools like SvcTraceViewer, and understand some of WCF rules for serialization and deserialization, it is not very painful to catch most errors.

Happy debugging!

Digg This
Posted in web services | Tagged , | 4 Comments

Thoughts on SharePoint/SocialCast Integration

SocialCast recently announced a Sharepoint Webpart, a part of their EASE release. I think some of the connectors, specially ones that bring SocialCast to Outlook and SharePoint will be very useful. I was also thinking about the reverse, which is bringing content from sources like Outlook and SharePoint into SocialCast (just like it allows bringing content from Twitter and Facebook).

Below are some thoughts about how such an integration could work.

SharePoint organizes everything in terms of sites, sub sites and lists. For example if I have a sharepoint site for my group (a set of engineers and PDs who work together organizationally), one way to organize my projects would be to create a site for each project under my group’s site. Inside a site, you can have any number of lists. List is the generic term sharepoint uses for any set of information. So Links, Announcements, Events and Documents etc are all lists within a sharepoint site. People usually associate webparts with Sharepoint but webparts are just a user interface concept, used to surface all or parts of underlying lists, and other information. The underlying data is all stored in terms of lists.

For SocialCast/Sharepoint integration, it would be good to have an interface where I can point to a top level sharepoint site, and see all the sites that are under it, and then select a site, and see all the lists that are under it. Then for each list, see all actions that are possible on the list, and be able to turn on/off notifications for each action. It would also be great to have the same notification features at the site level, meaning being able to turn on/off notifications for the whole site (i.e. all lists and sub-sites under it).

Subsequently, each time a notification is generated, it should have information about which site, list and item it is being generated for (including a link to the item), the kind of action being performed, and the user that performed the action. It would also be nice to have other useful fields of information associated with the change that sparked the notification such as Comments.

I can imagine that such automated notifications could easily clutter the “Company” or “Home” activity stream, so maybe there should be an option to see or not to see such notifications there. The same could be said for all stream items that are auto-generated (though some people may prefer those over person generated stream items 🙂

Consider this scenario…

Lets say I belong to a organizational group (Org Group) in my company called the “Company Data Group” and I am currently working on a project called “Fundamentals Integration”. I have a SharePoint site for my entire Org Group, and a sub-site under it for the current project I am working on. To help my Org Group collaborate, I also create a SocialCast Group (SC Group) called “Company Data Group” and include all members of my Org Group in it. Since the concept of projects is not directly supported in SocialCast, I would make another SC Group (maybe a private SC Group) and include all the people who are working with me on that project.

Now, I should be able to configure the stream settings for the SC Group that maps to my current project to include notifications that are being generated from that Sharepoint site for my current project (just like I am able to do so for twitter feeds being imported to the stream). Then the stream on my SC Group will be in sync with the activity going on in my project’s sharepoint site, and I will easily be able to keep on top of it.

Groups Vs. Workspaces/Projects

I think if we are talking about Sharepoint integration we must address the issue of Groups vs. Workspaces/Projects.

I associate SocialCast Groups with permanent organizational entities, like the “NYC Outreach Group” or the “Internal Communications Groups”. That makes sense but how does Socialcast support collaboration on a certain project or short term event, say a charity event being organized to support Chile or a market research project to identify the impact of a new product? How do we define the boundaries of that project, meaning I don’t want the content generated as a part of that project (messages/docs/links etc) to mix with other projects that I may have worked on or will work on.

Since I cannot make a “workspace” for my Project under my Group, the only option I will have is to make a Group for every Project I work on, and eventually that will lead to a lot of clutter (think thousands of Groups). It helps that Groups can be private and invitation only, so atleast my project groups will not clutter other people’s socialcast views. Also, I guess I could use a unique tag for every Project and make a stream that filters on that tag. But that seems fragile, as some people may not add those tags.

Posted in Enterprise Collaboration | Tagged , | Leave a comment

Serializing and Deserializing derived types or interfaces in WCF

Often you will have the case where you can take as input into a WCF operation contract a base type, which could be one of many derived types, or an interface that could be implemented by many

different classes. Similarly you could be returning a base type or an interface. WCF supports those scenarios fairly well, and is able to handle serialization and deserialization for them.

However, you have to do a few extra things to provide WCF the extra information it needs to work correctly. This blog will tell you what they are…

Lets say I have a service defined like this:

namespace MyNamespace
{
    [ServiceContract]
    public interface IMyServiceInterface
    {
            [OperationContract]
            [WebGet(UriTemplate = "MyObjects",
              ResponseFormat = WebMessageFormat.Json)]
            BaseResponse GetMyObjects(uint projectID,
                                       BaseRequest breq);
    }

    // Here BaseRequest and BaseResponse are 2 base classes 
    // and lets say each has 2 derived classes:
    [DataContract]
    public class BaseRequest
    {
        uint reportID;
    }

    [DataContract]
    public class DerivedRequest1 : BaseRequest
    {
        uint componentID;
    } 

    [DataContract]
    public class DerivedRequest2 : BaseRequest
    {
        uint screenID;
    }

    [DataContract]
    public class BaseResponse
    {
    }

    [DataContract]
    public class DerivedResponse1 : BaseResponse
    {
    } 

    [DataContract]
    public class DerivedResponse2 : BaseResponse
    {
    }

    // Lets say the implementation of that 
    // service is like this:
    public class MyService
    {
        public BaseResponse GetMyObjects(uint
                      projectID, BaseRequest breq)
        {
            BaseResponse bres = null;    

            if (breq is DerivedRequest1)
            {
                bres = new DerivedResponse1(projectID);
            }
            else if (breq is DerivedRequest2)
            {
                bres = new DerivedResponse2(projectID);
            }

            return bres;
        }
    }
}

Now the question is how does WCF know to serialize DerivedResponse1 and DerivedResponse2, and deserialize DerivedRequest1 and DerivedRequest1?

Firstly you have to tell it using the KnownType attribute on the base contracts themselves. Something like this:

[DataContract]
[KnownType(typeof(DerivedRequest1))]
[KnownType(typeof(DerivedRequest2))]
public class BaseRequest
{
} 

[DataContract]
[KnownType(typeof(DerivedResponse1))]
[KnownType(typeof(DerivedResponse2))]
public class BaseResponse
{
}

That should be enough to get it to serialize DerivedResponse1 and DerivedResponse2 but for an incoming request, it does not know which derived request to deserialize to.

Lets say this is how we are making the call to the service from Javascript (using Mootools):


var args = new Object();
args.projectID = 2;
args.breq = new Object();
args.breq.reportID = 4;
args.breq.componentID = 3; 

var req = new Request.JSON(
          {
              url: 'myserviceurl',
              headers: { 'Content-Type': 'application/json' }
          }); 

req.addEvent("success", successfn);
req.addEvent("failure", failurefn);
req.send(JSON.encode(args));

This will fail because WCF will not know that the breq object there was actually meant to be DerivedRequest1. It has to be told that. You can do that by adding a special “__type” (thats a double underscore) member to the breq object. Something like this:

var args = new Object();
args.projectID = 2;
args.breq = new Object();

// Specifying the type of the object as it
// can be of multiple types 
args.breq.__type = "DerivedRequest1:#MyNamespace"; 

args.breq.reportID = 4;
args.breq.componentID = 3; 

var req = new Request.JSON(
          {
              url: 'myserviceurl',
              headers: { 'Content-Type': 'application/json' }
          }); 

req.addEvent("success", successfn);
req.addEvent("failure", failurefn);
req.send(JSON.encode(args));

Now this will work correctly with WCF being able to correctly deserialize breq into DerivedRequest1. The same holds true if instead of the base types you had interfaces that were being implemented

by multiple classes. With the extra information provided by using the KnownType attribute and the “__type” member, you can get the behavior you expect.

Now you can use a client side stub generator, especially if you’re not making the request from JavaScript and you wont have to deal with the “__type” variable, as the stub should be able to insert in that for you.

Digg This
Posted in JavaScript, Mootools, web services | Tagged , , | 6 Comments

Hitting a WCF service from a Perl script on Linux, using JSON::RPC

Another post to show how different platforms can be connected together using services. I feel these kinds of examples are important to get buy in for Service Oriented Architectures within the enterprise.

I wrote up a little perl script running on linux that hits a WCF service installed on a windows box (running an IIS web server). In the script I use JSON::RPC, a freely available Perl module.

To run it you need to install 2 perl modules: JSON and JSON::RPC. I also use the Data::Dumper module to print out the results but you don’t have to. You can just write out the results on the screen using Perl’s print function.

Once you have the modules installed, here is the script that hits the service.

#!/usr/local/bin/perl

use JSON::RPC::Client;
use Data::Dumper;

my $client = new JSON::RPC::Client;

# URL for the WCF service
my $uri = 'http://mysrv.com/services/mysvc.svc/mysvcmethod;

# args to the service request, already jsonized
my $obj =  { "reportId" => 1, "projectId" => 126 };

# make the call
my $res = $client->call($uri, $obj);

if ($res) {
    if ($res->is_error) {
        print "Error : $res->error_message";
    }
    else {
        # everything looks good... print the response
        print Dumper($res);
    }
}
else {
     print $client->status_line;
}

Steps for installing required Perl modules

Here are some steps for installing the above mentioned Perl modules in your user directory, if you don’t have permissions to install them in your root directory.

First, download the tar files for the modules. Then:

cd ~
tar xzvf 
cd 
perl Makefile.PL PREFIX=/home/user/
make
make install
setenv PERL5LIB /home/user/lib/perl5/site_perl/5.8.5
Posted in web services | Tagged , , | 1 Comment

More on the war to control the web

One of the biggest wars going on in the tech world is about who will control the platform for web development.

The main players:

  • Microsoft (via Silverlight)
  • Adobe (via Flash)
  • Google (via HTML5)

Adobe’s Flash platform is by far the most common platform for RIAs, even in the enterprise. Here are some numbers (published by adobe)

image

Source: http://www.adobe.com/products/player_census/flashplayer/enterprise_penetration.html

HTML5 is being touted as the next big thing, and with Google backing it, it may be.

However this tweet by Scobleizer caught my attention:

Reading the latest drama about HTML5 it seems like Silverlight has a chance to make major inroads this year: http://bit.ly/8qcoNn. Sigh.

As someone who is affected by the outcome of this war, my advice is to build service oriented architectures where you don’t tie yourself to one of these technologies.

Digg This
Posted in web services | Tagged , , , | Leave a comment

Calling WCF Services from a Linux C++ Client Using gSOAP

Before I get into part II of my earlier post about Configuring and Debugging WCF Services, I want to write about a problem I solved recently. Took a lot of digging around and so I thought I would save someone time by making this post.

Disclaimer: I am primarily a Windows Developer. I usually don’t have any issues going between platforms, languages and such but by no means am I an expert on the Linux platform (or on SOAP for that matter).

The Motivation

The basic problem I was trying to solve was trying to hit a WCF service from Linux using C++. Why was I doing that you might ask. Well, in most environments out there today, programmers and architects have to make heterogeneous systems work together and deal with  legacy systems that will not die (the reasons are many, and complicated).

Service Oriented Architectures come with the promise of making this integration between different platforms easy to achieve, maintain and evolve. However, choosing the technologies to implement SoA in is an important decision, as to be useful, the services you create should be accessible from every platform easily. Only then will you get the buy in needed for SoA to succeed.

gSOAP

gSOAP is a technology that allows you to create stubs for client and server side code from WSDLs. There is a lot more that gSOAP can do but I only used it for creating the client side stubs using the WSDL I got from my WCF service.

You can read all about it here.

Making it Work

OK, let’s get down to how we can use gSOAP to access a WCF service using a C++ client. The steps I had to take were

  1. Install the gSOAP library on my Linux box, in my local directory
  2. Generate the SOAP stubs for the target WCF service
  3. Create the client

Here are the steps again with many more details:

Install the gSOAP library

1. Download the gSOAP tar file. The website is here.

wget http://sourceforge.net/projects/gsoap2/files/gSOAP/2.7.14%20stable%20%28update%29/gsoap_2.7.14.tar.gz/download

2. Untar the file.

tar -xvzf packagename.tar.gz

3. Make and install. Run the following commands.

./configure

make

// The exec_prefix is to install in your home directory
make install exec_prefix=$HOME

Generate the SOAP stubs for the target service.

I installed gSOAP in my home directory. Also lets assume that the service I am trying to connect to exposed an endpoint with BasicHttpBinding, which boils down to simple SOAP. And it is located at the following address

http://www.myserver.com/myWCFservice.svc

and the method I am trying to invoke has the following signature:

// The service implements the IMyService interface 
// and the interface has the GetCount method on it
int IMySevice.GetCount(string inputString)

You would need to execute the following commands to get your SOAP stubs:

Go to the appropriate directory for the platform you are on.

cd /lib/gSOAP/gsoap-2.7/gsoap/bin/linux386

Generate the WSDL header file.

./wsdl2h -o mywcfheader.h http://myserver.com/myWCFService.svc?wsdl

Generate the stub files by executing the gSOAP compiler

./soapcpp2 -I "/lib/gSOAP/gsoap-2.7/gsoap/" mywcfheader.h

At this point you should have the stub files in you directory. As far as the client is concerned, you care about these files

File Name

Description

BasicHttpBinding_IMyService.GetCount.req.xml Example SOAP Request
BasicHttpBinding_IMyService.GetCount..res.xml Example SOAP Response
soapBasicHttpBinding_IMyServiceProxy.h C++ Proxy that wraps the SOAP calls that are made on the client side into an Object Oriented interface. The client you write will consume this.
BasicHttpBinding_IMyService.nsmap File that defines the name space (for versioning of the SOAP protocol) of various schema prefixes
soapC.cpp, soapClient.cpp, soapClientLib.cpp, soapH.h and soapStub.h Client Side SOAP Code that the C++ proxy consumes

Create the client.

The client code is pretty simple. It looks something like this:

// This will be the name of the proxy file created when
// you generate the stubs
#include “soapBasicHttpBinding_IMyServiceProxy.h”

// This will be the nsmap file created when you created
// the stubs
#include “BasicHttpBinding_IMyService.nsmap”

using namespace std;

int main()

{
    // This will be the name of the service
    // class in the proxy header file from above
    BasicHttpBinding_IMyService s;

    // This is the request and response that
    // the service you are trying to call takes.
    // Again you can find the types in the class
    // used in the C++ proxy header
    _ns1__GetCount req;
    _ns1__GetCountResponse resp;

    string is(”Hello There America”);
    req.inputString = &is;

    int err = s.__ns1__GetCount(&req, &resp);

    if (SOAP_OK == err)
        cout << “Service Returned: ” << *resp.GetCountResult << endl;
    else
        cout << “Error: ” << err << endl;

    return 0;
}
2: // This will be the name of the proxy file created when
3: // you generate the stubs
4: #include “soapBasicHttpBinding_IMyServiceProxy.h”
5:
6: // This will be the nsmap file created when you created
7: // the stubs
8: #include “BasicHttpBinding_IMyService.nsmap”
9:
10: using namespace std;
11:
12: int main()
13: {
14:         // This will be the name of the service
15:         // class in the proxy header file from above
16:         BasicHttpBinding_IMyService s;
17:
18:         // This is the request and response that
19:         // the service you are trying to call takes.
20:         // Again you can find the types in the class
21:         // used in the C++ proxy header
22:         _ns1__GetCount req;
23:         _ns1__GetCountResponse resp;
24:
25:         string is(“Hello There America”);
26:         req.inputString = &is;
27:
28:         int err = s.__ns1__GetCount(&req, &resp);
29:
30:         if (SOAP_OK == err)
31:                 cout << “Service Returned: ” <<
32:                     *resp.GetCountResult << endl;
33:         else
34:                 cout << “Error: ” << err << endl;
35:
36:         return 0;
37: }
38:

Since our binding is BasicHttpBinding, the WCF service expects SOAP 1.1 as the protocol. By default gSOAP 2.7 talks in SOAP 1.2. So we need to make sure that we make changes required to generate a client that will communicate using SOAP 1.1.

We can do this by changing the following in your *.nsmap and C++ Proxy header file.

Change:

{“SOAP-ENV”, “http://www.w3.org/2003/05/soap-envelope”, “http://www.w3.org/2003/05/soap-envelope”, NULL},
{“SOAP-ENC”, “http://www.w3.org/2003/05/soap-encoding”, “http://www.w3.org/2003/05/soap-encoding”, NULL},
{“xsi”, “http://www.w3.org/2001/XMLSchema-instance”, “http://www.w3.org/*/XMLSchema-instance”, NULL},
{“xsd”, “http://www.w3.org/2001/XMLSchema”, “http://www.w3.org/*/XMLSchema”, NULL}

to

{“SOAP-ENV”, “http://schemas.xmlsoap.org/soap/envelope/”, NULL, NULL},
{“SOAP-ENC”, “http://schemas.xmlsoap.org/soap/encoding/”, NULL, NULL},
{“xsi”, “http://www.w3.org/2001/XMLSchema-instance”, NULL, NULL},
{“xsd”, “http://www.w3.org/2001/XMLSchema”, NULL, NULL}

I found this information here.

Compile the client

Now we are ready to compile the client. Besides the client code you write and the stub files generated by gSOAP, we also need to supply the compiler with another file stdsoap2.cpp that comes with the installation. Also we need to add the gSOAP lib path to the include path so that it can pick up the appropriate libraries it needs.

The command will look like this:

g++ -I "/lib/gSOAP/gsoap-2.7/gsoap" myclient.cpp soapC.cpp soapClient.cpp /lib/gSOAP/gsoap-2.7/gsoap/stdsoap2.cpp

At this point things should work. Leave comments if something does not work for you or if there are other ways to do this.

Posted in web services | Tagged , , | 11 Comments