views:

33

answers:

2

How do you add create a SOAP web service header?

Example

<soap:Header>
    <myHeader xmlns="https://www.domain.com"&gt;
        <Username>string</Username>
        <Password>string</Password>
    </myHeader>
</soap:Header>

source code

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;


namespace TestWebServices
{
    /// <summary>
    /// Summary description
    /// </summary>
    [WebService(Namespace = "https://Test.com")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class Testing : System.Web.Services.WebService
    {

        [WebMethod]
        public string GetTestValue()
        {


            return "xyz";
        }
    }

}
A: 

How about:

public class MyHeader : SoapHeader
{
    public string Username;
    public string Password;
}

There's more on the subject here:

Using SOAP Headers (MSDN)

Defining and Processing SOAP Headers (MSDN)

Kev
A: 

A SOAP message with headers may look something like the following:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;

  <soap:Header>
    <Username>string</Username>
    <Password>string</Password>
  </soap:Header>

</soap:Envelope>
Junior Mayhé