2016-04-25 102 views
1

我有一個帶有TransportWithMessageCredential安全模式的WCF客戶端。當嘗試使用BeforeSendRequest如何從客戶端記錄完整的原始WCF客戶端請求?

public object BeforeSendRequest(ref Message request, IClientChannel channel) 
    { 
     System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\tmp\\request_log.xml"); 
     file.WriteLine(request.ToString()); 
     file.Close(); 

     return null; 
    } 

有結果,沒有安全標籤的登錄請求

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
    <s:Header> 
     <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">https://(skiped)</Action> 
    </s:Header> 
    <s:Body> 
    ... 
    </s:Body> 
</s:Envelope> 

我如何登錄客戶端完全原始的請求?它必須是這樣的

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
<s:Header> 
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
<u:Timestamp u:Id="_0"> 
<u:Created>...</u:Created> 
<u:Expires>..</u:Expires> 
</u:Timestamp> 
<o:BinarySecurityToken> 
<!-- Removed--> 
</o:BinarySecurityToken> 
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#"> 
<SignedInfo> 
... 
</SignedInfo> 
<SignatureValue>...</SignatureValue> 
<KeyInfo> 
<o:SecurityTokenReference> 
... 
</o:SecurityTokenReference> 
</KeyInfo> 
</Signature> 
</o:Security> 
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">skiped</Action> 
</s:Header> 
<s:Body> 
... 
</s:Body> 
</s:Envelope> 

UPD。結合

<security mode="TransportWithMessageCredential"> 
    <transport clientCredentialType="None" proxyCredentialType="None" 
     realm="" /> 
    <message clientCredentialType="Certificate" algorithmSuite="Basic256" /> 
</security> 

回答

1

This安全選項可幫助:

public object BeforeSendRequest(ref Message request, IClientChannel channel) 
{ 
    MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue); 
    request = buffer.CreateMessage(); 
    Log("Request:" + Environment.NewLine + buffer.CreateMessage()); 
    return null; 
} 
+0

結果相同。只有標籤,沒有安全標籤 – TNomade

+0

結果表明你沒有湯頭的安全! –

+0

您可以檢查您是否正確添加了安全選項。 –

0

您還可以使用Fiddler這是免費的文章。 如果您的端點爲https一定要繞過證書驗證這一

ServicePointManager.ServerCertificateValidationCallback = delegate {return true;}; 

因爲菲德勒使用它自己的證書是您的連接無效。