C # SOAPHeader
Reference settings
1. VS create a solution to generate a CS file through WSDL
2. Create a blank XML file, copy the following file to the blank xml file, and save it to disk d, for example, d: \ wsdlconfig. xml.
c#
Soap
true
false
properties oldAsync
3. Use the WSDL program that comes with VS to generate a file. The method is as follows:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\wsdl.exe /par:d:\wsdlconfig.xml http://hostname:port/xxxService?wsdl
4. Put the generated file in cs to the project, <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Authorization + PHByZSBjbGFzcz0 = "brush: java;"> public string username {get; set;} public string password {get; set ;}///
/// Constructor ///Public LimsSoapHeader (){}///
/// Constructor //////
User Name///
PasswordPublic LimsSoapHeader (string userName, string passWord) {this. username = userName; this. password = passWord ;}
6. Add a reference to the soapHeader in the class generated through the WSDL. First, apply for the corresponding SoapHeader variable and add reference to the method.
public LimsSoapHeader limsSoapHeader; [System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="http://webservice.web.lims.panda.com/", ResponseNamespace="http://webservice.web.lims.panda.com/", Use=System.Web.Services.Description.SoapBindingUse.Literal)] [return: System.Xml.Serialization.XmlElementAttribute("return")] [SoapHeader("limsSoapHeader")] public string importPhysicalData(string xml) { object[] results = this.Invoke("importPhysicalData", new object[] { xml}); return ((string)(results[0])); }
Call settings
Before calling a method, specify the corresponding soapHeader, as shown in figure
HospitalFacadeServiceImplService proxy = new HospitalFacadeServiceImplService (); proxy. url = "http: // hostname: port/xxxService"; // specify the SoapHeader to verify the proxy. limsSoapHeader = new LimsSoapHeader ("soapUserName", "soapPassword"); String xml = proxy. importPhysicalData ("my name is panda"); Console. writeLine (xml );
In this way, the C # WebService with SoapHeader authentication is called.