簡體   English   中英

在ASMX服務中如何更改ResponseHeader ElementName

[英]In ASMX service how to change ResponseHeader ElementName

我在.net中為javaclient創建ASMX Web服務。 提供的肥皂看起來像這樣

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pus="http://www.example.org/pusheventservice/">
<soapenv:Header>
<ServiceHeader>
<TransactionID>258350</TransactionID>
<TransactionDate>2014/12/21</TransactionDate>.......

並且javaclient期望響應SOAP

像這樣

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pus="http://www.example.org/pusheventservice/">
<soapenv:Header>
<ResponseServiceHeader>
<TransactionID>258350</TransactionID>
<TransactionDate>2014/12/21</TransactionDate>....

表示requestElement為'ServiceHeader',ResponseElement必須為'ResponseServiceHeader'

我通過WebMethod實現了這一點,但是無法在Header中實現。

可能嗎?? 如果是,怎么辦? 我也不能使用WCF。

EDITS

namespace PushWS
{
[WebService(Namespace = "http://localhost:60463/PushEvent.asmx")]
[WebServiceBinding(ConformsTo = WsiProfiles.None)]
[SoapDocumentService(SoapBindingUse.Literal, SoapParameterStyle.Bare, RoutingStyle = SoapServiceRoutingStyle.SoapAction)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class PushEvent : System.Web.Services.WebService
{
    public ServiceHeader serviceHeader = null;
    public SoapUnknownHeader[] userCredentials;
    [WebMethod(Description = "updateEvent receives XML from Client")]
    [SoapHeader("serviceHeader", Direction = SoapHeaderDirection.InOut)]
    [SoapHeader("userCredentials", Required = true)]
    [return: XmlElement("EventResponse")]
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://localhost:60463/PushEvent.asmx/updateEvent",
    RequestElementName = "updateEventRequest",
    ResponseElementName = "updateEventResponse")]
    public XmlElement updateEvent([XmlAnyElement]XmlElement MyPushEvent)
    {
           //Logic here
    }
    public class ServiceHeader : SoapHeader
    {
         public string TransactionID{get;set;}
         public string TransactionDate{get;set;}
    }
 }

為響應頭創建一個派生類:

public class ResponseServiceHeader : ServiceHeader
{
}

public ServiceHeader serviceHeader = null;
public ResponseServiceHeader responseServiceHeader = null;

[SoapHeader("serviceHeader", Direction = SoapHeaderDirection.Int)]
[SoapHeader("responseServiceHeader", Direction = SoapHeaderDirection.Out)]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM