One of our customers from a major carinthian city is using AForms2Web and a public available webservice http://www.amtsweg.gv.at/amtsweg_apf/services/transfer?wsdl. This Webservice are written in Java and it is sometimes a little bit difficult to access a Java Webservice from C#. First of all you have to use WSDL.EXE to get a corresponding C# class/file. But now the question was – how to add the required security header – and here we go:

[SNIP]
const string ns = 
   "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";

XmlElement xmlUserToken = 
   XDoc.CreateElement("sec", "UsernameToken", ns);

XmlElement username = 
   XDoc.CreateElement("sec", "Username", ns);
username.InnerText = 
   soapUser;
xmlUserToken.AppendChild(username);

XmlElement password = 
   XDoc.CreateElement("sec", "Password", ns);
password.InnerText = 
   soapPwd;
xmlUserToken.AppendChild(password);

request.Headers.RemoveAt(0);
request.Headers.Insert(0, MessageHeader.CreateHeader("Security", ns, xmlUserToken));
 
[SNIP END]