问题
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>
回答1:
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
来源:https://stackoverflow.com/questions/32777656/invalid-soap-fault-unbound-prefix-used-in-qualified-name