2017-03-03 45 views
0

我寫了一個插件,其中我正在嘗試獲取XML響應。 這是我的代碼:它在一個控制檯應用程序寫入時HttpWebRequest.GetRequestStream()在MS Dynamics CRM插件中不起作用

// Set the Method property of the request to POST. 
string strXMLServer = "xxx"; 
var request = (HttpWebRequest)WebRequest.Create(strXMLServer); 
request.Method = "POST"; 

// Set the ContentType property of the WebRequest. 
request.ContentType = "xyz"; 

// Assuming XML is stored in strXML 
byte[] byteArray = Encoding.UTF8.GetBytes(strXML); 

// Set the ContentLength property of the WebRequest. 
request.ContentLength = byteArray.Length; 

//(LINE 5) Get the request stream 
Stream dataStream = request.GetRequestStream(); 

// Write the data to the request stream. 
dataStream.Write(byteArray, 0, byteArray.Length); 
// Close the Stream object. 
dataStream.Close(); 

此代碼工作正常。但是,當我相同的代碼複製到一個類庫(插件),並嘗試使用插件探查調試它,將應用程序突然停止,當它到達(5號線) 即在Stream dataStream = request.GetRequestStream();

request.GetRequestStream()函數不適用於插件,但在控制檯內正常工作。

任何幫助,將不勝感激:)提前

感謝

注:我使用的動態365在線試用版

回答