2015-09-25 30 views
0

我一直在嘗試解決此錯誤,但我已經用完了想法。我使用自己的WCF服務調用SOAP webservice,但發生以下CommunicationException:SOAP錯誤無效;以限定名稱使用的未綁定前綴

服務器返回無效的SOAP錯誤。有關更多詳細信息,請參閱InnerException。

和內部(XmlException):

合格的名稱中使用未綁定前綴 'soapenv:服務器'。

因此,爲了更好地理解它我使用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> 

據我所知,它是與在faultcode,但我不完全確定它是什麼。我知道我期望一個FaultException而不是一個通信異常。我想對此作出反應的錯誤的詳細信息中包含一些信息,但此例外隱藏了我的信息。

編輯:

這是他們收到的主機上的要求(從我的web發送):

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

這一點,一個我從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> 
+0

問題是的faultcode「soapenv.Server」 ...它與xml命名空間xmlns相匹配:soapenv =「http://schemas.xmlsoap.org/soap/envelope/」這在某種程度上會導致解析問題......您能否將服務端的故障代碼更改爲其他內容? – Viru

+0

我無法更改回復,因爲我沒有擁有該服務。 – evilfish

+0

但是那個有效的故障碼?可能是你必須與服務負責人覈實並糾正錯誤......我不認爲有任何其他方法...... – Viru

回答

1

我想出了問題,我很抱歉,你不得不花費你的時間,因爲它是我的編輯命名空間,這是問題(主要是@Viru,對不起)

問題是我從我們的合作伙伴獲得的WSDL有一個名稱空間,如http://derpco.com/OurNamespace,但是當我們收到回覆時,命名空間更改爲http://derpco.com/Namespace。顯然,他們在他們的末端進行命名空間操作,所以我只需要在我的腳趾上留下他們的回覆。 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); 
     } 

隨着替代的命名空間現在WSDL再次匹配,而且解串器是開心了

+0

似乎你可以根據[this]使用自定義命名空間名稱(http://stackoverflow.com/questions/1200346/wcf-service-reference-namespace-differs-from-original) –

相關問題