gpt4 book ai didi

java - 如何使用 BasicHttpBinding 和 BasicHttpSecurityMode.TransportWithCredential : 将 header 元素 "mustunderstand=0"设置到 SOAP 请求中

转载 作者:行者123 更新时间:2023-12-01 12:35:48 25 4
gpt4 key购买 nike

我正在使用带有 C# 的 .NET WCF 客户端来使用 Java WebService。当我向此 Web 服务发送请求时,封装的 WCF 客户端始终会放置元素 mustunderstand=1,即使使用实现 IClientMessageInspector 的自定义 MessageInspector 更改 header 也是如此IClientMessageInspector.BeforeSendRequest 方法中的元素。我猜想带有 BasicHttpSecurityMode.TrasportWithCredentials 的 BasicHttpBinding 总是将此元素放在请求的 header 中,忽略这些手动添加的 header 。

mustunderstand=1 header 元素在服务器端触发错误,并且该服务器超出了我们的控制范围。我想避免此 header 元素响应错误,请将 mustunderstand=1 的值更改为 mustunderstand=0

那么有什么技巧或技巧可以更改此 mustunderstand header 参数的值吗?

为了说明查看 FIDDLER 和 MessageInspector 跟踪的 REQUEST RAW、RESPONSE RAW。

请求原始数据:

POST "WSDLADDRESS" HTTP/1.1
MIME-Version: 1.0
Content-Type: multipart/related; type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:a0f5ee5b-4543-4aa9-85be-f7af4e8ea289+id=1";start-info="text/xml"
SOAPAction: "NAMEOFSOAPACTION"
Host: wwwh.cnj.jus.br
Content-Length: 5013
Expect: 100-continue
Accept-Encoding: gzip, deflate
Connection: Keep-Alive


--uuid:a0f5ee5b-4543-4aa9-85be-f7af4e8ea289+id=1
Content-ID: <http://tempuri.org/0>
Content-Transfer-Encoding: 8bit
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><s:Header><o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><u:Timestamp u:Id="_0"><u:Created>2014-09-01T14:06:59.225Z</u:Created><u:Expires>2014-09-01T14:11:59.225Z</u:Expires></u:Timestamp><o:BinarySecurityToken u:Id="uuid-562fb884-7bc7-4323-ac5e-29556b6c85aa-1" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"><xop:Include href="cid:http://tempuri.org/1/635451664301180633" xmlns:xop="http://www.w3.org/2004/08/xop/include"/></o:BinarySecurityToken><Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><Reference URI="#_0"><Transforms><Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><DigestValue>cIusnusCxdoCXm4BhihEXGC3MMw=</DigestValue></Reference></SignedInfo><SignatureValue>LC4d/YhYHKRocSmORNWC0oQzCrLkG00b1iSZxDL/TflCQ3pJa7qYxPY07oUR4Ngull22V9fn1QBl1NOoRii8JjK1XjJYW8XQ+pVVMnf6l2guYJjYmTp7y2p+UT3JAQrlJIYj2sAu38obsthemAtec/miY3K5anq/AYTIr1slkyDJsm23w4boq3RfTD9mbU+U+KSF71vFi5RK8ryX/i9FEsayp0N0Hpw5SP/lOEI2IkOmw4Mpg2slCLIcQWJMuP+g6aZgLviVTQBgUE3ETwdVQIogmHChfeAtHCD9Knid4Bndyldq0WoTWzGJZ9PL8PXZJIMzQtYLP+XG/emAb3Bp1g==</SignatureValue><KeyInfo><o:SecurityTokenReference><o:Reference ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" URI="#uuid-562fb884-7bc7-4323-ac5e-29556b6c85aa-1"/></o:SecurityTokenReference></KeyInfo></Signature></o:Security></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><consultarAvisosPendentes xmlns="http://www.cnj.jus.br/servico-intercomunicacao-2.2/"><idRepresentado xmlns="http://www.cnj.jus.br/tipos-servico-intercomunicacao-2.2"/><idConsultante xmlns="http://www.cnj.jus.br/tipos-servico-intercomunicacao-2.2"/><senhaConsultante xmlns="http://www.cnj.jus.br/tipos-servico-intercomunicacao-2.2"/><dataReferencia xmlns="http://www.cnj.jus.br/tipos-servico-intercomunicacao-2.2">01/09/2014</dataReferencia></consultarAvisosPendentes></s:Body></s:Envelope>
--uuid:a0f5ee5b-4543-4aa9-85be-f7af4e8ea289+id=1
Content-ID: <http://tempuri.org/1/635451664301180633>
Content-Transfer-Encoding: binary
Content-Type: application/octet-stream

0��0�ΠZN�(K��20� ���j0
*�H��

�0o1
0 UBR10U

(...certificate data...)
�����2o�w�|� ������#�d�e�Z9�KI��l����ɵ�v���Ka�����q�晚=]�ht���l�T�x�7<IS�d@��T�d՘�30��T;l��3�ЉJ�K(���tP��oU�結$�"�4�4�x����p����\ނl�/0鈾yN�
iu����y�-��Z�J���򉜵<���P�5�i}��;&u�t�DH�oc��@D�Mf}ue��I\Mk�鐈�^gF�_T'䌁U��ёN����qy;�P_����7F�dz��qLL
�`g>
�C�﨨�%��a;���z�����n�$��O�Vz4��ѡ�D��V�3�X�!m��y���E��E��};��)�Jlv��+��6���RK
�����w��k���@�XIB����?��qC��ġ��6n{n��s�̔-���
|�����@+�Jv�r�%̓p�� *gy4��(�hA�⮫*m��bU��c�>����}��h�����Y�(
--uuid:a0f5ee5b-4543-4aa9-85be-f7af4e8ea289+id=1--

原始响应:

HTTP/1.1 500 Internal Server Error
Date: Mon, 01 Sep 2014 14:07:10 GMT
X-Powered-By: Servlet 2.5; JBoss-5.0/JBossWeb-2.1
Content-Type: text/xml;charset=UTF-8
Vary: Accept-Encoding
Connection: close
Content-Length: 480

<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><env:Header></env:Header><env:Body><env:Fault xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><faultcode xmlns:codeNS='http://schemas.xmlsoap.org/soap/envelope/'>codeNS:MustUnderstand</faultcode><faultstring>Unprocessed &apos;mustUnderstand&apos; header element: {http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}Security</faultstring></env:Fault></env:Body></env:Envelope>

消息检查器:

    class MessageInspector : IClientMessageInspector
{
object IClientMessageInspector.BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
{
request.Headers.Add(MessageHeader.CreateHeader
(request.Headers[0].Name,
request.Headers[0].Namespace,
string.Empty,
false,
request.Headers[0].Actor,
request.Headers[0].Relay)
);

request.Headers.RemoveAt(0);

return Convert.DBNull;
}

public void AfterReceiveReply(ref Message reply, object correlationState)
{
}
}

请求 header 之前:

Request Headers Before

请求 header 之后:

Request Headers After

最佳答案

好吧...这需要一些工作才能完成。我不知道您是否熟悉绑定(bind)内的 channel 堆栈,但基本上,消息将流经 various operations在 WCF 中,每一个都会以某种方式转换消息。

This answer ,并且您需要使用自定义消息编码器,因为在您修改 header 以删除 mustUnderstand 之后,WCF 正在应用“正确” header (正如它所看到的,由于指定的绑定(bind))属性。

这是一个相当复杂的区域,我必须使用它来获取 WCF 生成的 SOAP header ,以符合 WSE 3.0 用于创建的内容,并在安全 header 中使用二进制 token ;但经过一些尝试和错误,它是一个非常强大的功能。

关于java - 如何使用 BasicHttpBinding 和 BasicHttpSecurityMode.TransportWithCredential : 将 header 元素 "mustunderstand=0"设置到 SOAP 请求中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25608557/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com