SOAP - Strong Typing in SOAP

What is Strong Typing in SOAP?

  • Strong typing means that every piece of data in a SOAP message has a well-defined type (string, int, dateTime, custom object, etc.).

  • These types are defined in the WSDL using XML Schema (XSD).

  • Because of this, the client and server must strictly follow the contract — no guessing.


Why SOAP Enforces Strong Typing

  1. Predictability

    • The client always knows exactly what kind of data to send and expect back.

    • Example: if the WSDL says Age is an int, you can’t suddenly send "thirty".

  2. Validation

    • Incoming and outgoing XML can be validated against the XSD to catch errors early.

  3. Interoperability

    • Even if client and server are written in different languages (C#, Java, PHP), the strict contract ensures they understand each other.


Example in WSDL (XSD Types)

<xs:element name="Person">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="Name" type="xs:string"/>
      <xs:element name="Age" type="xs:int"/>
      <xs:element name="BirthDate" type="xs:date"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>
  • Name → string

  • Age → int

  • BirthDate → date


SOAP Request Example

<soap:Body>
  <AddPerson xmlns="http://example.com/person">
    <Person>
      <Name>John</Name>
      <Age>30</Age>
      <BirthDate>1995-05-20</BirthDate>
    </Person>
  </AddPerson>
</soap:Body>

✅ Valid → Matches schema (string, int, date).
❌ Invalid → If you sent <Age>thirty</Age>, the server would reject it.


In C# / .NET

When you import a WSDL in Visual Studio, it auto-generates strongly typed classes:

public class Person {
    public string Name { get; set; }
    public int Age { get; set; }
    public DateTime BirthDate { get; set; }
}

So you can safely call the service like this:

var person = new Person {
    Name = "John",
    Age = 30,
    BirthDate = new DateTime(1995, 5, 20)
};

serviceClient.AddPerson(person);

If you try Age = "thirty", the code won’t even compile.


Pros & Cons of Strong Typing in SOAP

Advantages

  • Predictable, reliable communication.

  • Errors caught early (compile-time or schema validation).

  • Great for enterprise systems with strict contracts.

Disadvantages

  • Messages become verbose (lots of XML).

  • Less flexible (small changes in schema may break clients).


In short:
Strong typing in SOAP means that all data must strictly follow the types defined in the WSDL (via XML Schema). This makes communication predictable and safe, but at the cost of flexibility and verbosity.