Anfang der Woche hat mich ein Arbeitskollege danach gefragt, ob es möglich ist Interfaces oder abstrakte Klassen als Parameter an (WCF-)Service-Methoden zu übergeben. Zunächst war mir nicht ganz klar, was er eigentlich vor hatte, dabei liegt es klar auf der Hand. Die Frage war, ob man das Prinzip des Polymorphismus der Objektorientierung auch auf WCF-Services anwenden kann.
Meine erste Antwort: Ja, klar!
Nicht ganz so klar, wie sich später herausstellte …
Continued…
Categories: Programming, Web.
Tags: Polymorphism, serialization, SOA, WCF, Web Services
By stj
—
October 19, 2007 at 11:01 pm
Gestern abend laß ich im Visions Weekly, dass Stereogum “DRIVE XV: A Tribute To Automatic For The People” veröffentlicht haben. Ich musste nicht zweimal überlegen und habe mir das Album sofort runtergeladen. Das Original steht schließlich nicht umsonst in meinem Plattenschrank – ein Meisterwerk. Also schnell alle MP3s runtergeladen und auf meinen iPod gespielt, Kopfhörer auf und … AHHHHHHHHHH … Schmerz … Ohrenkrebs!
Ich musste mich wirklich selbst zwingen auch nur einen Song komplett zu hören. Eine absolute Tortur.
Einige Songs sind kaum wiedererkennbar. Bei anderen habe ich das Gefühl, es stand bei der Aufnahme eine jaulende Katze vor’m Mikrophone. Dieses Tribute hat mir echt den gestrigen Abend verdorben.
Hört selbst (oder besser nicht!):
you should see the stereogum.com drive xv player here if you have flash
Categories: Music.
Tags: Music, REM
By stj
—
October 14, 2007 at 11:42 am
At the very beginning of the ongoing work of my "Projektgruppe" we had to convert an existing XSD into a DataContract compliant schema. The XSD was part of the WSDL of one of our services which we developed using a contract-first approach. One complex type contained a xs:choice element which is not supported by DataContracts (see Data Contract Schema Reference). Therefore we decided to change our XSD. Retrospectively, maybe this was not the best decision. We discussed the usage of polymorphism with the help of xsd extension but didn't use it at all.
Nevertheless, the good old XmlSerializer supports xs:choice! Here's a very simple example:
C#:
-
using System;
-
using System.Collections.Generic;
-
using System.IO;
-
using System.Runtime.Serialization;
-
using System.ServiceModel;
-
using System.Text;
-
using System.Xml.Serialization;
-
using System.Xml;
-
using System.Xml.Schema;
-
-
namespace Choice
-
{
-
[ServiceContract(Name="ChoiceService", Namespace="http://dev.janus-net.de/example/choice")]
-
[XmlSerializerFormat(Style = OperationFormatStyle.Document)]
-
public interface IChoiceService
-
{
-
[OperationContract()]
-
void DoSomething(XSDChoice choice);
-
}
-
-
[ServiceBehavior(Name="ChoiceService", Namespace="http://dev.janus-net.de/example/choice")]
-
public class ChoiceService : IChoiceService
-
{
-
public void DoSomething(XSDChoice choice)
-
{
-
System.Console.WriteLine(choice.ToString());
-
}
-
}
-
-
[Serializable]
-
public class XSDChoice
-
{
-
-
[XmlChoiceIdentifier("ChoiceType")]
-
[XmlElement
("Choice1",
typeof(string), IsNullable =
false)]
-
[XmlElement
("Choice2",
typeof(double), IsNullable =
false)]
-
public object MyChoice;
-
-
[XmlIgnore]
-
[XmlElement(IsNullable=false)]
-
public ItemChoiceType ChoiceType;
-
-
public override string ToString()
-
{
-
string info = null != MyChoice ?
-
(":Type<" + MyChoice.GetType() + ">,Value<" + MyChoice.ToString() + ">")
-
: (":Type<object>,Value<null>");
-
if (ChoiceType == ItemChoiceType.Choice1)
-
{
-
return "Choice1:" + info;
-
}
-
else if (ChoiceType == ItemChoiceType.Choice2)
-
{
-
return "Choice2:" + info;
-
}
-
else
-
{
-
return info;
-
}
-
}
-
}
-
-
[XmlType(IncludeInSchema = false)]
-
public enum ItemChoiceType
-
{
-
None,
-
Choice1,
-
Choice2
-
}
-
}
This will result in the following XSD:
XML:
-
<xs:complexType name="XSDChoice">
-
<xs:sequence>
-
<xs:choice minOccurs="1" maxOccurs="1">
-
<xs:element minOccurs="1" maxOccurs="1" name="Choice2" type="xs:double"/>
-
<xs:element minOccurs="0" maxOccurs="1" name="Choice1" type="xs:string"/>
-
</xs:choice>
-
</xs:sequence>
-
</xs:complexType>
You can even do much more complex things using the XmlSerializer in conjunction with Service Contracts. Designing Service Contracts with WCF by Michele Leroux Bustamante gives a very very good introduction.
Categories: Programming, Web.
Tags: .Net, c#, Contracts, POETS, serialization, SOA, WCF, WSDL, XmlSerializer, XSD
By stj
—
August 7, 2007 at 10:57 pm
The last few days I struggled a lot with WCF endpoints while configuring them running with least privileges. As already mentioned in my post WCF: Namespace Reservierung there are several tools simplifying this procedure. Nevertheless I wanted to write my own little tool with a GUI. The tool works fine so far (go and grep a copy from here) but there's something really annoying.
It's this error I get when calling HttpQueryServiceConfiguration:
FatalExecutionEngineError was detected
Message: The runtime has encountered a fatal error. The address of the error was at "0x79e8a634", on thread "0x1be8". The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or on-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.
When executing httpcfg query urlacl I get these two reservations:
URL : http://*:2869/
ACL : D:(A;;GX;;;LS)
URL : http://+:80/Temporary_Listen_Addresses/
ACL : D:(A;;GX;;;WD)
On executing my code (see below) everything is ok. I get exactly the same results as above. However, after adding a third reservation with httpcfg set urlacl ... I get this annoying error.
At this point I should mention that I'm not very familiar with pinvoke and interop, but I want this to work. So, what am I missing or doing wrong? Any answers or suggestions will be appreciated.
Continued...
Categories: Programming.
Tags: .Net, c#, httpcfg, Namespaces, PInvoke, WCF
By stj
—
May 27, 2007 at 6:14 pm
Ein Kommilitone von mir, der sonst hauptsächlich im Java-Umfeld programmiert, stellte mir heute die Frage, warum er folgendes in C# nicht machen kann:
C#:
-
interface IInterface
-
{
-
void Method();
-
}
-
-
abstract class Base : IInterface
-
{
-
}
Folgendes funktioniert nämlich in Java problemlos:
Continued...
Categories: Programming.
Tags: .Net, c#, Java
By stj
—
May 16, 2007 at 8:41 pm