Search code examples
xmlwcfsoapsoapuixml-namespaces

SoapUI giving error as Malformed Request when Request is valid


Here is a snippet of xml generated by my .net code that is sent to a third party soap service endpoint.

<?xml version="1.0" encoding="utf-16"?>
  <ProgramInterface 
   xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">  
    <vnsState_request xmlns="http://www.statewide.Request.com">
.....
....
...

This works thru code but when I put the exact same request that I pulled out from my debug breakpoint in SoapUI and send it to the same service it returns with XML malformed error as below

<faultcode>SOAP-ENV:Client</faultcode>
<faultstring>Malformed SOAP message</faultstring>

When I generate a sample request for the same operation I see this difference in the generated request XML

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:vns="http://www.statewide.Request.com">
   <soapenv:Header/>
   <soapenv:Body>
      <vns:VNSSTATEOperation>
         <vns:vnsState_request>

Why does SoapUI require those extra tags and why can't it use the request generated by my .Net code? And why does it require vns: pre-pended to every element along with those new elements?

<soapenv:Envelope >
   <soapenv:Header/>
   <soapenv:Body>

Solution

    1. Regarding Extra Tags: If you are hitting a SOAP service from any client, SOAP headers are required. You may find more details here.
    2. Regarding Prefix: It is not required if the default namespace is used which is in you .net case. Where as in the SoapUI, it is using explicit namespace, hence the prefix is used. You can find more details regarding the namespace here.

    For instance, taking your example. Below both are same.

    <vnsState_request xmlns="http://www.statewide.Request.com">
    <!--the above one is using default namespace -->
    

    and

    <ns:vnsState_request xmlns:ns="http://www.statewide.Request.com">
    <!--using explicit namespace "ns", hence the same is prefixed for the tag -->
    

    And if you take a look at the one in SoapUI, it has added namespace in the first line itself. So, it using as you have shown.

    Hope this helps.