-
Notifications
You must be signed in to change notification settings - Fork 135
Description
Good morning, thanks for the BeSimple bundle, it works great!
Since I'm new to using MTOM mechanism and since it's not easy to find php code that supports MTOM attachments in SOAP messages, I would need an example.
In particular, i have to implement a SOAP client that sends a message with attachment (using MTOM mechanism) to a WS service listening. My client without attachments works.
My problem that i can not manage attachment part, I do not know what methods to call and how.
I set the header but I can not dial the message header and attachment.
It would be possible to have an example of a client sending a request with MTOM attachment ?
I attach my code.
Thank you in advance.
--- MY CODE ---
$nome = "richiesta_".time().".zip";
$clientbuilder = $this->get('besimple.soap.client.builder.client_name');
$soapClient= $clientbuilder->build();
$wsdl= $clientbuilder->getWsdl();
$sc = new BeSimpleSoapClient($wsdl, array(
'attachment_type' => BeSimpleSoapHelper::ATTACHMENTS_TYPE_MTOM,
'cache_wsdl' => WSDL_CACHE_NONE,
'trace' => 1,
'exception' => true));
$ss= new SoapCommon\Mime\Part();
$ss->setHeader("Content-Type","applicatio/xop+xml");
$ss->setHeader("type","text/xml");
$ss->setHeader("Content-Transfer-Encoding","base64");
$b53 = new SoapCommon\Mime\MultiPart();
$aa= $ss->getMessagePart();
$b53->getMimeMessage($aa);
$soapClient->getSoapKernel()->addAttachment($ss);
$b53->addPart($ss);
$sc->getSoapKernel()->addAttachment($ss);
// HEADER PARAMETER
// ---------------- my var parameter for header request----------------
// BODY PARAMETER
// ---------------- my var parameter for body request----------------
// HEADER
$CredentialObjectXML = '
<wsse:Security SOAP-ENV: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">
// ---------------- security part ----------------
</wsse:Security>';
$CredentialObject = new \SoapVar($CredentialObjectXML,XSD_ANYXML);
$header = new \SoapHeader('http://schemas.xmlsoap.org/soap/envelope/','null',$CredentialObject);
$soapClient->__setSoapHeaders($header);
// BODY
$inputparam = new \SoapVar('
<ns1:InstanceMessageCreateRequest>
// ---------------- other body request part ----------------
<attachments>
<!--Zero or more repetitions:-->
<attachment>
<fileset>attachment</fileset>
<filename>filename</filename>
<!--Optional:-->
<contentType>application</contentType>
<data>cid</data>
</attachment>
</attachments>
// ---------------- other body request part ----------------
</ns1:InstanceMessageCreateRequest>', XSD_ANYXML);
// request call
try {
$return = $soapClient->mathod_name($inputparam);
$sc->getSoapKernel()->filterRequest($return);
}
catch (\SoapFault $exception) {
}
));