您可以通過發送與WebClient的一個POST請求,和填充的身體消耗沒有WSDL web服務請求與SOAP XML消息。
您可能需要添加額外的HTTP標頭。首先使用SOAP UI執行請求,然後使用提琴手查看請求。然後用WebClient發送請求。該代碼應與此類似:
using (var client = new WebClient())
{
// this is the string containing the soap message
var data = File.ReadAllText("request.xml");
// HTTP header. set it to the identical working example you monitor with fiddler from SOAP UI
client.Headers.Add("Content-Type", "text/xml;charset=utf-8");
// HTTP header. set it to the identical working example you monitor with fiddler from SOAP UI
client.Headers.Add("SOAPAction", "\"http://tempuri.org/ITestWcfService/TestMethod\"");
// add/modify additional HTTP headers to make the request identical with what you get when calling from SOAP UI on a successful call
try
{
var response = client.UploadString("http://localhost:8080/TestWcfService", data);
}
catch (Exception e)
{
// handle exception
}
}
我不知道有關證書,但也許你可以將其設置爲網絡客戶端太莫名其妙。不幸的是,我對客戶證書瞭解不多。但如果你可以在評論中解釋我可能會幫助你。如果您設法使用此解決方案進行工作,請在此處張貼您的額外工作來處理證書問題。
WebClient是System.dll程序集中System.Net的類。
我不知道你爲什麼把REST單詞放在引號之間。這是因爲它實際上是一個帶有json對象的SOAP服務嗎? REST沒有將WSDL作爲公開元數據的標準方式。不過,我發佈了一個解決方案,可以爲您提供發送「原始」請求所需的控制權,就像您使用SOAP UI一樣。 – Cosmin
我把REST,因爲當調用它扔SOAPUI它需要REST項目這是我第一次調用非.Net服務。 – nabukhas