在ASMX服务中如何更改ResponseHeader ElementName

时间:2015-01-13 13:06:13

标签: c# web-services soap asmx

我正在.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是&#39; ServiceHeader&#39;和ResponseElement必须是“ResponseServiceHeader”

I 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;}
    }
 }

1 个答案:

答案 0 :(得分:1)

为响应标头创建派生类:

public class ResponseServiceHeader : ServiceHeader
{
}

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

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