gpt4 book ai didi

java - 调用 java web 服务 "REST"需要使用来自 .Net C# 的用户名和密码以及证书进行身份验证

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

好吧,这是我的故事,我有来自第三方的 java web 服务,我必须使用 C# 连接到该服务该服务需要以下内容

  • 使用用户名和密码进行身份验证。
  • 从客户端“keystore.jks”(Java keystore 文件)发送带有密码的证书。

我的问题是该服务的供应商没有提供该服务的 WSDL 链接,并且证书文件是 java keystore 我在这个问题上挂了 2 天,在网络上搜索这个但没有运气

因此:我使用 SOAPUI 软件来调用此服务,并且运行良好

我想要的是,是否可以在不向供应商请求 WSDL 的情况下使用此服务?如果是的话怎么办?

任何帮助我们都将不胜感激。提前致谢。

编辑:服务 url,如 https://10.111.10.12/ropnrs/Person?crn=1234567并且无法访问抛出网络浏览器返回 403 禁止

最佳答案

您可以通过使用 WebClient 发送 POST 请求并使用 SOAP XML 消息填充请求正文来使用没有 WSDL 的 Web 服务。

您可能需要添加其他 HTTP header 。首先用 SOAP UI 做一个请求,然后用 fiddler 查看请求。然后使用WebClient发送请求。代码应该类似于:

using (var client = new WebClient())
{
// this is the string containing the soap message
var data = File.ReadAllText("request.xml");
// HTTP header. set it to the identical working example you monitor with fiddler from SOAP UI
client.Headers.Add("Content-Type", "text/xml;charset=utf-8");
// HTTP header. set it to the identical working example you monitor with fiddler from SOAP UI
client.Headers.Add("SOAPAction", "\"http://tempuri.org/ITestWcfService/TestMethod\"");
// add/modify additional HTTP headers to make the request identical with what you get when calling from SOAP UI on a successful call
try
{
var response = client.UploadString("http://localhost:8080/TestWcfService", data);
}
catch (Exception e)
{
// handle exception
}
}

我不确定证书,但也许你也可以以某种方式将其设置到网络客户端。不幸的是,我对客户端证书了解不多。但如果你能在评论中解释一下,我也许可以帮助你。如果您设法使用此解决方案使其正常工作,也请在此处发布您处理证书问题的额外工作。

WebClient 是 System.dll 程序集中 System.Net 的类。

关于java - 调用 java web 服务 "REST"需要使用来自 .Net C# 的用户名和密码以及证书进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27957612/

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