Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This question is well written -- many thanks. In reference to @Junto's "How do I use this" comment, it turns out that the SecurityHeader param on the service method can be used to add the header. I've included an example below. I believe that what's happening is that the SvcUtil.exe tool is barfing when trying to read the WS* DTDs. This is not obvious when you use the "Add Service Reference" wizard. But it is very obvious when you run svcutil.exe from the command line. Because svcutil.exe fails to read the WS* DTD's, the SecurityHeader object is not well developed. But Microsoft gives you an out with the .Any property. You can serialize the UsernameToken class right into the .Any property and your header will be added to the message. Again, thanks for this excellent question.</p> <p>How to use the SecurityHeader parameter to add a UsernameToken security header:</p> <p><strong>Required tools:</strong></p> <blockquote> <p>Fiddler2 (or similar) -- you really can't figure any of this out without inspecting the http headers.</p> </blockquote> <p><strong>Required Reference:</strong></p> <pre><code>Microsoft.Web.Services3.dll -- you can reference this 2.0 framework assembly from your 4.0 assembly </code></pre> <p><strong>WCF service call:</strong></p> <pre><code>// Initialization of the service... _service = new MyService("MyEndpoint", RemoteUri); // etc. // Calling the service -- note call to GetSecurityHeader() _service.ServiceAction(GetSecurityHeader(), "myParam1"); // etc. /// &lt;summary&gt; /// Construct the WSE 3.0 Security Header /// &lt;/summary&gt; private SecurityHeader GetSecurityHeader() { SecurityHeader h = new SecurityHeader(); UsernameToken t = new UsernameToken(RemoteLogin, RemotePassword, PasswordOption.SendPlainText); h.Any = new XmlElement[1]; h.Any[0] = t.GetXml(new XmlDocument()); return h; } </code></pre> <p><strong>App.config:</strong></p> <pre><code> &lt;system.serviceModel&gt; &lt;bindings&gt; &lt;basicHttpBinding&gt; &lt;binding name="MyBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="1048576" maxBufferPoolSize="524288" maxReceivedMessageSize="1048576" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"&gt; &lt;readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /&gt; &lt;security mode="Transport"&gt; &lt;transport clientCredentialType="None" proxyCredentialType="None" realm="" /&gt; &lt;message clientCredentialType="UserName" algorithmSuite="Default" /&gt; &lt;/security&gt; &lt;/binding&gt; &lt;/basicHttpBinding&gt; &lt;/bindings&gt; &lt;client&gt; &lt;endpoint address="http://myservice.com/service.asmx" binding="basicHttpBinding" bindingConfiguration="MyBinding" contract="MyContract" name="MyEndpoint" /&gt; &lt;/client&gt; &lt;/system.serviceModel&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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