Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I attach a SOAP Header to my C# client?
    text
    copied!<p>I have my web service set up to recieve a soap header of name <code>"TestHeader"</code> with param <code>"Name"</code></p> <p><strong>How do i create a soap header in my client AND send it to the service?</strong></p> <p>So far I have created it in my client.</p> <pre><code>public class TestHeader : SoapHeader { public String Name; } </code></pre> <p>Initialised my service,</p> <pre><code> Test.TestServicesClient SOAP = new Test.TestServicesClient(); </code></pre> <p>Initialised my header.</p> <pre><code> TestHeader header = new TestHeader(); </code></pre> <p>set variable in header</p> <pre><code>header.Name = "BoB"; </code></pre> <p>Now what? Ive tried following MSDN, and other tutorials but not got anywhere.</p> <p><strong>TestService.cs</strong></p> <pre><code>using System; using System.Web.Services; using System.Web.Services.Protocols; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; using System.Data; using System.Data.SqlClient; using System.IO; using System.Security.Cryptography; using System.Runtime.InteropServices; using System.ServiceModel.Dispatcher; using System.ServiceModel.Channels; namespace Test { // Define a SOAP header by deriving from the SoapHeader class. public class TestHeader : SoapHeader { public String Name; } public class TestService : ITestServices { public TestHeader TestInHeader; [WebMethod] [SoapHeader("TestInHeader", Direction = SoapHeaderDirection.In)] public List&lt;ServiceDetails&gt; GetServiceDetails(Int32 CostCentreNo, Int32 ServiceCode, Boolean Recurring) { throw new System.Exception(TestInHeader.ToString()); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload