如何在 SOAP 接口调用的 Http header 中增加字段

如何在 SOAP 接口调用的 Http header 中增加字段,第1张

在 Delphi 中添加 SOAP Header 就不用说了,请参考 Delphi 自带示例,位于 Demos/WebServices/SOAPHeaders 目录下。添加 Http header 字段示例如下。

示例 WSDL 文件描述如下:

SampleServiceSoap = class(IInvokable)

['{08323867-2307-4569-8405-4E575CC3C453}']

procedure SampleProcedure1

procedure SampleProcedure2

end

function GetSampleServiceSoap(UseWSDL: BooleanAddr: stringHTTPRIO: THTTPRIO): SampleSoap

const

defWSDL = 'http://127.0.0.1/SampleService.asmx?WSDL'

defURL = 'http://127.0.0.1/SampleService.asmx'

defSvc = 'SampleService'

defPrt = 'SampleServiceSoap'

var

RIO: THTTPRIO

begin

Result := nil

if (Addr = '') then

begin

if UseWSDL then

Addr := defWSDL

else

Addr := defURL

end

if HTTPRIO = nil then

RIO := THTTPRIO.Create(nil)

else

RIO := HTTPRIO

try

Result := (RIO as SampleServiceSoap)

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

增加 Http header 示例如下:

unit Unit1

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls, SOAPHTTPTrans, SOAPHTTPClient, ActiveX

type

TForm1 = class(TForm)

Button1: TButton

procedure Button1Click(Sender: TObject)

private

procedure BeforePost(const HTTPReqResp: THTTPReqRespData: Pointer)

public

end

var

Form1: TForm1

implementation

{$R *.dfm}

// 在发送请求之前在 http header 中添加 CustomHeader 字段

// Data 是指向 HINTERNET 类型的指针

procedure TForm1.BeforePost(const HTTPReqResp: THTTPReqResp

Data: Pointer)

const

csCustomHeader = 'CustomHeader:XXXXXXXX'

begin

HttpAddRequestHeaders(Data, PChar(csCustomHeader), Length(csCustomHeader),

HTTP_ADDREQ_FLAG_ADD)

end

procedure TForm1.Button1Click(Sender: TObject)

var

Soap: SampleServiceSoap

RIO: THTTPRIO

begin

CoInitialize(nil)

RIO := THTTPRIO.Create(nil)

try

RIO.HTTPWebNode.OnBeforePost := BeforePost

Soap := GetSampleServiceSoap(False, 'http://127.0.0.1/SampleService.asmx', RIO)

if Assigned(Soap) then

Soap.SampleProcedure1

finally

RIO.Free

CoUninitialize

end

end

end.

此问题请参考esri说明文档:

http://support.esri.com/es/knowledgebase/techarticles/detail/34782

出错原因是:The feature class or table contains at least one feature or row. Fields with Allow NULL Values = NO can only be added to empty feature classes or tables.

也就是说,只有是空要素时才能设置字段值不允许为空。文档中附有解决方案。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11351001.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-15
下一篇 2023-05-15

发表评论

登录后才能评论

评论列表(0条)

保存