【问题标题】:Soap Service Upload Attachment Using Angular使用 Angular 的 Soap 服务上传附件
【发布时间】:2019-05-29 05:44:06
【问题描述】:

我正在使用soap 服务,在soap 服务中,我传递XML 和文件附件。在 SoapUI 工具中它的工作正常。但就我而言,我想通过 Angular6 来实现。这是我的 Xml 代码。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdl="http://service.wsvc.mhb.crimsonlogic.com/wsdl">
 <soapenv:Header><wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><wsse:UsernameToken wsu:Id="UsernameToken-4C616D2C88CB4E2F9915586128832798"><wsse:Username>this.userName</wsse:Username>
    <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest"> token.getPasswordDigest()  </wsse:Password><wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"> token.getNonceBase64() </wsse:Nonce><wsu:Created> token.getCreated() </wsu:Created></wsse:UsernameToken></wsse:Security>
     </soapenv:Header>
      <soapenv:Body>
      <wsdl:SubmitMessageRequest>
      <wsdl:DocumentType> document </wsdl:DocumentType>
       <wsdl:Subject>this.fileName</wsdl:Subject>
       <wsdl:PayloadName>
        <wsdl:href>cid: this.fileName</wsdl:href>
        </wsdl:PayloadName>
       <wsdl:AttachmentFile>
        <wsdl:href>?</wsdl:href>
         </wsdl:AttachmentFile>
         </wsdl:SubmitMessageRequest>
        </wsdl:MessageSubmission>
      </soapenv:Body>
      </soapenv:Envelope>

【问题讨论】:

    标签: javascript angular typescript web-services soap


    【解决方案1】:

    SOAP 服务使用 HTTP 协议,所以这是可能的。为了与 SOAP 服务进行通信,您可以使用 ngx-soap angular 模块。在 SOAP 请求的正文中,您需要将要上传的文件作为二进制数据放入。

    模板文件

    <input
      style="display: none"
      type="file" (change)="onFileChanged($event)"
      #fileInput>
    <button (click)="fileInput.click()">Select File</button>
    <button (click)="onUpload()">Upload!</button>
    

    组件文件

    export class MyFileUploadComponent {
      selectedFile: File
      client: Client;
    
      constructor(private soap: NgxSoapService) {
         this.soap.createClient('assets/fileuploader.wsdl').subscribe(client => this.client = client);
      }
    
      onFileChanged(event) {
        this.selectedFile = event.target.files[0]
      }
    
      onUpload() {
        // upload code goes here
        const body = {
              file: this.selectedFile
        };
        (<any>this.client).Add(body).subscribe((res: ISoapMethodResponse) => this.message = res.result.AddResult);
      }
    }
    

    【讨论】:

    • 谢谢@Rambou,但在我的场景文件中还有 XML 正文。
    • 那么请使用示例 XML 文件更新您的问题,以便我提供帮助。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-16
    • 1970-01-01
    • 1970-01-01
    • 2019-11-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多