Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过Soap发送xml内容_C#_Web Services_Wcf_Soap_Asmx - Fatal编程技术网

C# 通过Soap发送xml内容

C# 通过Soap发送xml内容,c#,web-services,wcf,soap,asmx,C#,Web Services,Wcf,Soap,Asmx,我发送的soap请求如下所示: WebRequest webRequest = WebRequest.Create("http://localhost:55056/myWebService.asmx"); HttpWebRequest httpRequest = (HttpWebRequest)webRequest; httpRequest.Method = "POST"; httpRequest.ContentType = "text/xml; charset=utf-8"; httpRequ

我发送的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();
如何使我的webmethod接受这个小xml:

<firstNode>myProduct</firstNode>
编辑1:


谢谢你的重播MarxWright,我已经试过了,但不起作用。我通过将:替换为>;它成功了。但是如果我能在另一边做些改变,那就太好了

我不能100%确定这是否可行,但您可以尝试使用以下功能将消息转换为发送,我相信您可以在另一端读取数据

String sMessage = "<tag>Data</tag>";

String messageFilling = System.Security.SecurityElement.Escape(sMessage);

我不完全理解你的回答,你能再解释一下吗。如果消息正在到达另一端,并且您需要进行更改,那么您是否可以使用消息的内容再次将其转换回Xml文档?
String sMessage = "<tag>Data</tag>";

String messageFilling = System.Security.SecurityElement.Escape(sMessage);