我需要在我的c#代码库中使用第三方服务,这需要将节点添加到请求中。(跟进问题至ws-addressing in soap request programatically)
到目前为止,我能做到的是
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header xmlns:soap="http://www.w3.org/2005/08/addressing">
<wsa:Action xmlns:wsa="Action">http://tempuri.org/GetDetails</wsa:Action>
<wsa:To xmlns:wsa="To">SAMPLEURL.svc/DP2Svcs11</wsa:To>
</soap:Header>
<soap:Body>
<GetBookingDetails xmlns="http://tempuri.org/">
<UserName>testt</UserName>
<Password>testt</Password>
</GetBookingDetails>
</soap:Body>
</soap:Envelope>我最终需要的是
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:Action>http://tempuri.org/GetDetails</wsa:Action>
<wsa:To>http://SAMPLEURL.svc/DP2Svcs11</wsa:To>
</soap:Header>
<soap:Body>
<GetBookingDetails xmlns="http://tempuri.org/">
<UserName>testt</UserName>
<Password>test</Password>
</GetBookingDetails>
</soap:Body>
</soap:Envelope>有没有人能帮我修改一下前面提到的命名空间?
用于生成上述响应的代码为
XmlDocument xmlDoc = new XmlDocument();
inwardStream.Position = 0;
var streamReader = new StreamReader(inwardStream);
var streamWriter = new StreamWriter(outwardStream);
message = streamReader.ReadToEnd();
xmlDoc.LoadXml(message);
var insertNode = (((xmlDoc).LastChild));
var headerNode = xmlDoc.CreateElement("soap", "Header", "http://www.w3.org/2005/08/addressing");
//var actionNode = xmlDoc.CreateElement("wsa", "Action", "http://www.w3.org/2004/12/addressing");
//var actionNodeTo = xmlDoc.CreateElement("wsa", "To", "http://www.w3.org/2004/12/addressing");
var actionNode = xmlDoc.CreateElement("wsa:Action", "Action");
var actionNodeTo = xmlDoc.CreateElement("wsa:To", "To");
actionNode.InnerText = "http://tempuri.org/IFlightBookingService/GetBookingDetails";
actionNodeTo.InnerText = "http://54.251.105.26/GQWCF_FlightEngine/FlightBookingService.svc/DP2Svcs11";
headerNode.AppendChild(actionNode);
headerNode.AppendChild(actionNodeTo);
(((((xmlDoc))).LastChild)).InsertBefore(headerNode, (((((xmlDoc))).LastChild)).FirstChild);发布于 2013-11-11 18:34:16
编辑线路:
var actionNode = xmlDoc.CreateElement("wsa:Action", "Action");
var actionNodeTo = xmlDoc.CreateElement("wsa:To", "To");至:
var actionNode = xmlDoc.CreateElement("wsa:Action");
var actionNodeTo = xmlDoc.CreateElement("wsa:To");https://stackoverflow.com/questions/19903854
复制相似问题