Skip to content
Tutorials Center
My learning

Topics

Lesson 36 of 36 ยท Projects and Practice

Practice: Exercises and Interview Questions

Test yourself on SOAP and web services - three hands-on debugging exercises with self-checking code, plus a bank of interview questions on envelopes, WSDL, faults, security, REST comparison and migration.

You have now seen the whole path: messages, contracts, security, comparison with REST, building, testing and migrating. This last lesson turns that knowledge into practice. First come three short debugging exercises in the editor, each with a self-check that prints PASS or FAIL. Then a bank of interview questions with model answers, the kind that come up when a job involves integrating with SOAP services.

For the exercises, the code as written contains a bug. Run it once and you will see FAIL lines. Fix the code, run again, and aim for all PASS. Solutions are explained after each exercise, so look only after you tried.

Exercise 1: the unsafe envelope builder

The function below builds a request envelope. Users report that orders for customers named Tom & Jerry or <script> return "XML parse error" from the service. Find and fix the bug.

Node.js Exercise 1: fix the escaping bug

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.

Solution: values placed in XML text must be escaped. Add a helper that replaces & first (always first, or you double-escape), then < and >, and apply it to customerName and sku. Escaping belongs in the one function that builds the XML, so no caller can forget it.

Exercise 2: the fault that was treated as success

The client below checks only the HTTP status. The service returns a SOAP fault with HTTP 200 in one legacy case, and the client reports a successful order. Make isFault robust so that a fault in the body always counts as a failure, whatever the status.

Node.js Exercise 2: detect faults in the body

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.

Solution: return status >= 400 || /<(?:\w+:)?Fault[\s>]/.test(xml). The body is the source of truth: SOAP 1.1 says faults use HTTP 500, but gateways, proxies and old services do not always follow the rule. Note the optional prefix in the pattern; the namespace prefix is whatever the sender chose.

Exercise 3: the contract drift

The two lists below should describe the same service, but a release changed the code. Complete findDrift so it returns the operations present in only one list, and read the output to see which release change was risky.

Node.js Exercise 3: report contract drift

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.

Solution: missingInCode is contract.filter(op => !code.includes(op)), and undocumented is code.filter(op => !contract.includes(op)). CancelOrder missing from the code is the dangerous one: partners can still call an operation that the contract promises but the code no longer serves.

Interview questions

Short model answers; practice saying each in your own words in under a minute.

What is SOAP? A protocol for exchanging structured XML messages between applications. A message is an envelope with an optional header and a mandatory body; it is usually carried over HTTP but can use other transports.

What are the parts of a SOAP message? Envelope (root), Header (optional: security, addressing, transaction context), Body (the operation or response), and inside the body possibly a Fault.

What is WSDL? An XML contract describing a service: types (XSD), messages, operations grouped in port types, bindings (SOAP over HTTP, style, encoding), and ports with addresses.

Document/literal vs RPC/encoded? Document/literal sends XML conforming to a schema and is validatable; RPC/encoded wraps parameters in an operation element with type attributes. RPC/encoded is deprecated by the WS-I Basic Profile; modern services use document/literal (wrapped).

SOAP 1.1 vs 1.2? Different envelope namespace; content type text/xml vs application/soap+xml; SOAPAction header vs action parameter; faults renamed (Client/Server to Sender/Receiver) and restructured; 1.2 is better defined, 1.1 is still everywhere.

How are errors reported? As a Fault element in the Body, with HTTP 500 in SOAP 1.1 (400 or 500 in 1.2). Business-specific data goes in detail.

What is WS-Security? A standard for securing messages themselves: UsernameToken, SAML or X.509 tokens, XML Signature and XML Encryption. It protects data end to end, not only on the connection, unlike TLS.

What else is in WS-*? WS-Addressing (routing and correlation headers), WS-ReliableMessaging, WS-AtomicTransaction, WS-Policy, WS-Trust and WS-Federation.

SOAP vs REST? SOAP is a protocol with a formal contract, XML, standard security and reliability extensions, one endpoint; REST is an architectural style using resources, verbs and status codes, cacheable and lightweight. Pick by requirements; many systems use both.

Why is SOAP not cacheable? Calls are POSTs to one URL, so intermediaries have no URL-and-method key for safe caching.

What is MTOM? A way to send binary attachments efficiently with SOAP, using XOP to move base64 content out of the XML and into MIME parts.

What is an idempotent operation and why does it matter? One that can be repeated without extra effect. Retrying after a time-out is only safe for such operations, or when an idempotency key lets the server deduplicate.

How do you secure a SOAP endpoint? TLS; authentication (WS-Security, mutual TLS or tokens at a gateway); schema validation; input size limits; DTD disabled; no internal details in faults; rate limits; logging with redaction.

What is the XXE attack? An XML parser resolves an external entity declared in the message and reads files or makes requests. Defend by disabling DTDs and external entities in the parser.

How would you migrate a SOAP service to REST? Map operations to resources, put a REST facade in front, translate faults to status codes, move routes gradually with the strangler pattern, run both interfaces during deprecation, and rethink security and transactions.

How do you test a SOAP service? Unit tests for logic and XML building, integration tests over HTTP for faults and headers, contract tests against the WSDL/XSD, mocks and fault injection for failure paths, and a few tests against the real partner system.

What is the tolerant reader? A consumer that reads only the elements it needs and ignores unknown ones, so additive changes do not break it.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In escaping text for XML, which character must be replaced first?

    If you replace < first and & later, the ampersand in < would be escaped again. Always handle & first.
  2. 2. A response has HTTP status 200 but contains a SOAP Fault. What is the correct client interpretation?

    Clients must inspect the body: a Fault element means the operation failed even if the status line says otherwise.
  3. 3. Which statement about WS-Security versus TLS is correct?

    Message-level security survives intermediaries and storage; transport-level security ends at each hop.
  4. 4. Which contract drift is the most dangerous for partners?

    Partners generate clients from the contract, so they will call the missing operation and receive faults.

Summary

  • Escape in one place, detect faults in the body, and compare contract with code automatically.
  • Be able to explain envelopes, WSDL, faults, SOAP 1.1 vs 1.2, WS-Security and WS-* standards in plain words.
  • Be ready to compare SOAP with REST honestly and describe a migration plan.
  • Testing, mocks, idempotency and tolerant readers separate hobby integrations from production ones.

Next: back to the SOAP and Web Services track page to review any chapter, or build your own service from the projects.