使用 Visual Studio 2008 制作 SOAP 代理/客户端时遇到问题

发布于 2024-12-17 17:02:27 字数 2998 浏览 0 评论 0原文

我有以下 Web 服务端点地址:

https://*.*.*/XISOAPAdapter/MessageServlet?channel=:TrackTrace:DTHZCOMSD_PI_TRACKTRACE_TRANSP

这些是我正在执行的步骤。

  • 在我的项目中,我转到参考资料 ->添加服务参考。
  • 在地址字段中,我输入上面的地址。
  • VS 说:“VS 检测到站点的安全证书有问题”
  • 我确认了此异常。
  • VS 表示该服务需要用户名和密码,并要求提供发现凭据。
  • 输入提供的用户名/密码组合。
  • 确认。
  • 得到这个:

HTML 文档不包含 Web 服务发现信息。 元数据包含无法解析的引用: 'https://..*/XISOAPAdapter/MessageServlet?channel=:TrackTrace:DTHZCOMSD_PI_TRACKTRACE_TRANSP'。 HTTP 请求未经客户端身份验证方案授权 '匿名的'。从服务器收到的身份验证标头是 '基本领域=“XISOAPApps”'。远程服务器返回错误:(401) 未经授权。如果当前解决方案中定义了该服务,请尝试 构建解决方案并再次添加服务引用。

如果不添加服务参考,我将转到参考 ->添加服务参考->高级->添加 Web 引用并输入上面的地址,系统将要求我接受证书并再次进行身份验证。确认后我会得到一个网页:

消息 Servlet 处于“状态正常”状态信息:Servlet com.sap.aii.af.mp.soap.web.MessageServlet(版本 $Id: //tc/xi/NW04S_18_REL/src/_adapters/_soap/java/com/sap/aii/af/mp/soap/web/MessageServlet.java#1 $) 绑定到 /MessageServlet 类名 ModuleProcessor: null localModuleProcessorLookupName 的查找名称: localejbs/ModuleProcessorBean 查找名称 RemoteModuleProcessorLookupName: null ModuleProcessorClass 不 实例化的 ModuleProcessorLocal 是 的实例 com.sap.aii.af.mp.processor.ModuleProcessorLocalLocalObjectImpl0_0 ModuleProcessorRemote 未实例化

且文本如下:

HTML 文档不包含 Web 服务发现信息

可能出现什么问题的任何提示吗?

编辑1:我可以从 SOAPSonar (使用提供的 wsdl 文件)设置基本身份验证调用该服务。如果我使用相同的 WSDL 通过 svcutils 生成代理,则生成的代码:

var serviceClient = new DTHZCOMSD_PI_TRACKTRACE_TRANSPClient();
serviceClient.Open();
ZCOMSD_PI_TRACKTRACE_TRANSPResponse response;
response = serviceClient.DTHZCOMSD_PI_TRACKTRACE_TRANSP(request) 

失败并出现以下错误:

{"根据验证,远程证书无效 程序。”} 底层连接已关闭:无法建立 SSL/TLS 安全通道的信任关系。

(证书已导入Windows) 我怎样才能绕过它? 如何添加用户名/密码以对 svcutil 生成的代码进行简单身份验证?

EDIT2:

我能够通过将 wsdl 文档直接传递到 VS(而不是传递服务 URL)来添加服务引用。在认证和授权方面遇到一些问题。

凭证问题很快就得到了解决: code:

service.ClientCredentials.Windows.ClientCredential = new NetworkCredential("user", "pass");  
service.ClientCredentials.UserName.UserName = "user";
service.ClientCredentials.UserName.Password = "pass"; 

和 app.config

<binding>
...
<transport clientCredentialType="Basic" proxyCredentialType="None"
                realm="" />

<message clientCredentialType="UserName" algorithmSuite="Default" />

...
</binding>

认证花了一点时间。 我尝试更改单个服务的认证模式,但没有成功。
知道为什么吗?

service.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;

不幸的是,目前绕过它的唯一方法是通过这种方式信任所有证书:

System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true); 

仍在寻找更改单个服务的认证模式的方法。

I have the following web-service endpoint address:

https://*.*.*/XISOAPAdapter/MessageServlet?channel=:TrackTrace:DTHZCOMSD_PI_TRACKTRACE_TRANSP

These are the steps I'm performing.

  • In my project I go to References -> Add Service Reference.
  • In Address field I enter the address above.
  • VS says: "VS has detected a problem with the site's security certificate"
  • I confirm this exception.
  • VS says that the service requires a username and password and asks for a Discovery Credential.
  • Entering the username/password combination that was provided.
  • Confirming.
  • Getting this:

The HTML document does not contain Web service discovery information.
Metadata contains a reference that cannot be resolved:
'https://..*/XISOAPAdapter/MessageServlet?channel=:TrackTrace:DTHZCOMSD_PI_TRACKTRACE_TRANSP'.
The HTTP request is unauthorized with client authentication scheme
'Anonymous'. The authentication header received from the server was
'Basic realm="XISOAPApps"'. The remote server returned an error: (401)
Unauthorized. If the service is defined in the current solution, try
building the solution and adding the service reference again.

If instead of adding a Service Reference I'll go References -> Add Service Reference -> Advanced -> Add Web Reference and enter the address above, I will be asked to accept the certificate and authenticate again. After confirming I will get a webpage:

Message Servlet is in Status OK Status information: Servlet
com.sap.aii.af.mp.soap.web.MessageServlet (Version $Id:
//tc/xi/NW04S_18_REL/src/_adapters/_soap/java/com/sap/aii/af/mp/soap/web/MessageServlet.java#1
$) bound to /MessageServlet Classname ModuleProcessor: null
Lookupname for localModuleProcessorLookupName:
localejbs/ModuleProcessorBean Lookupname for
remoteModuleProcessorLookupName: null ModuleProcessorClass not
instantiated ModuleProcessorLocal is Instance of
com.sap.aii.af.mp.processor.ModuleProcessorLocalLocalObjectImpl0_0
ModuleProcessorRemote not instantiated

and the following text:

The HTML document does not contain Web service discovery information

Any hints on what could be wrong?

EDIT 1: I can call the service from SOAPSonar (using a wsdl file provided) setting Basic Authentication. If I use the same WSDL to generate a proxy with svcutils the resulting code:

var serviceClient = new DTHZCOMSD_PI_TRACKTRACE_TRANSPClient();
serviceClient.Open();
ZCOMSD_PI_TRACKTRACE_TRANSPResponse response;
response = serviceClient.DTHZCOMSD_PI_TRACKTRACE_TRANSP(request) 

fails with the following errors:

{"The remote certificate is invalid according to the validation
procedure."} The underlying connection was closed: Could not establish
trust relationship for the SSL/TLS secure channel.

(The certificate was imported into Windows)
How can I bypass it ?
And how can I add username/password for simple authentication for the code that was generated by svcutil?

EDIT2:

I was able to add a Service Reference by passing a wsdl document directly to VS (instead of passing the service URL). Got a few problems with certification and authorization.

The credentials problem was solved pretty fast:
code:

service.ClientCredentials.Windows.ClientCredential = new NetworkCredential("user", "pass");  
service.ClientCredentials.UserName.UserName = "user";
service.ClientCredentials.UserName.Password = "pass"; 

and app.config

<binding>
...
<transport clientCredentialType="Basic" proxyCredentialType="None"
                realm="" />

<message clientCredentialType="UserName" algorithmSuite="Default" />

...
</binding>

Certification took a bit longer.
I tried to change the certification mode for a single service, but it didn't work.
Any idea why?

service.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;

Unfortunately, the only way to bypass it for now is to trust all certificates this way:

System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true); 

Still looking for a way to change the certification mode for a single service.

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

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

发布评论

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