从 .NET 调用 Java WS - Java 方式使用 Apache Rampart、.NET 等效项

发布于 2024-10-07 10:14:55 字数 904 浏览 7 评论 0原文

我们正在集成的供应商提供了一些 Web 服务功能...他们用 Java 开发了它,并且还为我们提供了一个示例客户端项目(用 Java 语言)来显示这些 Web 服务的消耗。我们实际上想用 .NET 实现 Web 服务的消费/接口,但我们无法弄清楚安全性应该如何工作。

在他们的 Java 客户端示例中,他们似乎正在使用名为“Apache Rampart”的东西。他们的代码看起来像这样:

public static void initSecurityPolicy(ServiceClient client) throws Exception 
{
    Options options = client.getOptions();
    options.setProperty(RampartMessageData.KEY_RAMPART_POLICY, 
        loadPolicy("policy.xml"));

    options.setUserName(USERID);
    options.setPassword(PASSWD);
    options.setTimeOutInMilliSeconds(READTIMEOUT);
    client.engageModule("rampart"); 
}

有人可以帮助我在 .NET 世界中找到我应该寻找的东西,以完成与此相同的事情吗?目前,在我的 .NET 项目中......我可以很好地使用他们的 WSDL,并且它生成的代理对象完全正常,但如果我尝试运行/调用任何函数,它会告诉我“缺少 SOAP 标头”,我相信这是安全的 -有关的。

他们还向我提供了policy.xml 文件。我是一名新手 .NET 程序员,我通常依赖 VStudio 生成的代理来处理任何与 WS 相关的编程,因此我不确定如何处理该 policy.xml 文件,也不知道如何执行与他们相同的操作在 .NET 世界中的上述代码中。

A vendor we're integrating with provides some web-service functions... They developed it in Java, and also gave us an example client project (in Java) that shows the consumption of those web-services. We actually want to implement the consumption/interface of the web-services with .NET, but we're not able to figure out how the security should work.

In their Java client example, they appear to be using something called "Apache Rampart". They have code within that looks like this:

public static void initSecurityPolicy(ServiceClient client) throws Exception 
{
    Options options = client.getOptions();
    options.setProperty(RampartMessageData.KEY_RAMPART_POLICY, 
        loadPolicy("policy.xml"));

    options.setUserName(USERID);
    options.setPassword(PASSWD);
    options.setTimeOutInMilliSeconds(READTIMEOUT);
    client.engageModule("rampart"); 
}

Could someone help me in what I should be looking for, in the .NET world, to do the equivalent of this? Currently, in my .NET project.. I can consume their WSDL fine, and it generates the proxy objects perfectly fine, but if I try to run/invoke any function, it tells me "missing SOAP header" and I believe it's security-related.

They also provide me the policy.xml file. I'm a novice .NET programmer and I usually rely on the proxies that VStudio generates to handle any WS-related programming, so I'm not sure what to do with that policy.xml file, nor do the equivalent of what they do in the code above in the .NET world.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

睡美人的小仙女 2024-10-14 10:14:55

如果您确实遇到困难,可以使用 IKVM 与他们的 Java 代码进行互操作。它基本上是一个托管在 .NET 中的 JVM。

If you get really stuck, you can use IKVM to interop with their Java code. Its basically a JVM hosted within .NET.

抱着落日 2024-10-14 10:14:55

您需要设置soap标头...类似这样:

<soap:Header>
   <wsse:Security soap: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">
      <wsse:UsernameToken wsu:Id="UsernameToken-E2E367EC446B10BDA2150463848593046">
         <wsse:Username>User</wsse:Username>
         <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">Pass</wsse:Password>
         <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">/rHCse9+oW6b71t1+J3GPA==</wsse:Nonce>
         <wsu:Created>2017-09-05T09:08:05.930Z</wsu:Created>
      </wsse:UsernameToken>
   </wsse:Security>
</soap:Header>

为此,您需要了解如何在.NET中设置UsernameToken以将安全凭证添加到SOAP消息

You need to set the soap header... something like this:

<soap:Header>
   <wsse:Security soap: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">
      <wsse:UsernameToken wsu:Id="UsernameToken-E2E367EC446B10BDA2150463848593046">
         <wsse:Username>User</wsse:Username>
         <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">Pass</wsse:Password>
         <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">/rHCse9+oW6b71t1+J3GPA==</wsse:Nonce>
         <wsu:Created>2017-09-05T09:08:05.930Z</wsu:Created>
      </wsse:UsernameToken>
   </wsse:Security>
</soap:Header>

For this, you need to find how set the UsernameToken in .NET to add the security credentials to a SOAP message

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文