सामग्री पर जाएँ

लेसन 18 · WS-Security and Standards

The WS-* Standards: Policy, Trust, MTOM and More

A guided tour of the WS-* family beyond security: WS-Policy, WS-Trust and SAML, MTOM attachments, WS-Coordination and transactions, WS-I profiles, plus runnable policy and attachment demos.

SOAP's reputation for being "heavy" comes from the WS-* specifications: dozens of standards from OASIS, W3C and the WS-I organization that build on the envelope. You have already met WS-Security, WS-Addressing and WS-ReliableMessaging. This lesson is the map of the rest, so that when a partner says "we need WS-Trust with SAML tokens and MTOM", you know what each word means and which ones you can ignore.

The map

mindmap
  root((WS-*))
    Describe
      WSDL
      XML Schema
      WS-Policy
      WS-MetadataExchange
    Message
      SOAP
      WS-Addressing
      MTOM and XOP
    Secure
      WS-Security
      WS-SecurityPolicy
      WS-Trust
      WS-SecureConversation
      WS-Federation
    Reliable
      WS-ReliableMessaging
      WS-Coordination
      WS-AtomicTransaction
      WS-BusinessActivity
    Interoperate
      WS-I Basic Profile
      WS-I Basic Security Profile

Most projects use only the upper branches plus one or two security specifications.

WS-Policy and WS-SecurityPolicy

A WSDL says what operations exist, but not which requirements a client must meet: "messages must be signed", "reliable messaging is required", "use TLS". WS-Policy lets a service attach such requirements to the WSDL as policy assertions, grouped into alternatives. WS-SecurityPolicy defines the security assertions: which tokens, which algorithms, which parts to sign and encrypt, and in what order.

XML
<wsp:Policy wsu:Id="OrderPolicy">
  <wsp:ExactlyOne>
    <wsp:All>   <!-- alternative 1 -->
      <sp:TransportBinding>...</sp:TransportBinding>
      <sp:UsernameToken/>
    </wsp:All>
    <wsp:All>   <!-- alternative 2 -->
      <sp:AsymmetricBinding>...</sp:AsymmetricBinding>
      <sp:X509Token/>
    </wsp:All>
  </wsp:ExactlyOne>
</wsp:Policy>

ExactlyOne means: pick one of the alternatives. All means: every assertion inside must be satisfied. The client's own policy is intersected with the service's: they can talk if some alternative is acceptable to both. Frameworks do this automatically; the stand-in below shows the idea.

Node.js Policy alternatives and intersection (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

This simplified version treats alternatives as plain sets of capabilities; real WS-Policy intersection also handles nested policies and assertion parameters.

WS-Trust, SAML and federation

A web service often does not want to know passwords at all. Instead, clients obtain a security token from a trusted Security Token Service (STS) and present that token to the service. WS-Trust defines the request/response protocol to ask an STS for a token (RequestSecurityToken / RequestSecurityTokenResponse). The token is commonly a SAML assertion: a signed XML statement such as "this is [email protected], issued by our identity provider at 09:30, valid until 09:40, with role = clerk".

sequenceDiagram
    participant C as Client
    participant STS as Security Token Service
    participant S as Order service
    C->>STS: RequestSecurityToken (with credentials)
    STS-->>C: SAML assertion (signed)
    C->>S: SOAP request + SAML in wsse:Security
    S->>S: verify signature, issuer, expiry
    S-->>C: response

The service trusts the STS, not the client's password.

WS-SecureConversation lets a client and service set up a security context: after one expensive handshake they share a session key and sign or encrypt many messages cheaply. WS-Federation extends the idea across organizations (single sign-on between companies). In the REST world the same roles are played by OAuth 2.0 and OpenID Connect (see the track on REST APIs and authentication).

Attachments: MTOM and XOP

XML has no binary type: sending a PDF means Base64 encoding, which makes it 33% bigger and slow to parse. MTOM (SOAP Message Transmission Optimization Mechanism) with XOP (XML-binary Optimized Packaging) fixes this: the SOAP message goes in the first part of a multipart/related HTTP body, the raw bytes in other parts, and the XML refers to them with <xop:Include href="cid:...">. To the application the document still looks as if it contained the Base64 data; the framework reassembles it.

TEXT
Content-Type: multipart/related; type="application/xop+xml"; boundary=MIME_boundary

--MIME_boundary
Content-Type: application/xop+xml; type="application/soap+xml"

<env:Envelope> ... <doc><xop:Include href="cid:part1@example"/></doc> ... </env:Envelope>
--MIME_boundary
Content-ID: <part1@example>
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary

(raw bytes)
--MIME_boundary--

The older attachment styles, SwA (SOAP with Attachments) and DIME, are legacy. Use MTOM for anything larger than a few kilobytes. The next program builds both forms of the same payload and compares sizes.

Node.js Base64 inline vs MTOM-style parts

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Transactions and coordination

WS-Coordination defines a general way to coordinate several services in an activity. WS-AtomicTransaction (two-phase commit across services: all commit or all roll back) and WS-BusinessActivity (long-running work with compensation: undo by running a "cancel booking" operation) build on it. They exist, mostly inside .NET WCF and Java application-server products, but distributed two-phase commit scales poorly and most modern systems use the saga pattern: a chain of local transactions with compensating actions, coordinated by your own code.

Interoperability: the WS-I profiles

Because the SOAP, WSDL and WS-* specifications allowed many options, the WS-I (Web Services Interoperability) organization published profiles: lists of rules that narrow the options so different products work together. The Basic Profile (1.1, 1.2, 2.0) says, for example: use document/literal or rpc/literal, never rpc/encoded; use HTTP POST with Content-Type: text/xml; faults must use HTTP 500; WSDL 1.1 must have soap:body use="literal"; do not put the DTD in a message. The Basic Security Profile constrains WS-Security usage. When a toolkit offers an option "WS-I compliant", it turns on those rules. WS-I has since closed, but its profiles still guide good design.

What you actually need

Situation Standards to learn
Call a bank's or government's SOAP service SOAP, WSDL, XSD, usually WS-Security (UsernameToken or signature)
Build an internal service for several teams SOAP/WSDL/XSD, TLS, maybe SAML via an STS
Send documents or scans MTOM
Messages that must not be lost Queues, or WS-RM if the partner mandates it
Need long business transactions Sagas; WS-AT only where required

Most services use three or four of the dozens of specifications. Read the partner's WSDL and policy; they tell you which ones you need.

Check your understanding

Quick check · 5 questions

of 5 answered You scored / 5 · perfect!

  1. 1. What does WS-Policy let a service describe?

    WS-Policy attaches requirements and capabilities to a WSDL; WS-SecurityPolicy defines the security assertions.
  2. 2. Why is MTOM preferred to Base64 for large attachments?

    MTOM sends binary parts raw in a multipart message and refers to them with xop:Include.
  3. 3. What does a Security Token Service do?

    WS-Trust defines how clients request tokens from an STS; services trust the STS instead of handling passwords.
  4. 4. What was the purpose of the WS-I Basic Profile?

    The profile is a set of rules (for example literal use only) that improve interoperability.
  5. 5. Which modern pattern often replaces WS-AtomicTransaction?

    Sagas chain local transactions and undo them with compensation, scaling better than distributed two-phase commit.

Summary

  • WS-* is a family of specifications around SOAP; most projects need only a few.
  • WS-Policy and WS-SecurityPolicy publish a service's requirements; clients and services negotiate a common alternative.
  • WS-Trust and SAML move authentication to an STS; WS-SecureConversation and WS-Federation extend the idea.
  • MTOM sends binary data efficiently as multipart parts.
  • WS-Coordination, AT and BA handle transactions, though sagas are more common today; the WS-I profiles guide interoperability.

Next: SOAP vs REST, Side by Side

अपनी प्रगति ट्रैक करें

मुफ़्त अकाउंट बनाएँ, लेसन पूरे के रूप में चिह्नित करें और किसी भी डिवाइस पर वहीं से शुरू करें जहाँ छोड़ा था।