Jérôme Laban

.NET Powered

WCF, NuSOAP and ArrayOfString

clock April 16, 2007 15:21 by author Jerome

When exposing a WebService via WCF, you might want to expose something like this :

[DataContract]
public class SomeContract
{
  [DataMember] 
  public string[] Values { get; set; }
}

For that particular data contract, WCF will be generating a WSDL with something like this :

<xs:complexType name="SomeContract">
  <xs:sequence>
    <xs:element minOccurs="0" name="Values" nillable="true"
                type="q1:ArrayOfstring"
                xmlns:q1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
  </xs:sequence>
</xs:complexType>

With ArrayOfString being defined like this :

  <xs:schema elementFormDefault="qualified"
             targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays"
             xmlns:xs="http://www.w3.org/2001/XMLSchema"
             xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
    <xs:complexType name="ArrayOfstring">
      <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" name="string" nillable="true" type="xs:string"/>
      </xs:sequence>
    </xs:complexType>
    <xs:element name="ArrayOfstring" nillable="true" type="tns:ArrayOfstring"/>
  </xs:schema>

In general, that would be fine. The type "ArrayOfString" is defined in a different namespace, but this should not be a problem.

So, to use that particular type in a method call, you should have a document like this one :

<SomeContract>
  <Values xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
    <a:string>My Value</a:string>
  </Values>
</SomeContract>

"string" elements are contained in a different namespace from the SomeContract element. However, the NuSOAP stock version 0.7.2 has a problem with that kind of schema, and generates instead something like this :

<SomeContract>
  <Values>
    <string>My Value</string>
  </Values>
</SomeContract>


When the WCF deserializer receives a document like this one, it does not find the "Values" member in the namespace he's looking and ends up creating a SomeContract instance with a null array of strings.

Since there's no way of fixing NuSOAP, you may need to tweak your contract to help NuSOAP serializing your data without a namespace.

The CollectionDataContract attribute seems to be the way to go, since there is a way to specify the namespace to use when generating the metadata. The service contract then looks like this :

  [DataContract(Namespace = "http://my.name.space")] 
  public class SomeContract 
  { 
    [DataMember] 
    public ArrayOfString InvalidIdentifiers { get; set; } 
  } 

  [CollectionDataContract(ItemName="string", Namespace="http://my.name.space")]
  public class ArrayOfString : List<string> { } 

Thereby placing everything in the "http://my.name.space" namespace.

You might need to tweak a bit the ArrayOfString class, especially if you need to assign it from an actual string[] instance, but you get the idea.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


WCF WebService behind a NAT Gateway

clock April 15, 2007 11:06 by author Jerome

I'm currently working on a WCF service that's exposed via a basicHttpBinding, with some exposition of the metadata via a WSDL url.

The metadata generator has been improved a bit since it is now split into multiple files, with references from the first wsdl to other URI's. There's not much to do to have that WSDL generated, and the generator take the liberty of using the machine's name to create reference URIs.

Most of the time, this is a good idea, but sometimes when your machine is behind a NAT gateway doing some port forwarding, your machine probably won't have the public FQDN used to access your gateway. You then end up with a root document referencing URI's with a host name that is not valid on the other side of the gateway.

The solution to change that behavior is quite simple : Just change the host name IIS is listening on. Use the MMC snap-in, and specify that your port 80 (or whatever port you're using) is listening on your external FQDN. WCF will then use that host name when generating URI's. Also don't forget that if you specify a host name, you might need to add an other entry to be able to access your website using "localhost".

This operation is also needed for servers farm when doing some load balancing.

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Unprotecting Protected Processes

clock April 7, 2007 15:09 by author Jerome

Alex Ionescu's been searching a bit about Protected Processes, and he's managed to get around that protected state.

I'm no expert on that part nor have I read enough documentation on how that works, but since a goal of that particular feature is the "Protected Media Path" (PMP) to prevent anyone from eavesdropping a protected media, this is not good.

Since that implementation is based on a driver, that won't work on Vista 64, well, as long as you don't boot in that particular mode that allows you to load unsigned drivers. That's a good news for malware protection, since a virus shoud not be able to hide itself under normal conditions, but this is not for PMP. It seems that protected processes can check for a "tainted" environment, but how long is it going to take for someone to fool programs into thinking the system is clean... ? As always, that won't prevent evil dvd rippers to copy the media... but that'll piss a legitimate user.

Moreover, since it is easily possible in Vista 32, as alex is pointing it out, it probably won't take long for viruses to hide themselves using this technique and just a bit longer for antiviruses to unprotected any running process.

What a mess :)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Vista's Support for External Displays

clock April 7, 2007 10:14 by author Jerome

Among the many hidden new features of vista which belong to the category of "why didn't they do this in the first place", there is the new and improved support for displays and external displays in particular for a laptop.

In Windows XP, when you were attaching a display to your laptop, the resolution (and color depth) used was attached to the physical port, not to the display itself. So if you were moving around a lot with your laptop attaching many displays with many different resolutions, you had to reconfigure each time.

Vista's way is a bit different since the resolution and color depth are now attached to each specific display, and are automatically recalled upon connecting the cable. Now, when you attach a display, you can hear the "device connected" sound, the same used when connecting an USB device or PCMCIA card.

This also goes along with the presentation mode which allows to hide your trolling background when hosting a presentation. This is particularly useful at Epitech :)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


About me

My name is Jerome Laban, I am a Software developer and .NET enthustiast from Montréal, QC. You will find my blog on this site, where I'm adding my thoughts on current events, or the things I'm working on, such as the Bluetooth Remote Control Software for Windows Mobile.

© Copyright 2008

Links

Advertizing

Search

Categories


Tags

Calendar

<<  October 2008  >>
SuMoTuWeThFrSa
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

Archive

Blogroll

Sign in