Skip to main content

Crate soap_server

Crate soap_server 

Source
Expand description

§soap-server

A WSDL-driven SOAP 1.1/1.2 server library for Rust, built on top of axum. Provide a WSDL file, register async handler closures for each operation, and get a SOAP 1.1/1.2 endpoint with no boilerplate envelope handling. soap-server is a transport + dispatch layer — not a code generator or full XSD validator (see the Capabilities & Limitations page in the user guide for the precise scope).

§Features

  • SOAP 1.1 and 1.2 — auto-detects version from Content-Type and envelope namespace; responds in the same version as the request.
  • WSDL-driven dispatch — operations are discovered from the WSDL at build time. Registering a handler for an unknown operation is a build-time error.
  • WS-Security (UsernameToken) — supports PasswordDigest and PasswordText authentication with nonce replay detection and timestamp freshness checks.
  • XSD structural validation — required elements are validated against the WSDL/XSD schema before the handler is called.

§Quick start

use soap_server::{FnHandler, ServerBuilder, SoapFault};
use bytes::Bytes;

#[tokio::main]
async fn main() {
    let svc = ServerBuilder::from_wsdl_file("path/to/service.wsdl")
        .handler(
            "MyOperation",
            FnHandler::new(|_body: Bytes| async move {
                // Parse body, call business logic, return response XML bytes.
                Ok::<Bytes, SoapFault>(Bytes::from(
                    r#"<MyOperationResponse xmlns="urn:example"/>"#,
                ))
            }),
        )
        .build()
        .expect("WSDL build failed");

    let router = svc.into_router();
    let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await.unwrap();
    axum::serve(listener, router).await.unwrap();
}

§WS-Security

Call .auth(|username| { /* return password or None */ }) on the builder. Operations that require authentication return a Sender fault if the <wsse:Security> header is missing or invalid. Use .auth_bypass([...]) to exempt specific operations (e.g. clock-sync operations).

§Multi-WSDL / multi-service

Call SoapService::into_router() on each service and merge the resulting axum::Router instances — each service mounts at its own path derived from the WSDL <service><port address> element.

Re-exports§

pub use crate::dispatch::build_dispatch_table;
pub use crate::dispatch::DispatchTable;
pub use crate::fault::FaultCode;
pub use crate::fault::SoapFault;
pub use crate::handler::FnHandler;
pub use crate::handler::SoapHandler;
pub use crate::xml_escape::escape_attr;
pub use crate::xml_escape::escape_text;

Modules§

dispatch
fault
SOAP fault types and serialization for SOAP 1.1 and 1.2.
handler
xml_escape
XML character escaping helpers.

Structs§

FileWsdlLoader
A WsdlLoader that resolves import locations relative to a base directory on the filesystem. Used automatically when ServerBuilder::from_wsdl_file() is called.
RotatingNonceCache
Two-bucket rotating nonce cache for WS-Security replay detection.
ServerBuilder
Builder for a SoapService. Accumulates WSDL source, handlers, auth config, and routing.
SoapService
A fully configured SOAP service that can be converted into an axum Router.

Enums§

BuildError
Errors that can occur during ServerBuilder::build().
WsdlError
Error type for WSDL parsing failures.

Traits§

WsdlLoader
Abstracts file/network I/O for loading WSDL files during recursive import resolution.

Functions§

validate_username_token
Validate a WS-Security UsernameToken from a raw <wsse:Security> XML element.