使用SoapUI调用Web Service POST请求返回400 Bad Request求助
Let's break down the most likely causes for your 400 Bad Request error—this almost always points to a malformed SOAP request that the server can't parse correctly.
Common Causes & Fixes
1. Invalid Namespace for the kn Prefix
Looking at your SOAP envelope, the kn namespace is set to http://..//soapAction — this is clearly a placeholder from the example you used, not the actual namespace required by the service.
SOAP relies heavily on namespaces to identify the operation being called (in this case, kn:InsertOrders). If the server doesn't recognize this namespace, it won't know how to process your request, resulting in a 400 error.
Fix: Replace http://..//soapAction with the actual namespace URL provided by the Web Service documentation or WSDL.
2. Unescaped XML in the XmlOrders Parameter
Since XmlOrders expects a string value, you can't directly embed raw XML inside the SOAP envelope without escaping special characters. The inner XML tags (<EXAMPLE>, <HEADER>, etc.) will break the structure of the outer SOAP envelope, causing the server's XML parser to fail.
Fix: Escape all XML special characters in your inner XML string:
- Replace
<with< - Replace
>with> - Remove the
<?xml version="1.0" encoding="utf-8"?>declaration (this is redundant inside a SOAP envelope and can cause parsing conflicts)
Your escaped XmlOrders content should look like this:
<EXAMPLE xmlns="EXAMPLE"> <HEADER> <ID>G112233</ID> <TR>AB123</TR> </HEADER> <HEADER> <ID>G123123</ID> <TR>AB1234</TR> </HEADER> <DETAIL> <DETAILID>123123123</DETAILID> <TXT>ATR_123</TXT> </DETAIL> <DETAIL> <DETAILID>123123123</DETAILID> <TXT>ATR_123</TXT> </DETAIL> </EXAMPLE>
3. Missing/Invalid stringLength Parameter
The stringLength field is present in your SOAP envelope but marked with a ? — this is likely a required parameter that expects the exact length of the XmlOrders string (after escaping). If you leave it as a placeholder or provide an incorrect value, the server's validation will fail.
Fix: Calculate the length of your escaped XmlOrders string and insert that number here. For example, if the escaped string is 500 characters long, set <kn:stringLength>500</kn:stringLength>.
4. SOAP Version Mismatch
Your envelope uses the SOAP 1.2 namespace (http://www.w3.org/2003/05/soap-envelope). If the Web Service only supports SOAP 1.1, this will cause a 400 error.
Fix:
- Check the service's WSDL or documentation to confirm the supported SOAP version.
- If using SOAP 1.1, replace the soap namespace with
http://schemas.xmlsoap.org/soap/envelope/and set your request'sContent-Typeheader totext/xml; charset=utf-8(SOAP 1.2 usesapplication/soap+xml; charset=utf-8).
Additional Debugging Steps
- Use SoapUI's "Raw" view to inspect the exact request being sent — this will help you spot any typos or unescaped characters that might be breaking the envelope.
- Enable more detailed logging on the server side (if you have access) or use a tool like Fiddler to capture the full request/response and check for parsing errors.
内容的提问来源于stack exchange,提问作者Ioannis Brant-Ioannidis

