C# 无效SOAP错误;限定名称中使用的未绑定前缀

C# 无效SOAP错误;限定名称中使用的未绑定前缀,c#,web-services,wcf,soap,C#,Web Services,Wcf,Soap,我一直在试图纠正这个错误,但我已经没有主意了。我正在使用自己的WCF服务调用SOAP Web服务,但我得到以下CommunicationException: 服务器返回了无效的SOAP错误。有关更多详细信息,请参阅InnerException 和内部(XmlException): 限定名称“soapenv:Server”中使用的未绑定前缀 因此,为了更好地理解它,我使用SOAP UI查看得到的响应,如下所示: <SOAP-ENV:Envelope xmlns:xsi="http://www

我一直在试图纠正这个错误,但我已经没有主意了。我正在使用自己的WCF服务调用SOAP Web服务,但我得到以下CommunicationException:

服务器返回了无效的SOAP错误。有关更多详细信息,请参阅InnerException

和内部(XmlException):

限定名称“soapenv:Server”中使用的未绑定前缀

因此,为了更好地理解它,我使用SOAP UI查看得到的响应,如下所示:

<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>

soapenv:服务器
编辑
编辑
据我所知,它与错误代码有关,但我不完全确定它是什么。我知道我预期的是一个故障异常,而不是通信异常。我想对错误的详细信息做出反应,但是这个异常对我隐藏了这些信息

编辑:

这是他们在主机上收到的请求(从我的Web服务发送):


信息
这是我从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>

信息

我发现了这个问题,很抱歉您不得不花时间在这个问题上,因为问题出在我编辑的名称空间上(主要是@Viru,抱歉)

问题是,我从我们的合作伙伴那里得到的WSDL有一个类似的名称空间,但当我们得到回复时,名称空间被更改为。显然,他们在自己的端进行名称空间操作,所以我只需要留意他们的回复。WCF当然不高兴,因为它无法理解新名称空间,放弃并返回null。为了修复它,我创建了一个消息检查器,并对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);
        }

使用replace,名称空间现在再次匹配WSDL,反序列化程序再次感到高兴

问题在于错误代码“soapenv.Server”…与xml名称空间xmlns:soapenv=“”匹配这在某种程度上导致了解析问题…您可以将服务端的故障代码更改为其他代码吗?我无法更改响应,因为我不拥有该服务。但该故障代码有效吗?可能您必须向服务所有者查询并更正它…我认为没有其他方法…也要检查您的请求…是否存在任何无效的xml节点?可能这就是导致此问题的错误代码中返回的内容。我觉得您的请求“xmlns=”redact“>”中有错误。你能检查你的WSDL吗?也许在这里发布WSDL中提到的内容?似乎您可以根据需要使用自定义名称空间名称
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);
        }