Delphi 6中导入的界面中缺少Wsdl soap标头

时间:2011-02-14 00:04:48

标签: delphi soap delphi-6

我正在尝试使用Delphi 6实现Web服务.Web服务使用soap 1.2版,而我的delphi有一个1.1的soap代理。当我尝试导入wsdl时,界面中缺少soap标题“Autenticacao”。提供商坚持在调用Web服务之前将4个参数作为此soap标头的一部分发送?我已经附加了我的wsdl xml文件和导入的pas文件?

有人可以帮我设置“Autenticacao”的参数吗?

提前致谢。

亲切的问候 西努

.xml文件内容

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="https://www.nfp.sp.gov.br/ws" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" targetNamespace="https://www.nfp.sp.gov.br/ws" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:types>
    <s:schema elementFormDefault="qualified" targetNamespace="https://www.nfp.sp.gov.br/ws">
      <s:element name="Enviar">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="NomeArquivo" type="s:string"/>
            <s:element minOccurs="0" maxOccurs="1" name="ConteudoArquivo" type="s:string"/>
            <s:element minOccurs="0" maxOccurs="1" name="Observacoes" type="s:string"/>
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="EnviarResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="EnviarResult" type="s:string"/>
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="Autenticacao" type="tns:Autenticacao"/>
      <s:complexType name="Autenticacao">
        <s:attribute name="Usuario" type="s:string"/>
        <s:attribute name="Senha" type="s:string"/>
        <s:attribute name="CNPJ" type="s:string"/>
        <s:attribute name="CategoriaUsuario" type="s:unsignedByte" use="required"/>
        <s:anyAttribute/>
      </s:complexType>
      <s:element name="Consultar">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="Protocolo" type="s:string"/>
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="ConsultarResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="ConsultarResult" type="s:string"/>
          </s:sequence>
        </s:complexType>
      </s:element>
    </s:schema>
  </wsdl:types>
  <wsdl:message name="EnviarSoap12In">
    <wsdl:part name="parameters" element="tns:Enviar"/>
  </wsdl:message>
  <wsdl:message name="EnviarSoap12Out">
    <wsdl:part name="parameters" element="tns:EnviarResponse"/>
  </wsdl:message>
  <wsdl:message name="EnviarAutenticacao">
    <wsdl:part name="Autenticacao" element="tns:Autenticacao"/>
  </wsdl:message>
  <wsdl:message name="ConsultarSoap12In">
    <wsdl:part name="parameters" element="tns:Consultar"/>
  </wsdl:message>
  <wsdl:message name="ConsultarSoap12Out">
    <wsdl:part name="parameters" element="tns:ConsultarResponse"/>
  </wsdl:message>
  <wsdl:message name="ConsultarAutenticacao">
    <wsdl:part name="Autenticacao" element="tns:Autenticacao"/>
  </wsdl:message>
  <wsdl:portType name="ArquivoNF_Mod1Soap12">
    <wsdl:operation name="Enviar">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">&lt;br /&gt;Este método deve ser usado para envio do arquivo de Nota Fiscal modelo 1/1A.&lt;br /&gt;Os parâmetros de autenticação, informados via SOAP Header, são:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Usuario&lt;/b&gt;: login do usuário que está fazendo a requisição de acordo com o perfil escolhido&lt;/li&gt;&lt;li&gt;&lt;b&gt;Senha&lt;/b&gt;: senha do usuário&lt;/li&gt;&lt;li&gt;&lt;b&gt;CNPJ&lt;/b&gt;: CNPJ do estabelecimento ao qual o usuário está vinculado e o arquivo pertence&lt;/li&gt;&lt;li&gt;&lt;b&gt;CategoriaUsuario&lt;/b&gt;: perfil do usuário informado (1 para contribuintes e 2 para contabilistas)&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;Os parâmetros do método são:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;NomeArquivo&lt;/b&gt;: nome do arquivo enviado&lt;/li&gt;&lt;li&gt;&lt;b&gt;ConteudoArquivo&lt;/b&gt;: conteúdo do arquivo enviado&lt;/li&gt;&lt;li&gt;&lt;b&gt;Observacoes&lt;/b&gt;: observações, caso existam, relativas ao arquivo ou envio&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;</wsdl:documentation>
      <wsdl:input message="tns:EnviarSoap12In"/>
      <wsdl:output message="tns:EnviarSoap12Out"/>
    </wsdl:operation>
    <wsdl:operation name="Consultar">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">&lt;br /&gt;Este método é utilizado para consultar o resultado de processamento para um arquivo de Nota Fiscal modelo 1.&lt;br /&gt;Os parâmetros de autenticação, informados via SOAP Header, são:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Usuario&lt;/b&gt;: login do usuário que está fazendo a requisição de acordo com o perfil escolhido&lt;/li&gt;&lt;li&gt;&lt;b&gt;Senha&lt;/b&gt;: senha do usuário&lt;/li&gt;&lt;li&gt;&lt;b&gt;CNPJ&lt;/b&gt;: CNPJ do estabelecimento ao qual o usuário está vinculado e o arquivo pertence&lt;/li&gt;&lt;li&gt;&lt;b&gt;CategoriaUsuario&lt;/b&gt;: perfil do usuário informado (1 para contribuintes e 2 para contabilistas)&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;O parâmetro do método é:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Protocolo&lt;/b&gt;: número do protocolo a ser consultado&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;</wsdl:documentation>
      <wsdl:input message="tns:ConsultarSoap12In"/>
      <wsdl:output message="tns:ConsultarSoap12Out"/>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="ArquivoNF_Mod1Soap12" type="tns:ArquivoNF_Mod1Soap12">
    <soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="Enviar">
      <soap12:operation soapAction="https://www.nfp.sp.gov.br/ws/Enviar" style="document"/>
      <wsdl:input>
        <soap12:body use="literal"/>
        <soap12:header message="tns:EnviarAutenticacao" part="Autenticacao" use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="Consultar">
      <soap12:operation soapAction="https://www.nfp.sp.gov.br/ws/Consultar" style="document"/>
      <wsdl:input>
        <soap12:body use="literal"/>
        <soap12:header message="tns:ConsultarAutenticacao" part="Autenticacao" use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="ArquivoNF_Mod1">
    <wsdl:port name="ArquivoNF_Mod1Soap12" binding="tns:ArquivoNF_Mod1Soap12">
      <soap12:address location="https://www.nfp.fazenda.sp.gov.br/ws/arquivonf_mod1.asmx"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

.pas文件内容

// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL     : C:\Projects\Delphi 6\WBWaiter\arquivonf_mod1.asmx.xml
// Encoding : UTF-8
// Version  : 1.0
// (10/02/2011 4:37:33 p.m. - $Revision:   1.9.1.0.1.0.1.9  $)
// ************************************************************************ //

unit arquivonf_mod1;

interface

uses InvokeRegistry, 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"

  ConsultarResponse    = class;                 { "https://www.nfp.sp.gov.br/ws" }
  Consultar            = class;                 { "https://www.nfp.sp.gov.br/ws" }
  EnviarResponse       = class;                 { "https://www.nfp.sp.gov.br/ws" }
  Enviar               = class;                 { "https://www.nfp.sp.gov.br/ws" }

  // ************************************************************************ //

  // ************************************************************************ //
  ConsultarResponse = class(TRemotable)
  private
    FConsultarResult: String;
  published
    property ConsultarResult: String read FConsultarResult write FConsultarResult;
  end;

  // ************************************************************************ //
  // 
  // ************************************************************************ //
  Consultar = class(TRemotable)
  private
    FProtocolo: String;
  published
    property Protocolo: String read FProtocolo write FProtocolo;
  end;

  // ************************************************************************ //
  // 
  // ************************************************************************ //
  EnviarResponse = class(TRemotable)
  private
    FEnviarResult: String;
  published
    property EnviarResult: String read FEnviarResult write FEnviarResult;
  end;

  // ************************************************************************ //
  // 
  // ************************************************************************ //
  Enviar = class(TRemotable)
  private
    FNomeArquivo: String;
    FConteudoArquivo: String;
    FObservacoes: String;
  published
    property NomeArquivo: String read FNomeArquivo write FNomeArquivo;
    property ConteudoArquivo: String read FConteudoArquivo write FConteudoArquivo;
    property Observacoes: String read FObservacoes write FObservacoes;
  end;

  // ************************************************************************ //
  // Namespace : 
  // binding   : ArquivoNF_Mod1Soap12
  // service   : ArquivoNF_Mod1
  // port      : ArquivoNF_Mod1Soap12
  // ************************************************************************ //
  ArquivoNF_Mod1Soap12 = interface(IInvokable)
  ['{AD787B4C-A2C5-BE98-12B8-A37CF0CEA897}']
    function  Enviar(const parameters: Enviar): EnviarResponse; stdcall;
    function  Consultar(const parameters: Consultar): ConsultarResponse; stdcall;
  end;

implementation
  uses SOAPHTTPClient;

initialization
  InvRegistry.RegisterInterface(TypeInfo(ArquivoNF_Mod1Soap12), 'https://www.nfp.sp.gov.br/ws', 'UTF-8');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(ArquivoNF_Mod1Soap12), '');
  RemClassRegistry.RegisterXSClass(ConsultarResponse, 'https://www.nfp.sp.gov.br/ws', 'ConsultarResponse');
  RemClassRegistry.RegisterXSClass(Consultar, 'https://www.nfp.sp.gov.br/ws', 'Consultar');
  RemClassRegistry.RegisterXSClass(EnviarResponse, 'https://www.nfp.sp.gov.br/ws', 'EnviarResponse');
  RemClassRegistry.RegisterXSClass(Enviar, 'https://www.nfp.sp.gov.br/ws', 'Enviar');

end. 

3 个答案:

答案 0 :(得分:1)

我认为最简单的解决方案是升级到更新的Delphi版本,最好是Delphi XE,它具有更好的SOAP支持。 Delphi 6不再适用于现代开发。特别是SOAPy部分...
作为替代方案,您可以让Delphi XE的某个人在XE中为您导入服务,然后将代码迁移回Delphi 6.但是我担心如果您尝试这样做会有太多的不兼容性。
另一种解决方案包括使用Visual Studio为您的Delphi应用程序创建客户端代理。这恰好是我过去必须为某个项目选择的解决方案。您可以使用C#创建一个支持COM的程序集,您可以从Delphi应用程序中调用它。然后,该程序集执行对Web服务的调用。这是一个令人恼火的解决方法,但是当你开始工作时,它的效果也很好。

答案 1 :(得分:0)

您可以通过在RIO_AfterExecute方法期间更改响应XML来解决问题。只需使用StringReplace将标题注入响应,您需要它。我们做了类似的事情,但在我们的例子中,我们有一些根本没有出现在WSDL中的身份验证内容,因为它实际上并不是目标服务所需要的,而是由中间XML网关用来验证请求。所以我们只是用一个stringreplace“把它塞进那里”。

答案 2 :(得分:0)

如果您转到 Delphi 7 ,您的选项会改善......

Delphi 7 WSDL导入程序(wsdlimp.exe)有一个可以从Embarcadero ID: 24535, Delphi SOAP Runtime and Importer Update下载的更新

虽然没有说支持Delphi 6(可能是技术或营销原因),但您可以尝试从命令行使用下载的wsdlimp.exe,然后使用Delphi 6尝试生成的.pas文件无论如何都是项目。

相关问题