C# 服务器端映射Soap MTOM格式(MIME边界)

C# 服务器端映射Soap MTOM格式(MIME边界),c#,wcf,soap,C#,Wcf,Soap,我试图找到一种方法来编写一个能够处理soapmtom格式的web方法。Soap请求有一个头和主体,然后是MIME边界 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_d2d526d5b9a7f9dba48a297330

我试图找到一种方法来编写一个能够处理soapmtom格式的web方法。Soap请求有一个头和主体,然后是MIME边界

   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--
下面是webmethod框架

  [WebMethod(Description = "Send document on this")]
 
        public SupportingDocReply NextGenSupportingDoc(NextGetSupportDocHeader sDocMsg)
        {
            return null;
        }
  • 如何更新类以映射到mimebundary
  • 如何更新类以从标头读取UsernameToken

  • 在webconfig中添加以下内容,使服务为MTOM和用户身份验证做好准备

     <binding name="mtomBasic" closeTimeout="00:20:00" openTimeout="00:20:00"
              receiveTimeout="00:20:00" sendTimeout="00:20:00" hostNameComparisonMode="StrongWildcard"
              maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
              textEncoding="utf-8" transferMode="Buffered" messageEncoding="Mtom">
              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" />
              <security mode="TransportWithMessageCredential">
                <message clientCredentialType="UserName" />
              </security>
            </binding>
    
    <behavior name="NextGenServiceBehavior">
          <serviceMetadata httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          <serviceCredentials>
    
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="SupportingDocsFacade.ServiceAuthenticator,SupportingDocsFacade" />
          </serviceCredentials>
    
        </behavior>
    
    
    
    在自定义身份验证的行为部分中添加以下内容

     <binding name="mtomBasic" closeTimeout="00:20:00" openTimeout="00:20:00"
              receiveTimeout="00:20:00" sendTimeout="00:20:00" hostNameComparisonMode="StrongWildcard"
              maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
              textEncoding="utf-8" transferMode="Buffered" messageEncoding="Mtom">
              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" />
              <security mode="TransportWithMessageCredential">
                <message clientCredentialType="UserName" />
              </security>
            </binding>
    
    <behavior name="NextGenServiceBehavior">
          <serviceMetadata httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          <serviceCredentials>
    
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="SupportingDocsFacade.ServiceAuthenticator,SupportingDocsFacade" />
          </serviceCredentials>
    
        </behavior>
    
    
    
    有关问题2,请参阅此