Friday, February 5, 2010

New layout for the blog

@YaronNaveh

After getting some feedback I have finally decided to change the blog layout.

Old layout:



New layout:



I saw that due to size changes some code snippets in several posts have been trnucated. If you happen to find any let me know.

@YaronNaveh

What's next? get this blog rss updates or register for mail updates!

Wednesday, February 3, 2010

Test-free features?

@YaronNaveh

At some mature stage of a system development we replace all of these messages:


throw new Exception("should never see this")


with something more customer oriented:


throw new Exception("An error has occur while loading the document. Please verify it is in the correct format. ")


Or even better - doing globalization:


throw new Exception(Resources.UnknownLoginError)


These changes are not expected to cause any non-UI regressions, right?

Consider the case where we originally had this


String.Format("Cannot download url");


And now the documentation guys kindly asked to change to this:


String.Format("Cannot download url {0}", url);


or this:


String.Format("Cannot download url {0} using credentials {1}:{2}", url, user, pass);


A mismatch between the number of tokens in the string to the actual provided parameters may result in this error:


Index (zero based) must be greater than or equal to zero and less than the size of the argument list.


Conclusion: Proofing/Localizing always require running all your tests and doing a regression cycle.

@YaronNaveh

What's next? get this blog rss updates or register for mail updates!

Saturday, January 30, 2010

Google & Xml – Not a love story :)

@YaronNaveh


I have just finished my Soap-less Google post and used Google calendar to remind me of my next post:

image

A moment later I enter that event to edit it and this is what I see:

image

I double checked and this issue is consistent. I’m not sure it it’s a long beta thing or just a protobuf Upselling but someone in Google really hates Xml…

@YaronNaveh

What's next? get this blog rss updates or register for mail updates!

Google API’s are Soap-less

@YaronNaveh

 
A few months ago Google officially retired its Soap search Api and put an Ajax search Api instead. The official reason was that it’s moving to a “new generation” Api, however some comments claimed for a conspiracy where Google is trying to push ads into the results or trying to prevent consumers from reordering them. Since Google’s search engine main business is ads it makes sense for them to reduce the number of non-Html Api consumers.

Google Apps however do not rely solely on ads. When organizations pay to get their domains in apps they expect to get some Api for their calendar, documents and etc. With this Api Google chose to be Rest/Atom based.

And I haven’t mentioned yet Google Protocol Buffersa proprietary an open source serialization format developed by Google.

It seems Google likes to do stuff its own way. In some cases it’s a commercial trick to force its ads on Api users. This is a legitimate move but as long as they insist the real reason is a better “new generation” we can call it a trick. In other cases Google claim their new format is better than existing ones. protobuf is one example. However it’s a shame that every vendor comes up with its own formats. In this particular case, some of the other encodings in the market include Microsoft binary xml encoding  and xml fast infoset.

If you’re really into this Soap & Search thing try the Bing Wsdl

@YaronNaveh

What's next? get this blog rss updates or register for mail updates!

Saturday, January 23, 2010

Schema repository on your machine

@YaronNaveh

Sometimes it is useful to look at some of the known xsd schemas. These schemas are the xsd schema itself, the soap schema, the schema of wsdl and much more.
If you have VS 2008 installed then check out this folder:


%Program Files%\Microsoft Visual Studio 9.0\Xml\Schemas


It contains all of these schemas and more.

@YaronNaveh

What's next? get this blog rss updates or register for mail updates!

Friday, January 22, 2010

ReSharper and NUnit - A word of warning

@YaronNaveh

A lot of people prefer the shiny ReSharper test runner over the NUnit GUI. The main reason is of course that it is embedded in the VS IDE.

In some cases this means trouble.

Let's look in this test:


[Test]
[ExpectedException(ExpectedMessage = "my error", MatchType=MessageMatch.Contains)]
public void myUnitTest()
{
  throw new Exception("my error");
}


Does this test pass or fail? It depends who you ask.

ReSharper says:



NUnit says:



The reason is that the ReSharper runner does not know the "ExpectedException" attribute of NUnit. Who knows, maybe it's just a version thing and some x.y.z version of ReSharper knows how to work with the u.v.w version of NUnit. The lesson is that when you have two clocks you never know what the real time is...

@YaronNaveh

What's next? get this blog rss updates or register for mail updates!

Interoperability Gotcha: "These members may not be derived"

@YaronNaveh

The following gotcha applies when the server is written in a Java framework (e.g. Axis) and the client is in .Net. When we "add service reference" in VS to create the client proxy from the wsdl we may get this error:


Custom tool error: Unable to import WebService/Schema. Unable to import binding 'SomeBinding'
from namespace 'http://SomeNamespace'. Unable to import operation 'myOpereration'.
These members may not be derived.


In order to understand what this means we need to take a look at some other (valid wsdl):


<s:element name="EchoString">
 <s:complexType>
  <s:sequence>
   <s:element minOccurs="0" maxOccurs="1" name="s" type="s:string"    />
  </s:sequence>
 </s:complexType>
</s:element>
...
<wsdl:message name="EchoStringSoapIn">
 <wsdl:part name="parameters" element="tns:EchoString" />
</wsdl:message>
...
<wsdl:portType name="SimpleServiceSoap">
 <wsdl:operation name="EchoString">
  <wsdl:input message="tns:EchoStringSoapIn" />
  <wsdl:output message="tns:EchoStringSoapOut" />
 </wsdl:operation>
</wsdl:portType>


This means that the EchoString operation accepts a message that looks like that:


<EchoString xmlns="...">
 <s>some string</s>
</EchoString>


We might expect the proxy class to look something like that:


string EchoString(EchoStringRequest req) {...}

class EchoStringRequest
{
  string s;
}



However the real proxy looks like this:


string EchoString(string s) {...}


Why?
The reason is that most wsdls use the "document/literal/wrapped" pattern. This means that the first element of the message ("EchoString" here) is just some wrapper that the user does not really care about. What our user cares about is the "s" parameter. So the proxy generated the more useful proxy.

But let's take a look at this schema:


<s:element name="EchoString" type="tns:SomeBaseType" />

<xs:complexType name="SomeBaseType">
  <xs:sequence>
   <xs:element name="inParent" type="xs:integer"/>
  </xs:sequence>
</xs:complexType>

<xs:complexType name="SomeDerivedType">
  <xs:complexContent>
   <xs:extension base="tns:SomeBaseType">
    <xs:sequence>
     <xs:element name="inChild" type="xs:integer"/>
    </xs:sequence>
   </xs:extension>
  </xs:complexContent>
</xs:complexType>


Here the root element "EchoString" is not a dummy wrapper - it can take the form of a few types (since there is derivation). This means the proxy should not omit it.

So how does VS knows which proxy to create?

The answer is in the message definition in the wsdl:


<wsdl:message name="EchoStringSoapIn">
 <wsdl:part name="parameters" element="tns:EchoString" />
</wsdl:message>


Whenever the name of a part is "parameters" .Net assumed doc/lit/wrapped is used and generates the proxy accordingly. If even though the word "parameters" is used the wsdl is not doc/lit/wrapped (as in the last example) .Net may give us some error. Which error? You guessed correctly: "These members may not be derived". Now we can understand what the error means: .Net tries to omit the root element as it thinks doc/lit/wrapped is used. However this element cannot be removed since it is not dummy - it should be actively chosen by the user out of a few derived types.

Fix
The way to fix it is open the wsdl in a text editor and change the part name from "parameters" to "parameters1". Now .Net will know to generate a doc/lit/bare proxy. This means a new wrapper class will appear as the root parameter in the proxy. While this may be a little more tedious api, this will not have any affect on the wire format and the proxy is fully interoperable.

@YaronNaveh

What's next? get this blog rss updates or register for mail updates!