Wcf для получения больших данных - параметр MTOM - PullRequest
0 голосов
/ 21 октября 2019

Я пытаюсь написать веб-сервис, который может принимать данные от клиента вместе с некоторыми параметрами. Пример запроса клиента мыла может выглядеть следующим образом. Этот формат используется потому, что у клиента уже есть указанный формат, и нам нужно предоставить веб-сервис, совместимый с клиентом

    POST /v2/document/soap HTTP/1.1
Host: doctest.applyonline.com.au
User-Agent: curl/7.43.0
Accept: */*
Content-Type: multipart/related; boundary="MIMEBoundary_d2d526d5b9a7f9dba48a297330bf779329aac7a96200f579"; type="application/xop+xml"; start="<0.a2d526d5b9a7f9dba48a297330bf779329aac7a96200f579@apache.org>"; start-info="application/soap+xml"; action="http://localhost:8080/RequestEmailer/email?requestType=ANZSOAP&sendTo=daniel.szwed@nextgen.net"

--MIMEBoundary_d2d526d5b9a7f9dba48a297330bf779329aac7a96200f579
Content-Type: application/xop+xml; charset=UTF-8; type="application/soap+xml"
Content-Transfer-Encoding: binary
Content-ID: <0.a2d526d5b9a7f9dba48a297330bf779329aac7a96200f579@apache.org>

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
    <soapenv:Header>
        <wsa:To xmlns:wsa="http://www.w3.org/2005/08/addressing">Application Centre</wsa:To>
        <wsa:From xmlns:wsa="http://www.w3.org/2005/08/addressing">
            <wsa:Address>SAIG</wsa:Address>
        </wsa:From>
        <wsa:Action xmlns:wsa="http://www.w3.org/2005/08/addressing">http://resources.nextgen.net/Reference/BUNDLE/wsdl/DocumentExchange</wsa:Action>
        <wsa:MessageID xmlns:wsa="http://www.w3.org/2005/08/addressing">http://resources.nextgen.net/Storage/NextGen/BUNDLE/9b16574b-bc6f-4ace-88ab-5d12cc717dc7/e1ce7ca9-52cb-42f0-b9f0-784b72868713</wsa:MessageID>
        <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
            <wsse:UsernameToken>
                <wsse:Username>DocumentExchangeUATNABSAIG</wsse:Username>
                <wsse:Password wsse:type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">*password goes here*</wsse:Password>
            </wsse:UsernameToken>
        </wsse:Security>
    </soapenv:Header>
    <soapenv:Body>
        <m:DocumentExchangeRequest xmlns:m="http://resources.nextgen.net/Reference/NextGen/WSDL/DocumentExchange/2016/03/29">
            <m:Documents m:bundleIdentifier="9b16574b-bc6f-4ace-88ab-5d12cc717dc7">
                <m:Document m:documentIdentifier="618e451f-d511-4f42-84ee-4520e6b2c7ef" m:documentPart="1" m:ofDocumentParts="1" m:batchPart="1" m:ofBatchParts="3">
                    <m:Data>
                        <xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:35ca06c2-0b57-4cbf-84fa-09caaca4a0df"/>
                    </m:Data>
                    <dcds:descriptionSet xmlns:dcds="http://purl.org/dc/xmlns/2008/09/01/dc-ds-xml/">
                        <dcds:description xmlns:ns0="http://purl.org/dc/xmlns/2008/09/01/dc-ds-xml/">
                            <dcds:statement ns0:propertyURI="http://purl.org/dc/terms/creator">
                                <dcds:literalValueString>FunctionalTest</dcds:literalValueString>
                            </dcds:statement>
                        </dcds:description>
                    </dcds:descriptionSet>
                    <m:LoanFileIdentifiers>
                        <m:LoanFileIdentifier m:identifierType="ApplyOnlineID" m:identifierOwner="ApplyOnline">96544-NABBROKER</m:LoanFileIdentifier>
                    </m:LoanFileIdentifiers>
                </m:Document>
                <m:Document m:documentIdentifier="984c39cf-7004-426c-87d6-31a3362fff6e" m:documentPart="1" m:ofDocumentParts="2" m:batchPart="2" m:ofBatchParts="3">
                    <m:Data>
                        <xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:038dbbbf-2328-430a-8081-35cfd4ac9de2"/>
                    </m:Data>
                    <dcds:descriptionSet xmlns:dcds="http://purl.org/dc/xmlns/2008/09/01/dc-ds-xml/">
                        <dcds:description xmlns:ns0="http://purl.org/dc/xmlns/2008/09/01/dc-ds-xml/">
                            <dcds:statement ns0:propertyURI="http://purl.org/dc/terms/creator">
                                <dcds:literalValueString>FunctionalTest</dcds:literalValueString>
                            </dcds:statement>
                        </dcds:description>
                    </dcds:descriptionSet>
                    <m:LoanFileIdentifiers>
                        <m:LoanFileIdentifier m:identifierType="ApplyOnlineID" m:identifierOwner="ApplyOnline">96544-NABBROKER</m:LoanFileIdentifier>
                    </m:LoanFileIdentifiers>
                </m:Document>
                <m:Document m:documentIdentifier="0fc3564b-4947-4522-8902-1706438bfbf1" m:documentPart="2" m:ofDocumentParts="2" m:batchPart="3" m:ofBatchParts="3">
                    <m:Data>
                        <xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:f688eb04-2fc7-4037-9f1c-10682295b050"/>
                    </m:Data>
                    <dcds:descriptionSet xmlns:dcds="http://purl.org/dc/xmlns/2008/09/01/dc-ds-xml/">
                        <dcds:description xmlns:ns0="http://purl.org/dc/xmlns/2008/09/01/dc-ds-xml/">
                            <dcds:statement ns0:propertyURI="http://purl.org/dc/terms/creator">
                                <dcds:literalValueString>FunctionalTest</dcds:literalValueString>
                            </dcds:statement>
                        </dcds:description>
                    </dcds:descriptionSet>
                    <m:LoanFileIdentifiers>
                        <m:LoanFileIdentifier m:identifierType="ApplyOnlineID" m:identifierOwner="ApplyOnline">96544-NABBROKER</m:LoanFileIdentifier>
                    </m:LoanFileIdentifiers>
                </m:Document>
            </m:Documents>
        </m:DocumentExchangeRequest>
    </soapenv:Body>
</soapenv:Envelope>
--MIMEBoundary_d2d526d5b9a7f9dba48a297330bf779329aac7a96200f579
Content-Type: text/plain
Content-Transfer-Encoding: binary
Content-ID: <35ca06c2-0b57-4cbf-84fa-09caaca4a0df>

Document 1
--MIMEBoundary_d2d526d5b9a7f9dba48a297330bf779329aac7a96200f579
Content-Type: text/plain
Content-Transfer-Encoding: binary
Content-ID: <038dbbbf-2328-430a-8081-35cfd4ac9de2>

Document 2
--MIMEBoundary_d2d526d5b9a7f9dba48a297330bf779329aac7a96200f579
Content-Type: application/pdf
Content-Transfer-Encoding: binary
Content-ID: <f688eb04-2fc7-4037-9f1c-10682295b050>

%PDF-1.4
<removed binary PDF content.>
%%EOF

--MIMEBoundary_d2d526d5b9a7f9dba48a297330bf779329aac7a96200f579--

После прочтения другой статьи я обнаружил, что мне нужно перейти с сообщениемКонтракт.

Образец Контракта с сообщением приведен ниже

[MessageContract]
public class RemoteFileInfo : IDisposable
{
     [MessageHeader(MustUnderstand = true)]
    public  DocumentExchangeRequestrq dcExhange;

    [MessageBodyMember]
    public System.IO.Stream FileByteStream;

    public void Dispose()
    {
        if (FileByteStream != null)
        {
            FileByteStream.Close();
            FileByteStream = null;
        }
    }
}


[Serializable]
      [DataContract(Namespace = "")]
     public class LoanFileIdentifiers
      {
          [DataMember(IsRequired = true)]
          public string DocHeaderID { get; set; }

          [DataMember(IsRequired = true)]
          public string BrokerID { get; set; }

          [DataMember(IsRequired = true)]
          public string ApplyOnlineID { get; set; }
      }


      [Serializable]
      [DataContract(Namespace = "")]

      public class DocumentExchangeRequestrq
      {


      [DataMember(IsRequired = true)]
      public DocumentDescriptionSet DocumentDescription { get; set; }


      [DataMember(IsRequired = true)]
      public LoanFileIdentifiers LoanIdentifier { get; set; }
  }
  [Serializable]
  [DataContract(Namespace = "")] 
  public class DocumentDescriptionSet
  {
      [DataMember(IsRequired = true)]
      public string  Statement { get; set; }

      [DataMember(IsRequired = true)]
      public string DocumentID { get; set; }

      [DataMember()]
      public string DocumentCreated { get; set; }
  }

Одна вещь, которая меня беспокоит, это то, что Description, Loanidentity являются членами body, но из-за потока я не могу иметь более одного члена messagebody,Есть ли способ передать их в качестве параметра или это оставить его в MessageHeader.

Когда я проверил запрос мыла, все параметры находятся в области заголовка. Есть ли способ заставить их появиться в части тела

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header>
      <tem:dcExhange>
         <DocumentDescription>
            <DocumentID>?</DocumentID>
            <Statement>?</Statement>
         </DocumentDescription>
         <LoanIdentifier>
            <ApplyOnlineID>?</ApplyOnlineID>
            <BrokerID>?</BrokerID>
            <DocHeaderID>?</DocHeaderID>
         </LoanIdentifier>
      </tem:dcExhange>

   </soapenv:Header>
   <soapenv:Body>
      <tem:RemoteFileInfo>
         <tem:FileByteStream>cid:1201880270141</tem:FileByteStream>
      </tem:RemoteFileInfo>
   </soapenv:Body>
</soapenv:Envelope>
...