我有一个asmx webservice,它有一个web方法
[WebMethod(Description = "Request for Read Stop Sale")]
[SoapHeader("Security", Direction = SoapHeaderDirection.In)]
[SoapDocumentMethod(ParameterStyle=SoapParameterStyle.Bare,Action="OTA_HotelBookingRule")]
public XmlDocument ReadStopSales()
{
....
I am getting some details from database and converting and transforming it into
XML and then putting it into XmlDocument object and returning it...
XmlResultDocument.LoadXml(results.ToString());
return XmlResultDocument;
}
我加载到XmlResultDocument的结果是根元素< OTA_HotelBookingRuleRS xmlns =“”>
我正在通过调用SoapUI来测试这个方法,它给了我以下结果:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<ReadStopSalesResult xmlns="http://localhost:6092/connectAPI.asmx">
<OTA_HotelBookingRuleRS xmlns="">
<RuleMessage HotelCode="5">
<StatusApplication RatePlanCode="579_1" InvTypeCode="579" RatePlanCategory="BB"/>
<BookingRules>
<BookingRule Start="2015-07-15" End="2015-07-15">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-16" End="2015-07-16">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-17" End="2015-07-17">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-18" End="2015-07-18">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-19" End="2015-07-19">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-20" End="2015-07-20">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-21" End="2015-07-21">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-22" End="2015-07-22">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-23" End="2015-07-23">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-24" End="2015-07-24">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-25" End="2015-07-25">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-26" End="2015-07-26">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
</BookingRules>
</RuleMessage>
</OTA_HotelBookingRuleRS>
</ReadStopSalesResult>
</soap:Body>
</soap:Envelope>
我不需要元素&lt; ReadStopSalesResult xmlns =“http:// localhost:6092 / connectAPI.asmx”&gt;
在这个元素中,“ReadStopSales”是您在C#代码中可以看到的web方法名称。
我想要的结果如下:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<OTA_HotelBookingRuleRS xmlns="">
<RuleMessage HotelCode="5">
<StatusApplication RatePlanCode="579_1" InvTypeCode="579" RatePlanCategory="BB"/>
<BookingRules>
<BookingRule Start="2015-07-15" End="2015-07-15">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-16" End="2015-07-16">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-17" End="2015-07-17">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-18" End="2015-07-18">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-19" End="2015-07-19">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-20" End="2015-07-20">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-21" End="2015-07-21">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-22" End="2015-07-22">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-23" End="2015-07-23">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-24" End="2015-07-24">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-25" End="2015-07-25">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-26" End="2015-07-26">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
</BookingRules>
</RuleMessage>
</OTA_HotelBookingRuleRS>
</soap:Body>
</soap:Envelope>
请帮助您删除默认结果元素....
答案 0 :(得分:0)
您可以尝试实施WebserviceHandler
并更改响应消息。示例代码如下所示:
public class ChangeMessageHandler implements SOAPHandler<SOAPMessageContext> {
@Override
public boolean handleMessage(SOAPMessageContext context) {
Boolean outbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (!outbound) {
try {
SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
soapMessage.getSOAPBody().appendChild(context.getMessage().getSOAPBody().getFirstChild().getFirstChild());
context.setMessage(soapMessage);
}
catch (Exception ex) {
}
}
return true;
} }
基本上,我正在尝试获取第二个节点并将其添加到新消息中。