none
ASMX web service and SoapHeaderDirection IN/OUT RRS feed

  • Question

  • i have seen some time people use SoapHeaderDirection.Out SoapHeaderDirection.In

    [WebMethod]
        [SoapHeader("myOutHeader",Direction=SoapHeaderDirection.Out)]
        public void MyOutHeaderMethod() 
        {
          // Return the client's authenticated name.
          myOutHeader.Username = User.Identity.Name;          
        }

    code taken from these web site https://msdn.microsoft.com/en-us/library/dz7ks0ee(v=vs.100).aspx

    also consult these two web site too

    https://msdn.microsoft.com/en-us/library/system.web.services.protocols.soapheaderdirection(v=vs.110).aspx

    https://msdn.microsoft.com/en-us/library/8728chd5(v=vs.100).aspx

    so my question is when to set SoapHeaderDirection.Out and when SoapHeaderDirection.In

    please let me know. thanks


    Monday, December 19, 2016 11:17 AM

Answers

  • Hi Mou_inn,

    >> so my question is when to set SoapHeaderDirection.Out and when SoapHeaderDirection.In

    For SoapHeaderDirection, below table lists helpful information.

    Member name Description
    Fault

    Specifies the SoapHeader is sent to the XML Web service client when an exception is thrown by the XML Web service method.

    In

    Specifies the SoapHeader is sent to the XML Web service.

    InOut

    Specifies the SoapHeader is sent to both the XML Web service and the XML Web service client.

    Out

    Specifies the SoapHeader is sent to the XML Web service client.

    In/Out is used to specify whether SoapHeader is sent to Web Service or Web Service client.

    For example, if you want to send SoapHeader from client to Service, you could set it by In. If you want to send SoapHeader from client to Service, change the value at Service and send it back to client, you could set it with InOut.

    For your code, you could check myOutHeader after receiving response at client side.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Sudip_inn Wednesday, December 21, 2016 9:26 AM
    Tuesday, December 20, 2016 3:24 AM
  • Hi Mou_inn,

    For this, if you set AuthenticateHeader with UserName as Jeff at client side, you could use Credentials.UserName to get current UserName, you also could set “Credentials.UserName = "WebService";”, and get this new value at client by “client.AuthenticateHeaderValue.UserName”.

    Client code
                WebExtensionService.WebService1 client = new WebExtensionService.WebService1();            
                var item=client.Proxy;
                WebExtensionService.AuthenticateHeader header = new WebExtensionService.AuthenticateHeader() { UserName = "jeff1", Password = "imbatman" };
                    client.AuthenticateHeaderValue = header;
                    string result = client.HelloWorld();                
                    MessageBox.Show(client.AuthenticateHeaderValue.UserName);
    Server cdoe
            public AuthenticateHeader Credentials;
            [AuthExtension]
            [SoapHeader("Credentials", Required = true,Direction=SoapHeaderDirection.InOut)]
            [WebMethod]
            public string HelloWorld()
            {
                Credentials.UserName = "WebService";
                return "Hello World";
            }

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Sudip_inn Thursday, December 22, 2016 8:36 AM
    Thursday, December 22, 2016 7:43 AM

All replies

  • Hi Mou_inn,

    >> so my question is when to set SoapHeaderDirection.Out and when SoapHeaderDirection.In

    For SoapHeaderDirection, below table lists helpful information.

    Member name Description
    Fault

    Specifies the SoapHeader is sent to the XML Web service client when an exception is thrown by the XML Web service method.

    In

    Specifies the SoapHeader is sent to the XML Web service.

    InOut

    Specifies the SoapHeader is sent to both the XML Web service and the XML Web service client.

    Out

    Specifies the SoapHeader is sent to the XML Web service client.

    In/Out is used to specify whether SoapHeader is sent to Web Service or Web Service client.

    For example, if you want to send SoapHeader from client to Service, you could set it by In. If you want to send SoapHeader from client to Service, change the value at Service and send it back to client, you could set it with InOut.

    For your code, you could check myOutHeader after receiving response at client side.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Sudip_inn Wednesday, December 21, 2016 9:26 AM
    Tuesday, December 20, 2016 3:24 AM
  • what u said "For your code, you could check myOutHeader after receiving response at client side." not clear to me. if elaborate this point. thanks
    Wednesday, December 21, 2016 9:27 AM
  • Hi Mou_inn,

    For this, if you set AuthenticateHeader with UserName as Jeff at client side, you could use Credentials.UserName to get current UserName, you also could set “Credentials.UserName = "WebService";”, and get this new value at client by “client.AuthenticateHeaderValue.UserName”.

    Client code
                WebExtensionService.WebService1 client = new WebExtensionService.WebService1();            
                var item=client.Proxy;
                WebExtensionService.AuthenticateHeader header = new WebExtensionService.AuthenticateHeader() { UserName = "jeff1", Password = "imbatman" };
                    client.AuthenticateHeaderValue = header;
                    string result = client.HelloWorld();                
                    MessageBox.Show(client.AuthenticateHeaderValue.UserName);
    Server cdoe
            public AuthenticateHeader Credentials;
            [AuthExtension]
            [SoapHeader("Credentials", Required = true,Direction=SoapHeaderDirection.InOut)]
            [WebMethod]
            public string HelloWorld()
            {
                Credentials.UserName = "WebService";
                return "Hello World";
            }

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Sudip_inn Thursday, December 22, 2016 8:36 AM
    Thursday, December 22, 2016 7:43 AM
  • client credentials is always set at client side but in your code client credentials set at client and service side too. so can u tell me few reason why one should set client credentials at service side ?
    Thursday, December 22, 2016 8:37 AM
  • Hi Mou_inn,

    SoapHeaderDirection is for SoapHeader. In your scenario, you use it as client credentials. So, there is no need to set it as InOut, and you do not need to set anything at service side. I just use this simple demo to tell you which we could use under SoapHeaderDirection.InOut.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, December 22, 2016 8:46 AM