0

I have been trying to fix this error, but I have run out of ideas. I am calling a SOAP webservice with my own WCF service, but I get the following CommunicationException:

Server returned an invalid SOAP Fault. Please see InnerException for more details.

And inner (XmlException):

Unbound prefix used in qualified name 'soapenv:Server'.

So to understand it better I used SOAP UI to see the response I get which is the following:

<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pbs="REDACTED" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Body>
      <SOAP-ENV:Fault>
         <faultcode>soapenv:Server</faultcode>
         <faultstring>REDACTED</faultstring>
         <detail>
            REDACTED
         </detail>
      </SOAP-ENV:Fault>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

As far as I can tell, it has something to do with the faultcode, but I am not entirely sure what it is. I do know I expected a FaultException and not a Communication Exception. There are some information in the detail of the error I would like to react on, but this Exception hides the information from me.

Edit:

This is the request they are receiving on the host (sent from my webservice):

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
        <setREDACTED xmlns="REDACTED" >
            <infotag>info</infotag>
        </setREDACTED>
    </s:Body>
</s:Envelope>

This it the one i send from SOAPUI:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pbs="REDACTED" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Header/>
    <soapenv:Body>
      <pbs:setREDACTED>
         <infotag>info<infotag>
      </pbs:setREDACTED>
   </soapenv:Body>
</soapenv:Envelope>
evilfish
  • 661
  • 8
  • 30
  • problem is in faultcode "soapenv.Server"...which matches with xml namespace xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" which is somehow causing parsing problem...Can you change fault code fro service side to something else? – Viru Sep 25 '15 at 08:35
  • I cannot change the response as I do not own that service. – evilfish Sep 25 '15 at 08:43
  • but is that valid fault code? May be you have to check with service owner and get it corrected...I don't think there is any other way...... – Viru Sep 25 '15 at 08:51
  • Also check your request...was there any invalid xml node? May be that is what is returend in fault code causing this issue.. – Viru Sep 25 '15 at 08:57
  • Try to _trace_ your request and returned SOAP Fault. Fault may have malformed XML if it's serialized manually. – Roman Dibikhin Sep 25 '15 at 09:36
  • I added the requests i send from my webservice and SOAPUI – evilfish Sep 25 '15 at 11:41
  • 1
    I feel there is something wrong in your request "xmlns="REDACTED" >". Can you check your WSDL? maybe post here whats mentioned in WSDL? – Viru Sep 25 '15 at 15:02
  • @RomanDibikhin Got the trace. There is a XmlException on the soapenv:Server in the faultcode. Could it be there it should have been SOAP-ENV because of the xmlns:SOAP-ENV declaration. Just saw now there there is double soap envelope declarations. Could that trigger something? – evilfish Sep 28 '15 at 04:48
  • @Viru I do not think it is the redacted namespace that are the problem here, because of the XmlException. I will look into it though. I can't give out the REDACTED information due to security and NDA reasons. – evilfish Sep 28 '15 at 04:50

1 Answers1

2

I figured out the problem and I am sorry you had to spend your time on this, because it WAS my redacted namespaces that was the problem (Mainly @Viru, Sorry)

The problem was that the WSDL I got from our partner had a namespace like http://derpco.com/OurNamespace but when we got the reply the namespace was changed to http://derpco.com/Namespace. Apparently they do namespace manipulation on their end so I just have to be on my toes on their replies. WCF is of cause not happy because it cant understand the new namespace, gives up and returns null. To fix it I created a message inspector did a replace on the xml:

public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
        {
            System.IO.File.WriteAllText("c:\\temp\\AfterReceiveReply" + reply.GetHashCode() + ".txt", reply.ToString());

            // Read 
            XmlDocument doc = new XmlDocument();
            MemoryStream ms = new MemoryStream();
            XmlWriter writer = XmlWriter.Create(ms);
            reply.WriteMessage(writer);
            writer.Flush();
            ms.Position = 0;
            doc.Load(ms);

            // Change 
            ChangeMessageToPBSNamespace(doc);

            // Write the new reply 
            ms.SetLength(0);
            writer = XmlWriter.Create(ms);
            doc.WriteTo(writer);
            writer.Flush();
            ms.Position = 0;
            XmlReader reader = XmlReader.Create(ms);
            reply = System.ServiceModel.Channels.Message.CreateMessage(reader, int.MaxValue, reply.Version);
        }

        void ChangeMessageToPBSNamespace(XmlDocument doc)
        {
            string xml = doc.OuterXml;
            xml = xml.Replace("http://derpco.com/Namespace", "http://derpco.com/OurNamespace");
            doc.LoadXml(xml);
        }

With the replace the namespace now matches the WSDL again and the Deserialiser is happy again

evilfish
  • 661
  • 8
  • 30
  • Seems you can use custom namespace names according to [this](http://stackoverflow.com/questions/1200346/wcf-service-reference-namespace-differs-from-original) – Roman Dibikhin Oct 02 '15 at 12:53