如何编程或在WCF配置中添加标头值

发布于 2025-02-12 17:40:04 字数 3793 浏览 0 评论 0原文

我在WCF服务方面有问题。我是WCF端的客户端,我想为WCF请求添加一些标题值,最终请求是:

<soap:Envelope
    xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
    xmlns:tem="http://tempuri.org/">
    <soap:Header
        xmlns:wsa="http://www.w3.org/2005/08/addressing">
        <wsse:Security
            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">
            <wsu:Timestamp wsu:Id="TS-6F2DD34E8610CE8C601656677431004366">
                <wsu:Created>2022-07-01T12:10:31.004Z</wsu:Created>
                <wsu:Expires>2022-07-01T12:15:31.004Z</wsu:Expires>
            </wsu:Timestamp>
            <wsse:BinarySecurityToken EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" wsu:Id="X509-6F2DD34E8610CE8C601656677430928361">certificate body</wsse:BinarySecurityToken>
            <ds:Signature Id="SIG-6F2DD34E8610CE8C601656677430937365"
                xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
                <ds:SignedInfo>
                    <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
                        <ec:InclusiveNamespaces PrefixList="wsa soap tem"
                            xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/>
                        </ds:CanonicalizationMethod>
                        <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
                        <ds:Reference URI="#id-6F2DD34E8610CE8C601656677430929364">
                            <ds:Transforms>
                                <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
                                    <ec:InclusiveNamespaces PrefixList="soap tem"
                                        xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/>
                                    </ds:Transform>
                                </ds:Transforms>
                                <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
                                <ds:DigestValue>fvOkKSb73QCylskA10SCp2cCwC0=</ds:DigestValue>
                            </ds:Reference>
                        </ds:SignedInfo>
                        <ds:SignatureValue>signature value</ds:SignatureValue>
                        <ds:KeyInfo Id="KI-6F2DD34E8610CE8C601656677430928362">
                            <wsse:SecurityTokenReference wsu:Id="STR-6F2DD34E8610CE8C601656677430928363">
                                <wsse:Reference URI="#X509-6F2DD34E8610CE8C601656677430928361" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
                            </wsse:SecurityTokenReference>
                        </ds:KeyInfo>
                    </ds:Signature>
                </wsse:Security>
                <wsa:Action>http://tempuri.org/IWSTRM01/CheckDeal</wsa:Action>
                <wsa:To wsu:Id="id-6F2DD34E8610CE8C601656677430929364"
                    xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">https://paysrvweb.otpbank.com.ua/WSTRM/WSTRM01.svc
                </wsa:To>
            </soap:Header>
        </soap:Envelope>

我尝试使用WSHTTPBINDING和BASICHTTPBINDING来执行此操作,但这是不起作用的。 如何将所有这些标题添加到我的请求中?

I have a problem with WCF service. I am a client in wcf side and i want to add some header values to my wcf request, final request, is:

<soap:Envelope
    xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
    xmlns:tem="http://tempuri.org/">
    <soap:Header
        xmlns:wsa="http://www.w3.org/2005/08/addressing">
        <wsse:Security
            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">
            <wsu:Timestamp wsu:Id="TS-6F2DD34E8610CE8C601656677431004366">
                <wsu:Created>2022-07-01T12:10:31.004Z</wsu:Created>
                <wsu:Expires>2022-07-01T12:15:31.004Z</wsu:Expires>
            </wsu:Timestamp>
            <wsse:BinarySecurityToken EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" wsu:Id="X509-6F2DD34E8610CE8C601656677430928361">certificate body</wsse:BinarySecurityToken>
            <ds:Signature Id="SIG-6F2DD34E8610CE8C601656677430937365"
                xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
                <ds:SignedInfo>
                    <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
                        <ec:InclusiveNamespaces PrefixList="wsa soap tem"
                            xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/>
                        </ds:CanonicalizationMethod>
                        <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
                        <ds:Reference URI="#id-6F2DD34E8610CE8C601656677430929364">
                            <ds:Transforms>
                                <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
                                    <ec:InclusiveNamespaces PrefixList="soap tem"
                                        xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/>
                                    </ds:Transform>
                                </ds:Transforms>
                                <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
                                <ds:DigestValue>fvOkKSb73QCylskA10SCp2cCwC0=</ds:DigestValue>
                            </ds:Reference>
                        </ds:SignedInfo>
                        <ds:SignatureValue>signature value</ds:SignatureValue>
                        <ds:KeyInfo Id="KI-6F2DD34E8610CE8C601656677430928362">
                            <wsse:SecurityTokenReference wsu:Id="STR-6F2DD34E8610CE8C601656677430928363">
                                <wsse:Reference URI="#X509-6F2DD34E8610CE8C601656677430928361" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
                            </wsse:SecurityTokenReference>
                        </ds:KeyInfo>
                    </ds:Signature>
                </wsse:Security>
                <wsa:Action>http://tempuri.org/IWSTRM01/CheckDeal</wsa:Action>
                <wsa:To wsu:Id="id-6F2DD34E8610CE8C601656677430929364"
                    xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">https://paysrvweb.otpbank.com.ua/WSTRM/WSTRM01.svc
                </wsa:To>
            </soap:Header>
        </soap:Envelope>

I tried to do this with wsHttpBinding and BasicHttpBinding but it's not worked.
How can i add all this headers to my request ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文