0
XML內容,我發送SOAP請求,看起來像下面這樣:發送SOAP上
WebRequest webRequest = WebRequest.Create("http://localhost:55056/myWebService.asmx");
HttpWebRequest httpRequest = (HttpWebRequest)webRequest;
httpRequest.Method = "POST";
httpRequest.ContentType = "text/xml; charset=utf-8";
httpRequest.Accept = "text/xml";
httpRequest.Headers.Add("SOAPAction: http://tempuri.org/myWebMethod");
httpRequest.ProtocolVersion = HttpVersion.Version11;
httpRequest.Credentials = CredentialCache.DefaultCredentials;
Stream requestStream = httpRequest.GetRequestStream();
//Create Stream and Complete Request
StreamWriter streamWriter = new StreamWriter(requestStream, Encoding.ASCII);
soapRequest.Append("<soap:Body>");
soapRequest.Append("<myWebMethod xmlns=\"http://tempuri.org/\">");
soapRequest.Append("<eventType>myEventType</eventType>");
soapRequest.Append("<eventId><firstNode>myProduct</firstNode></eventId>");
soapRequest.Append("<eventData>myEventData</eventData>");
soapRequest.Append("</myWebMethod>");
soapRequest.Append("</soap:Body>");
streamWriter.Write(soapRequest.ToString());
streamWriter.Close();
//Get the Response
HttpWebResponse wr = (HttpWebResponse)httpRequest.GetResponse();
StreamReader srd = new StreamReader(wr.GetResponseStream());
string resulXmlFromWebService = srd.ReadToEnd();
我的問題是EVENTID包含一些XML內容=> < firstNode> myProduct的</firstNode>,當我發送soapRequest,另一邊我得到在調試模式:事件類型= 「myEventType」 事件ID = 「」 EVENTDATA = NULL
我的Web方法看起來像
[WebMethod]
public void myWebMethod(string eventType, string eventId, string eventData)
{
}
我能做些什麼使我的webmethod接受這個小 「XML」:
<firstNode>myProduct</firstNode>
EDIT1:
感謝您的重播MarxWright,我已經嘗試過這一點,但它不工作。我設法通過將「<」替換爲「& lt」來手動轉換您的sMessage和「>」與「& gt」;「它有效。但如果我可以在另一邊進行更改,那將會很好。
我不完全理解你的回答,你能否進一步解釋一下。如果消息到達另一端,並且需要進行更改,您是否可以不使用消息的內容再次將它重新轉換爲Xml文檔? – MarxWright