一个WebService服务端是用JAVA写的,需要SOAP Header验证,soap的Header如下:
<soapenv:Header><ns1:username soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xsi:type="xsd:string" xmlns:ns1="Authorization" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">admin</ns1:username><ns1:password soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xsi:type="xsd:string" xmlns:ns1="Authorization" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">1</ns1:password></soapenv:Header>我客户端用Delphi做的。
我参考了网上一些前辈的一些soap Header代码,但发出的SOAP header都不是这样
以下是我delphi发出的SOAP Header<SOAP-ENV:Header SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:NS1="Authorization" xmlns:NS2="urn:wsGenericXcjkServer"><NS1:Authorization xsi:type="NS2:Authorization"><username xsi:type="xsd:string">admin</username><password xsi:type="xsd:string">1</password></NS1:Authorization></SOAP-ENV:Header>我实现的代码如下
// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL     : C:\Documents and Settings\Administrator\桌面\GenericXcjkServer.xml
// Encoding : UTF-8
// Version  : 1.0
// (2010-06-12 09:42:19 - 1.33.2.5)
// ************************************************************************ //unit wsGenericXcjkServer;interfaceuses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;type  // ************************************************************************ //
  // The following types, referred to in the WSDL document are not being represented
  // in this file. They are either aliases[@] of other types represented or were referred
  // to but never[!] declared in the document. The types from the latter category
  // typically map to predefined/known XML or Borland types; however, they could also 
  // indicate incorrect WSDL documents that failed to declare or import a schema type.
  // ************************************************************************ //
  // !:string          - "http://www.w3.org/2001/XMLSchema"
  // ************************************************************************ //
  // Namespace : http://webservice.hzjbbis.com
  // transport : http://schemas.xmlsoap.org/soap/http
  // style     : rpc
  // binding   : GenericXcjkServerSoapBinding
  // service   : GenericXcjkServerService
  // port      : GenericXcjkServer
  // URL       : http://10.136.34.206/fascis/services/GenericXcjkServer
  // ************************************************************************ //
  Authorization = class(TSOAPHeader)
  private
    Fusername: WideString;
    Fpassword: WideString;
  published
    property username: WideString read Fusername write Fusername;
    property password: WideString read FpassWord write Fpassword;
  end;
  GenericXcjkServer = interface(IInvokable)
  ['{71ABC778-5C38-145C-24EE-AE0FF94DECC9}']
    function  invoke(const path: WideString; const methodName: WideString; const xml: WideString): WideString; stdcall;
    function  invokeServer(const path: WideString; const methodName: WideString; const xml: WideString): WideString; stdcall;
  end;function GetGenericXcjkServer(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): GenericXcjkServer;
implementation
uses
  Unit1;
function GetGenericXcjkServer(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): GenericXcjkServer;
const
  defWSDL = 'GenericXcjkServer?wsdl';
  defURL  = 'GenericXcjkServer';
  defSvc  = 'GenericXcjkServerService';
  defPrt  = 'GenericXcjkServer';
var
  RIO: THTTPRIO;
begin
  Result := nil;
  if (Addr = '') then
  begin
    if UseWSDL then
      Addr := defWSDL
    else
      Addr := defURL;
  end;  Addr := frmMain.iniRootAddr + Addr;  if HTTPRIO = nil then
    RIO := THTTPRIO.Create(nil)
  else
    RIO := HTTPRIO;  try
    Result := (RIO as GenericXcjkServer);
    if UseWSDL then
    begin
      RIO.WSDLLocation := Addr;
      RIO.Service := defSvc;
      RIO.Port := defPrt;
    end else
      RIO.URL := Addr;
  finally
    if (Result = nil) and (HTTPRIO = nil) then
      RIO.Free;
  end;
end;
initialization
  InvRegistry.RegisterInterface(TypeInfo(GenericXcjkServer), 'http://webservice.hzjbbis.com', 'UTF-8');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(GenericXcjkServer), '');
  InvRegistry.RegisterHeaderClass(TypeInfo(GenericXcjkServer), Authorization, 'username', 'Authorization',hmtRequest);
  RemClassRegistry.RegisterXSInfo(TypeInfo(GenericXcjkServer), '','Authorization', 'Authorization');  InvRegistry.RegisterInvokeOptions(TypeInfo(GenericXcjkServer), ioLiteral);  RemClassRegistry.RegisterSerializeOptions(TypeInfo(Authorization), [xoHolderClass,xoSimpleTypeWrapper]);        //xoLiteralParam xoHolderClass  //RemClassRegistry.RegisterXSClass(Authorization);///////////////////////调用代码////////////////////
procedure TfrmMain.btn1Click(Sender: TObject);
var
  Headers: ISOAPHeaders;
  H: Authorization;
  webServer: GenericXcjkServer;
  path, methodName: WideString;
  strXML: WideString;
  strRe: WideString;
const
  dataMd =  '<?xml version="1.0" encoding="UTF-8"?><DBSET><R><C N="DWDM">%s</C>'
          + '<C N="HH">1315096228</C><C N="BJJH">AG30002586</C>'
          + '<C N="SJSJ">2009-08-10</C><C N="ZXYGZ">200.01</C><C N="ZXYGZ1">100.05</C></R>'
          + '<R><C N="DWDM">%s</C><C N="HH">1321019934</C><C N="BJJH">AG30002587</C>'
+ '<C N="SJSJ">2009-08-11</C><C N="ZXYGZ">300.01</C><C N="ZXYGZ1">103.05</C><C N="ZXYGZ2">103.88</C></R></DBSET>' ;
Begin
  iniRootAddr := edtServerAddr.Text;
  path := 'com/zpepc/webservice/FasWSForJc';
  methodName := 'storeAmeterData';
  strXML := Format(dataMd, [Trim(edtUnitCode.Text), Trim(edtUnitCode.Text)]);  webServer := GetGenericXcjkServer();
  //aIntf := (HTTPRio as ISoapAuth);
  H := Authorization.Create;
  H.UserName := edtUserName.Text ;  //这里只是举个例子
  H.PassWord := edtPSW.Text;
  Try
    Headers := (webServer  as  ISOAPHeaders);    Headers.Send(H);  //发送Soap Header
    strRe := webServer.invoke(path, methodName, strXML);  //调用服务
    mmo1.Text := strRe;
  finally
    webServer := nil;
    H.Free;
  end;end;end.====================
无法通过验证,请高手们指点兄弟,谢谢