soap_server/lib.rs
1//! # soap-server
2//!
3//! A WSDL-driven SOAP 1.1/1.2 server library for Rust, built on top of
4//! [axum](https://docs.rs/axum). Provide a WSDL file, register async handler
5//! closures for each operation, and get a SOAP 1.1/1.2 endpoint with no
6//! boilerplate envelope handling. `soap-server` is a transport + dispatch layer —
7//! not a code generator or full XSD validator (see the Capabilities & Limitations
8//! page in the user guide for the precise scope).
9//!
10//! ## Features
11//!
12//! - **SOAP 1.1 and 1.2** — auto-detects version from `Content-Type` and envelope
13//! namespace; responds in the same version as the request.
14//! - **WSDL-driven dispatch** — operations are discovered from the WSDL at build time.
15//! Registering a handler for an unknown operation is a build-time error.
16//! - **WS-Security (UsernameToken)** — supports PasswordDigest and PasswordText
17//! authentication with nonce replay detection and timestamp freshness checks.
18//! - **XSD structural validation** — required elements are validated against the
19//! WSDL/XSD schema before the handler is called.
20//!
21//! ## Quick start
22//!
23//! ```rust,no_run
24//! use soap_server::{FnHandler, ServerBuilder, SoapFault};
25//! use bytes::Bytes;
26//!
27//! #[tokio::main]
28//! async fn main() {
29//! let svc = ServerBuilder::from_wsdl_file("path/to/service.wsdl")
30//! .handler(
31//! "MyOperation",
32//! FnHandler::new(|_body: Bytes| async move {
33//! // Parse body, call business logic, return response XML bytes.
34//! Ok::<Bytes, SoapFault>(Bytes::from(
35//! r#"<MyOperationResponse xmlns="urn:example"/>"#,
36//! ))
37//! }),
38//! )
39//! .build()
40//! .expect("WSDL build failed");
41//!
42//! let router = svc.into_router();
43//! let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await.unwrap();
44//! axum::serve(listener, router).await.unwrap();
45//! }
46//! ```
47//!
48//! ## WS-Security
49//!
50//! Call `.auth(|username| { /* return password or None */ })` on the builder.
51//! Operations that require authentication return a `Sender` fault if the
52//! `<wsse:Security>` header is missing or invalid. Use `.auth_bypass([...])` to
53//! exempt specific operations (e.g. clock-sync operations).
54//!
55//! ## Multi-WSDL / multi-service
56//!
57//! Call `SoapService::into_router()` on each service and merge the resulting
58//! `axum::Router` instances — each service mounts at its own path derived from
59//! the WSDL `<service><port address>` element.
60
61pub mod dispatch;
62pub(crate) mod envelope;
63pub(crate) mod qname;
64pub(crate) mod server;
65pub(crate) mod wsdl;
66pub(crate) mod wssec;
67pub(crate) mod xsd;
68
69pub mod fault;
70pub mod handler;
71pub mod xml_escape;
72
73pub use crate::dispatch::{build_dispatch_table, DispatchTable};
74pub use crate::fault::{FaultCode, SoapFault};
75pub use crate::handler::{FnHandler, SoapHandler};
76pub use crate::server::{BuildError, FileWsdlLoader, ServerBuilder, SoapService};
77pub use crate::wsdl::parser::WsdlError;
78pub use crate::wsdl::resolver::WsdlLoader;
79pub use crate::wssec::nonce_cache::RotatingNonceCache;
80pub use crate::wssec::username_token::compute_digest;
81pub use crate::wssec::username_token::validate_username_token;
82pub use crate::xml_escape::{escape_attr, escape_text};