I'm trying to wirte a C# application as Webservice client invoke Java Web servie (use Axis 1.4) in 3 days but it's not work until now. Java WS require a custom SOAP header for authentication. So, I have to add a custom SOAP header in C# application. Code generated by VS 2010 do not include SOAP header, so I add a MySOAPHeader class into the project like that
namespace AddProvinceCityDemo
{
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://service.itthrm.vnitt.org")]
[System.Xml.Serialization.XmlRootAttribute("securitytoken", Namespace = "http://service.itthrm.vnitt.org", IsNullable = false)]
public class MySOAPHeader:SoapHeader
{
public String username;
public String password;
}
}
I also altered generated code in Reference.cs by adding MySOAPHeader varriable
public partial class ProvinceServiceClient : System.ServiceModel.ClientBase<AddProvinceCityDemo.ProvinceService.ProvinceService>, AddProvinceCityDemo.ProvinceService.ProvinceService {
public MySOAPHeader customSOAPHeader;
public ProvinceServiceClient() {
}
//.........................
}
Finally, I invoked WS by the following code
MySOAPHeader authentication = new MySOAPHeader();
authentication.username = username;
authentication.password = encryptedpass;
//end set SOAP header information
ProvinceServiceClient provinceservice = new ProvinceServiceClient();
provinceservice.customSOAPHeader = authentication;
Province[] arrprovince = null;
arrprovince = provinceservice.findAll();
Below code throw an exception when it runs. Error message is "Failed to retreive the SOAP header"
Pls, help me to fix that bug.
I also tried to develop a Java application instead of C# application, and It's so simple like that
SOAPHeaderElement oHeaderElement;
oHeaderElement = new SOAPHeaderElement(namespace, "securityHeader");
oHeaderElement.setPrefix"sec");
oHeaderElement.setMustUnderstand(false);
oElement = oHeaderElement.addChildElement("username");
oElement.addTextNode(username);
oElement = oHeaderElement.addChildElement("password");
oElement.addTextNode(passwordEncrypt);
How can I do the same in .net and C#?