WSDL可调用接口方法调用时出现访问冲突错误...?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WSDL可调用接口方法调用时出现访问冲突错误...?相关的知识,希望对你有一定的参考价值。

我想在delphi中使用服务(WSDL IMPORTER),但我不能这样做,因为当我调用此代码时引发了错误'地址访问冲突......'

接口:

 SendLetterService = interface(IInvokable)
  ['{FFACC70E-33A0-5413-E720-F5421944C864}']
     function  sendLetters(const parameters: sendLetters):sendLettersResponse; stdcall;
     function  getLetterType(const parameters: getLetterType):getLetterTypeResponse; stdcall;
     function  getOrgLetterType(const parameters: getOrgLetterType):getOrgLetterTypeResponse; stdcall;
     function  getOrgForms(const parameters: getOrgForms):getOrgFormsResponse; stdcall;
  end;

 function GetSendLetterService(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): SendLetterService;

 implementation
 function GetSendLetterService(UseWSDL: Boolean; Addr: string;HTTPRIO:THTTPRIO): SendLetterService;
 const
    defWSDL = 'E:delphiTSN0sendletter.xml';
    defURL  = 'http://10.0.233.254/ebox/sendletter?wsdl';
    defSvc  = 'SendLetterServicePortBindingQSService';
    defPrt  = 'SendLetterServicePortBindingQSPort';
 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
    if UseWSDL then
    begin
        RIO.WSDLLocation := Addr;
        RIO.Service := defSvc;
        RIO.Port := defPrt;
    end
    else
       RIO.URL := Addr;
     Result := (RIO as SendLetterService);
    finally
      if (Result = nil) and (HTTPRIO = nil) then
      RIO.Free;
     end;
  end;

*******我的电话代码方法*******

procedure TForm1.btnRcvLetterTypesClick(Sender: TObject);
var
  Response : getLetterTypeResponse;
  glt : getLetterType;     
  Srv : SendLetterService;
begin
 Response := getLetterTypeResponse.Create;
 glt := getLetterType.Create;
 try
    Srv := GetSendLetterService(True,'');
  if Assigned(Srv) then
      {======= Access Violation?????? ===========}
       Response := Srv.getLetterType(glt);
      {======= Access Violation?????? ===========}
 finally
   Response.Free;
   glt.Free;
 end;
 end;

当按钮点击此代码运行但在{===}部分引发错误...请帮助我...

答案

完整代码:WSDL导入创建的接口:

type

  sendLetterAttach     = class;
   Array_Of_sendLetterAttach = array of sendLetterAttach;
   sendLetterAttach = class(TRemotable)
   private
     FfileData: TByteDynArray;
     FfileData_Specified: boolean;
     FfileName: string;
     FfileName_Specified: boolean;
     procedure SetfileData(Index: Integer; const ATByteDynArray: TByteDynArray);
     function  fileData_Specified(Index: Integer): boolean;
     procedure SetfileName(Index: Integer; const Astring: string);
     function  fileName_Specified(Index: Integer): boolean;
   published
     property fileData: TByteDynArray  Index (IS_OPTN or IS_UNQL) read FfileData           
              write SetfileData stored fileData_Specified;
      property fileName: string         Index (IS_OPTN or IS_UNQL) read FfileName      
             write SetfileName stored fileName_Specified;
   end;

   getLetterTypeResponseType = array of string;

   SendLetterService = interface(IInvokable)
   ['{FFACC70E-33A0-5413-E720-F5421944C864}']
     function  sendLetters(const orgCode: string; const orgUser: string; 
             const orgUserPassword: string; const letterTypeCode: string; 
             const orgLetterTypeCode: string; const letterSubject: string; 
             const letterText: string; const letterOfficialNO: string; 
             const letterOfficialDate: string; const letterCanDelete: Int64; 
             const letterCanReply: Int64; const lettterReplyDueDate: string; 
             const letterPaymentNo: string; const formCode: string; 
             const InPersonAuthentication: Int64; 
             const people: getLetterTypeResponseType; 
             const attachments: Array_Of_sendLetterAttach): string;   stdcall;
        function  getLetterType(const orgCode: string; const orgUser: string; 
             const orgUserPassword: string): getLetterTypeResponseType; stdcall;
        function  getOrgLetterType(const orgCode: string; const orgUser: string; 
             const orgUserPassword: string; 
             const letterTypeCode: string):getLetterTypeResponseType; stdcall;
        function  getOrgForms(const orgCode: string; const orgUser: string; 
             const orgUserPassword: string): getLetterTypeResponseType; stdcall;
   end;

    function GetSendLetterService(UseWSDL: Boolean=System.False; Addr: string=''; 
        HTTPRIO: THTTPRIO = nil): SendLetterService;


    implementation
        uses SysUtils;

    function GetSendLetterService(UseWSDL: Boolean; Addr: string; HTTPRIO:      
            THTTPRIO): SendLetterService;
  const
   defWSDL = 'http://10.0.233.254/ebox/sendletter?wsdl';
   defURL  = 'http://10.0.233.254/ebox/sendletter';
   defSvc  = 'SendLetterServicePortBindingQSService';
   defPrt  = 'SendLetterServicePortBindingQSPort';
 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 SendLetterService);
     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;

和我调用方法的代码:

procedure TForm1.btnRcvLetterTypesClick(Sender: TObject);
var
  Response: getLetterTypeResponseType;
  I: Integer;
  Srv : SendLetterService;
begin
try
   Srv := GetSendLetterService(True);       

   srv.getLetterType('Code','UserName','Pass');        

 finally

 end;
 end;

以上是关于WSDL可调用接口方法调用时出现访问冲突错误...?的主要内容,如果未能解决你的问题,请参考以下文章

执行可调用语句时出现 SQLException

插入记录时出现语法错误或访问冲突

访问分配的内存时出现访问冲突错误[重复]

使用带有分号字符的 STRPOS 时出现语法错误或访问冲突

WindowsError 异常访问冲突 - 在简单的 python c++ ctypes 接口中

调用 [playerFactory play] 方法时出现错误访问错误