Recently called the third-party WebService interface encountered the problem of SoapHeader authentication, record the workaround.
Required format for the interface:
<Soapenv:header> <Reqsoapheaderxmlns= "Http://xxx.com"> <AppKey>Key</AppKey> <AuthKey>Pwd</AuthKey> </Reqsoapheader><Soapenv:header>
C#:
//Create header class, note property name[DataContract (Namespace ="http://xxx.com")] Public classReqsoapheader {[DataMember] Public stringAppKey {Get;Set; } [DataMember] Public stringAuthKey {Get;Set; } } //client-generated proxy class based on WSDL//Create and join requestsAddressheader SoapHeader = Addressheader.createaddressheader ("Reqsoapheader","http://xxx.com",NewReqsoapheader {AppKey ="Key", AuthKey ="pwd" }); Endpointaddressbuilder EAB=Newendpointaddressbuilder (client. endpoint.address); Eab. Headers.add (SoapHeader); Client. Endpoint.address= Eab. Toendpointaddress ();
Php:
//Create header class//Note property name classReqsoapheader { Public $appKey; Public $authKey; Public function__construct ($app,$auth) { $this->appkey=$app; $this->authkey=$auth; } }//Create soapclient and add headers$simple=NewSoapClient (NULL,Array(' Location ' =$location, ' uri ' = ' xxx.com ', ' encoding ' = ' UTF-8 '));$auth=NewReqsoapheader ("Key", "PWD");$header=NewSoapHeader (' http://xxx.com ', ' Reqsoapheader ',$auth);$simple->__setsoapheaders ($header);
C#/php calls the WebService with SoapHeader