使用WCF,VB.NET和VS2015使用BinarySecurityToken来使用SOAP Web服务

时间:2015-12-22 19:59:00

标签: vb.net web-services wcf soap

最好的问候费拉斯

我正在尝试使用VB.NET和Framework 4.5访问接收签名XML作为参数的Web服务方法。碰巧Web Service使用带有BinarySecurityToken模式的WS-Authentication,我设法从SOAP UI生成一个resquest,它工作正常,这是请求的XML:

                    使用Base64Binary令牌                                                                                                                                                                                                                                                           使用Base64Binary-的DigestValue                                          base64Binary的-的SignatureValue                                                                                                                                    这里是CDATA TAGS之间的XML数据                     

我一直在做很多研究,发现这可以通过WCF“轻松”完成,但是我可以很好地发现这个WCF绑定是如何工作的,以及我如何传递我的XML数据以便它可以被包装到SOAP信封的主体与propper安全元素。

我已经检查过的代码对我来说看起来非常复杂,因为我只能使用基类,我可以弄清楚它来自哪里。我想生成代码来使用WS而不添加引用,而是使用http请求,就像这个人在这里做的那样:

http://www2.sys-con.com/ITSG/virtualcd/WebServices/archives/0208/thota/index.html

我很感激任何帮助,并提前感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

我没有意识到XML代码,所以,这里是SOAP消息XML代码<soapenv:Envelope xmlns:dgi="http://dgi.gub.uy" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header> <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"> <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-B1784C762113654DB514508130204461">base64binary-Token</wsse:BinarySecurityToken> <ds:Signature Id="SIG-B1784C762113654DB514508130206685" 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="dgi soapenv" 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-B1784C762113654DB514508130206654"> <ds:Transforms> <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"> <ec:InclusiveNamespaces PrefixList="dgi" 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>base64binary-DigestValue</ds:DigestValue> </ds:Reference> </ds:SignedInfo> <ds:SignatureValue>base64Binary-SignatureValue</ds:SignatureValue> <ds:KeyInfo Id="KI-B1784C762113654DB514508130206312"> <wsse:SecurityTokenReference wsu:Id="STR-B1784C762113654DB514508130206463"> <wsse:Reference URI="#X509-B1784C762113654DB514508130204461" 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> </soapenv:Header> <soapenv:Body wsu:Id="id-B1784C762113654DB514508130206654" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> <dgi:WS_eFactura.EFACRECEPCIONSOBRE> <dgi:Datain> <dgi:xmlData>HERE GOES XML DATA BETWEEN CDATA TAGS</dgi:xmlData> </dgi:Datain> </dgi:WS_eFactura.EFACRECEPCIONSOBRE> </soapenv:Body> </soapenv:Envelope>