简体   繁体   中英

ASP.NET WEB SERVICE: Adding custom attribute C#

Hi can I add an attribute to my asp.net web service header?

I need to include something like: xmlns:trac="http://whatever".

This is my code:

namespace com.chronopost.notification.push.trace.webservice
{ 
    [WebService(Namespace = "http://webservice.trace.push.notification.chronopost.com/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class TracePushWSService : System.Web.Services.WebService
    {
        [WebMethod]
        public string TraceMessageFeedback(DtTrackTraceParamUserCredential mtTrackTraceParamUserCredential, string mtTrackTraceTestFeedBack)
        {

            return "DTM00: TracePush Feedback:  " + mtTrackTraceTestFeedBack;

        }

        [WebMethod]
        public DtTrackTraceAnswer NewTraceMessage(DtTrackTraceParamUserCredential mtTrackTraceParamUserCredential, DtTrackTraceParam mtTrackTraceReq)
        {

            DtTrackTraceAnswer iDtTrackTraceResp = new DtTrackTraceAnswer("DTM00: TracePush OBJ - OK");

            return iDtTrackTraceResp;
        }

        [WebMethod]
        public DtTrackTraceAnswerXML NewTraceMessageXML(DtTrackTraceParamUserCredential mtTrackTraceParamUserCredential, DtTrackTraceParamXML mtTrackTraceReqXML)
        {

            DtTrackTraceAnswerXML iDtTrackTraceResp = new DtTrackTraceAnswerXML("DTM00: TracePush XML - OK");

            return iDtTrackTraceResp;
        }
    }
}

If I understoo you correctly you need SoapExtension Class , you can look the example in the msdn, about creating Attribute for the Web Service Method.

ASP.NET allows a SOAP-related infrastructure to be built by means of an extensibility mechanism. The ASP.NET SOAP extension architecture revolves around an extension that can inspect or modify a message at specific stages in message processing on either the client or the server. ASP.NET SOAP extensions derive from the SoapExtension class. The GetInitializer and Initialize methods provide alternative mechanisms for initializing the SOAP extension to enhance performance. ProcessMessage is the heart of most SOAP extensions, as the method is called at each stage defined in SoapMessageStage, allowing the SOAP extension to perform the desired behavior of that specific SOAP extension. For SOAP extensions that need to modify the SOAP request or SOAP response, ChainStream provides an opportunity to receive the proposed data to be sent across the wire.

I think I know what you want. Just go to your class objetcs and set the XmlRoot. Prefix and namespace: trac = http://whatever . It will become available in the soap envelope.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM