[英]calling java web service “REST” that require auth with username & password and certificate from .Net C#
好的,这是我的故事,我有来自第三方的Java Web服务,我必须使用C#连接到该服务,该服务需要以下内容
我的问题是该服务的供应商未提供该服务的WSDL链接,并且证书文件为Java密钥库,我在此挂了两天,并在网上搜索失败
因此:我使用SOAPUI软件来调用此服务,并且该服务运行良好
我想要的是,是否可以在不向供应商请求WSDL的情况下使用此服务? 如果是,怎么办?
任何帮助,不胜感激。 提前致谢。
编辑:服务网址,例如https://10.111.10.12/ropnrs/Person?crn=1234567并且它不可访问抛出Web浏览器禁止返回403
通过使用WebClient发送POST请求,并使用SOAP XML消息填充请求的主体,可以使用没有WSDL的Web服务。
您可能需要添加其他HTTP标头。 首先使用SOAP UI进行请求,然后使用提琴手查看该请求。 然后使用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
}
}
我不确定该证书,但也许您也可以将其设置为Web客户端。 不幸的是,我对客户证书了解不多。 但是,如果您可以在评论中解释我可能会为您提供帮助。 如果您设法使用此解决方案使其工作,请在此处发布您的其他工作来处理证书问题。
WebClient是System.Net程序集中System.Net中的类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.