web-services - WDSL 服务问题
问题描述
我正在尝试开发代码以使用 Web 服务。文档在这里:https ://app.foliosdigitalespac.com/CR33Test/ConexionRemota.svc 。具体来说,我想使用方法GenerarTicket。
如果我使用这个工具并提供上面的链接,我可以为这个特定的方法生成一个 XML。这是生成的 XML。
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tem="http://tempuri.org/"
xmlns:tes="http://schemas.datacontract.org/2004/07/TES.V33.CFDI.Negocios">
<soapenv:Header/>
<soapenv:Body>
<tem:GenerarTicket>
<!--Optional:-->
<tem:credenciales>
<!--Optional:-->
<tes:Cuenta>TES030201001</tes:Cuenta>
<!--Optional:-->
<tes:Password>TES030201001j+2020</tes:Password>
<!--Optional:-->
<tes:Usuario>TES030201001</tes:Usuario>
</tem:credenciales>
<!--Optional:-->
<tem:ticket>
<!--Optional:-->
<tes:ClaveCFDI>FAC</tes:ClaveCFDI>
<!--Optional:-->
<tes:Conceptos>
<!--Zero or more repetitions:-->
<tes:ConceptoR>
<!--Optional:-->
<tes:Cantidad>2</tes:Cantidad>
<!--Optional:-->
<tes:ClaveProdServ>84111506</tes:ClaveProdServ>
<!--Optional:-->
<tes:ClaveUnidad>C81</tes:ClaveUnidad>
<!--Optional:-->
<!--Optional:-->
<tes:Descripcion>Producto 1</tes:Descripcion>
<!--Optional:-->
<tes:Importe>0.09</tes:Importe>
<!--Optional:-->
<tes:NoIdentificacion>1234567890</tes:NoIdentificacion>
<!--Optional:-->
<tes:Unidad>ACT</tes:Unidad>
<!--Optional:-->
<tes:ValorUnitario>0.045</tes:ValorUnitario>
<!--Optional:-->
</tes:ConceptoR>
<tes:ConceptoR>
<!--Optional:-->
<tes:Cantidad>5</tes:Cantidad>
<!--Optional:-->
<tes:ClaveProdServ>84111506</tes:ClaveProdServ>
<!--Optional:-->
<tes:ClaveUnidad>C81</tes:ClaveUnidad>
<!--Optional:-->
<tes:Descripcion>Producto 2</tes:Descripcion>
<!--Optional:-->
<tes:Importe>0.02</tes:Importe>
<!--Optional:-->
<tes:NoIdentificacion>001</tes:NoIdentificacion>
<!--Optional:-->
<tes:Unidad>ACT</tes:Unidad>
<!--Optional:-->
<tes:ValorUnitario>0.004</tes:ValorUnitario>
<!--Optional:-->
</tes:ConceptoR>
</tes:Conceptos>
<!--Optional:-->
<tes:CondicionesDePago>Condiciones De Pago</tes:CondicionesDePago>
<!--Optional:-->
<!--Optional:-->
<tes:Emisor>
<!--Optional:-->
<tes:Nombre>Nombre del Emisor</tes:Nombre>
<!--Optional:-->
<tes:RegimenFiscal>601</tes:RegimenFiscal>
</tes:Emisor>
<!--Optional:-->
<tes:FormaPago>01</tes:FormaPago>
<tes:LugarExpedicion>72000</tes:LugarExpedicion>
<!--Optional:-->
<tes:MetodoPago>PUE</tes:MetodoPago>
<!--Optional:-->
<tes:Moneda>MXN</tes:Moneda>
<!--Optional:-->
<!--Optional:-->
<!--Optional:-->
<tes:Referencia>1234</tes:Referencia>
<!--Optional:-->
<tes:SubTotal>0.11</tes:SubTotal>
<!--Optional:-->
<tes:Total>0.11</tes:Total>
</tem:ticket>
</tem:GenerarTicket>
</soapenv:Body>
</soapenv:Envelope>
然后我可以提交请求,它按预期工作。如果想用 Postman 试试这个,我可以编写 PHP 代码。
我将 POST 发送到https://app.foliosdigitalespac.com/CR33Test/ConexionRemota.svc?function_name=GenerarTicket,其中 Content-Type 标头设置为 text/xml,上述 XML 作为原始 XML 正文。当我单击提交时,我收到以下错误。
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">a:ActionNotSupported</faultcode>
<faultstring xml:lang="es-MX">The message with Action 'GenerarTicket' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).</faultstring>
</s:Fault>
</s:Body>
</s:Envelope>
显然我做得不好,但无法弄清楚它是什么。WDSL 开发人员告诉我,我可以发送带有正确信息的 POST 并获得响应。请问有什么帮助吗?
解决方案
我弄清楚发生了什么事。正确的 URL 是https://app.foliosdigitalespac.com/CR33Test/ConexionRemota.svc。
然后必须将 SOAPAction 标头设置为正确的 Action。根据文档,Action 是http://tempuri.org/IConexionRemota/GenerarTicket。我只使用作为操作的 GenerarTicket。
由于我想使用 PHP,因此相应的代码是
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://app.foliosdigitalespac.com/CR33Test/ConexionRemota.svc",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>"<soapenv:Envelope\n xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n xmlns:tem=\"http://tempuri.org/\"\n xmlns:tes=\"http://schemas.datacontract.org/2004/07/TES.V33.CFDI.Negocios\">\n <soapenv:Header/>\n <soapenv:Body>\n <tem:GenerarTicket>\n <!--Optional:-->\n <tem:credenciales>\n <!--Optional:-->\n <tes:Cuenta>TES030201001</tes:Cuenta>\n <!--Optional:-->\n <tes:Password>TES030201001j+2020</tes:Password>\n <!--Optional:-->\n <tes:Usuario>TES030201001</tes:Usuario>\n </tem:credenciales>\n <!--Optional:-->\n <tem:ticket>\n <!--Optional:-->\n <tes:ClaveCFDI>FAC</tes:ClaveCFDI>\n <!--Optional:-->\n <tes:Conceptos>\n <!--Zero or more repetitions:-->\n <tes:ConceptoR>\n <!--Optional:-->\n <tes:Cantidad>2</tes:Cantidad>\n <!--Optional:-->\n <tes:ClaveProdServ>84111506</tes:ClaveProdServ>\n <!--Optional:-->\n <tes:ClaveUnidad>C81</tes:ClaveUnidad>\n <!--Optional:-->\n <!--Optional:-->\n <tes:Descripcion>Producto 1</tes:Descripcion>\n <!--Optional:-->\n <tes:Importe>0.09</tes:Importe>\n <!--Optional:-->\n <tes:NoIdentificacion>1234567890</tes:NoIdentificacion>\n <!--Optional:-->\n <tes:Unidad>ACT</tes:Unidad>\n <!--Optional:-->\n <tes:ValorUnitario>0.045</tes:ValorUnitario>\n <!--Optional:-->\n \n </tes:ConceptoR>\n <tes:ConceptoR>\n <!--Optional:-->\n <tes:Cantidad>5</tes:Cantidad>\n <!--Optional:-->\n <tes:ClaveProdServ>84111506</tes:ClaveProdServ>\n <!--Optional:-->\n <tes:ClaveUnidad>C81</tes:ClaveUnidad>\n <!--Optional:-->\n <tes:Descripcion>Producto 2</tes:Descripcion>\n <!--Optional:-->\n <tes:Importe>0.02</tes:Importe>\n <!--Optional:-->\n <tes:NoIdentificacion>001</tes:NoIdentificacion>\n <!--Optional:-->\n <tes:Unidad>ACT</tes:Unidad>\n <!--Optional:-->\n <tes:ValorUnitario>0.004</tes:ValorUnitario>\n <!--Optional:-->\n \n </tes:ConceptoR>\n </tes:Conceptos>\n <!--Optional:-->\n <tes:CondicionesDePago>Condiciones De Pago</tes:CondicionesDePago>\n <!--Optional:-->\n <!--Optional:-->\n <tes:Emisor>\n <!--Optional:-->\n <tes:Nombre>Nombre del Emisor</tes:Nombre>\n <!--Optional:-->\n <tes:RegimenFiscal>601</tes:RegimenFiscal>\n </tes:Emisor>\n <!--Optional:-->\n <tes:FormaPago>01</tes:FormaPago>\n <tes:LugarExpedicion>72000</tes:LugarExpedicion>\n <!--Optional:-->\n <tes:MetodoPago>PUE</tes:MetodoPago>\n <!--Optional:-->\n <tes:Moneda>MXN</tes:Moneda>\n <!--Optional:-->\n <!--Optional:-->\n <!--Optional:-->\n <tes:Referencia>1234</tes:Referencia>\n <!--Optional:-->\n <tes:SubTotal>0.11</tes:SubTotal>\n <!--Optional:-->\n <tes:Total>0.11</tes:Total>\n </tem:ticket>\n </tem:GenerarTicket>\n </soapenv:Body>\n</soapenv:Envelope>",
CURLOPT_HTTPHEADER => array(
"Content-Type: text/xml",
"SOAPAction: http://tempuri.org/IConexionRemota/GenerarTicket"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
推荐阅读
- python-3.x - PyTorch:DecoderRNN:RuntimeError:输入必须有 3 维,得到 2
- html - 边距在 CSS 中不起作用
- android - 如何在 Parse Server Android 上运行计划作业/脚本
- java - ScheduledExecutorService 用于在异常后仍然存在的任务
- javascript - AngularJS Material Datepicker 更改格式
- python - 替换 JSON 文件中的方括号和逗号
- python - 将 Numpy 数组转换为 datetime.date pandas DataFrame
- visual-studio-code - 如何在另存为对话框中添加新的文件类型过滤器
- c - mac的多点触控代码
- scala - 将异常结果转换为迭代器