wsdlxsdtroubleshootingweb-services

WSDL External Schema Import Failed: Resolving XSD Include and Import Errors

SOAPless Team6 min read

If you've ever tried to generate client code from a WSDL and hit an error like "Could not resolve schema import" or "Failed to load external schema", you know how frustrating XSD resolution failures can be. WSDL files frequently reference external XML Schema definitions using xs:import and xs:include, and when any link in this chain breaks, the entire code generation or parsing process fails.

This guide covers the root causes of external schema import errors, the critical difference between xs:import and xs:include, and how to fix these problems across wsimport, wsdl2java, svcutil, and other tools.

xs:import vs xs:include: Understanding the Difference

These two XSD mechanisms look similar but serve fundamentally different purposes, and confusing them is a common source of errors.

xs:include

xs:include merges schema components from the same target namespace (or no namespace) into the current schema. Think of it as a copy-paste of type definitions.

<!-- Both schemas must share the same targetNamespace -->
<xs:schema targetNamespace="http://example.com/types"
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:include schemaLocation="CommonTypes.xsd"/>
  <xs:element name="Order" type="tns:OrderType"/>
</xs:schema>

xs:import

xs:import brings in schema components from a different namespace. It establishes a namespace dependency between schemas.

<xs:schema targetNamespace="http://example.com/orders"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:types="http://example.com/types">
  <xs:import namespace="http://example.com/types"
             schemaLocation="types/CommonTypes.xsd"/>
  <xs:element name="Order" type="types:OrderType"/>
</xs:schema>

Key rule: Using xs:include when namespaces differ (or xs:import when they match) will cause parsing failures.

Quick Reference

Featurexs:includexs:import
NamespaceSame or absentDifferent
namespace attributeNot allowedRequired
schemaLocationRequiredOptional
SemanticMerge into current schemaReference external namespace
Common analogy#include in Cimport in Java

Common Error Messages and Their Causes

Error 1: schemaLocation Resolution Failure

org.xml.sax.SAXParseException: schema_reference.4:
  Failed to read schema document 'CommonTypes.xsd',
  because the document could not be read.

This typically means the schemaLocation path cannot be resolved. The most common causes:

Relative path base mismatch. When a WSDL at https://api.example.com/services/OrderService?wsdl references schemaLocation="../schemas/types.xsd", the parser must resolve the relative path against the WSDL URL. If the server doesn't serve the schema at that relative location, the fetch fails.

Fix: Use absolute URLs or verify relative path resolution.

<!-- Before: Relative path that may not resolve -->
<xs:import schemaLocation="../schemas/types.xsd"
           namespace="http://example.com/types"/>

<!-- After: Absolute URL that resolves reliably -->
<xs:import schemaLocation="https://api.example.com/schemas/types.xsd"
           namespace="http://example.com/types"/>

Error 2: Network Constraints Preventing Schema Fetch

java.net.ConnectException: Connection timed out
  while resolving schema at https://internal.corp.example.com/schemas/types.xsd

Many enterprise WSDL files reference schemas hosted on internal networks, behind firewalls, or on servers that restrict access. When your development machine cannot reach the schema URL, resolution fails.

Fix: Download and localize the schemas.

# Download all referenced schemas
mkdir -p schemas
curl -o schemas/types.xsd https://internal.corp.example.com/schemas/types.xsd
curl -o schemas/common.xsd https://internal.corp.example.com/schemas/common.xsd

# Update the WSDL to point to local files
# Replace remote URLs with relative local paths

For wsimport, you can use a catalog file:

<!-- jax-ws-catalog.xml -->
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
  <system systemId="https://internal.corp.example.com/schemas/types.xsd"
          uri="schemas/types.xsd"/>
  <system systemId="https://internal.corp.example.com/schemas/common.xsd"
          uri="schemas/common.xsd"/>
</catalog>

Then pass the catalog:

wsimport -catalog jax-ws-catalog.xml service.wsdl

Error 3: Namespace Mismatch Between Import and Schema

s4s-att-invalid-value: Invalid attribute value for 'namespace'
  in element 'import'. Recorded information indicates
  the actual targetNamespace is 'http://example.com/types/v2'.

This happens when the namespace attribute on xs:import doesn't match the targetNamespace in the referenced schema document.

Fix: Align the namespace values.

<!-- The import namespace must exactly match the schema's targetNamespace -->
<xs:import namespace="http://example.com/types/v2"
           schemaLocation="types-v2.xsd"/>

Error 4: Circular Schema References

org.apache.xmlbeans.XmlException: error: Circular reference
  detected while resolving schema imports

Circular imports occur when Schema A imports Schema B, which imports Schema C, which imports Schema A. While the XSD specification technically allows this, many parsers handle it poorly.

Fix: Restructure to break the cycle.

Before (circular):
  A.xsd → imports B.xsd → imports C.xsd → imports A.xsd

After (acyclic):
  Common.xsd (shared types extracted here)
  A.xsd → imports Common.xsd
  B.xsd → imports Common.xsd
  C.xsd → imports Common.xsd

Tool-Specific Solutions

wsimport (JAX-WS)

# Use -wsdllocation for classpath-relative resolution
wsimport -keep -wsdllocation /wsdl/service.wsdl \
  -catalog jax-ws-catalog.xml \
  -d output/ \
  service.wsdl

# For HTTPS with self-signed certificates
wsimport -keep \
  -XdisableSSLHostnameVerification \
  -Xss 4m \
  https://api.example.com/service?wsdl

wsdl2java (Apache CXF)

# Specify schema resolution with -catalog
wsdl2java -catalog catalog.xml \
  -d output/ \
  -p com.example.service \
  service.wsdl

# Resolve imports from a directory
wsdl2java -wsdlLocation classpath:wsdl/service.wsdl \
  -d output/ \
  service.wsdl

svcutil (.NET)

# Use /reference to resolve external schemas manually
svcutil service.wsdl types.xsd common.xsd /out:ServiceClient.cs

# If behind a proxy
svcutil /config:proxy.config service.wsdl

For .NET Core and .NET 5+, use dotnet-svcutil:

dotnet tool install --global dotnet-svcutil
dotnet-svcutil service.wsdl --outputDir Generated

Local Schema Caching Strategy

For teams that work with WSDL files referencing many external schemas, a local caching strategy prevents repeated download failures and speeds up builds.

project/
├── wsdl/
│   ├── OrderService.wsdl
│   └── schemas/
│       ├── order-types.xsd
│       ├── common-types.xsd
│       └── external/
│           ├── xmldsig-core-schema.xsd
│           └── xenc-schema.xsd
├── catalog.xml
└── pom.xml

Maven configuration with local schema resolution:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>jaxws-maven-plugin</artifactId>
  <version>2.6</version>
  <executions>
    <execution>
      <goals><goal>wsimport</goal></goals>
      <configuration>
        <wsdlDirectory>${basedir}/src/main/resources/wsdl</wsdlDirectory>
        <wsdlFiles>
          <wsdlFile>OrderService.wsdl</wsdlFile>
        </wsdlFiles>
        <catalog>${basedir}/src/main/resources/catalog.xml</catalog>
        <packageName>com.example.order</packageName>
      </configuration>
    </execution>
  </executions>
</plugin>

Debugging Schema Resolution

When the error message isn't clear about which schema failed to load, enable verbose logging:

# wsimport verbose mode
wsimport -verbose -Xdebug service.wsdl

# Apache CXF verbose
wsdl2java -verbose -validate service.wsdl

# Quick validation with xmllint
xmllint --schema http://www.w3.org/2001/XMLSchema.xsd service.wsdl --noout

You can also use curl to manually verify that each schemaLocation URL is reachable:

# Extract all schemaLocation values and test each one
grep -oP 'schemaLocation="[^"]*"' service.wsdl | \
  sed 's/schemaLocation="//;s/"//' | \
  while read url; do
    echo -n "Testing $url ... "
    curl -s -o /dev/null -w "%{http_code}" "$url"
    echo
  done

How SOAPless Helps

External schema resolution errors are one of the most time-consuming WSDL troubleshooting tasks. SOAPless eliminates this problem entirely by handling WSDL parsing and schema resolution on the server side. You paste your WSDL URL, and SOAPless resolves all xs:import and xs:include references automatically — including schemas behind firewalls (when accessible from your configured endpoint), schemas with relative paths, and even schemas with circular references.

The result is a clean REST JSON API with auto-generated OpenAPI 3.0 documentation. No client code generation, no catalog files, no build plugin configuration. Your JSON requests are automatically converted to properly namespaced SOAP XML, and responses come back as clean JSON. Authentication credentials are secured with AES-256-GCM encryption and never exposed in logs.

You can test any operation directly from the SOAPless dashboard before writing a single line of integration code.