gpt4 book ai didi

wcf - Metro 客户端在使用 wsHttpBinding 调用 WCF 网络服务器时挂起

转载 作者:行者123 更新时间:2023-12-04 20:53:51 27 4
gpt4 key购买 nike

我使用 Metro 1.2 以这种方式生成了一个带有本地 wsdl 的 webservice 客户端:

./wsimport.sh -extension -verbose -wsdllocation service.wsdl -s src -d target service.wsdl -Xendorsed

wsdl 使用 SOAP 1.2wsHttpBinding 。它应该连接到使用 NTLM 作为身份验证方法的 WCF 服务器。

我创建了一个 Authenticator 来处理 NTLM 身份验证:
public class NtlmAuthenticator extends Authenticator
{
private String username = "";
private String password = "";

public NtlmAuthenticator(String username, String password) {
this.username = username;
this.password = password;
}

@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password.toCharArray());
}
}

我在调用每个 webservice 方法之前设置的:
@WebEndpoint(name = "WSHttpBinding_ICustomerService")
public ICustomerService getWSHttpBindingICustomerService() {
ICustomerService service =
super.getPort(new QName("http://xmlns.example.com/services/Customer",
"WSHttpBinding_ICustomerService"), ICustomerService.class);

NtlmAuthenticator auth = new NtlmAuthenticator(username, password);
Authenticator.setDefault(auth);

return service;
}

如果我使用了错误的用户名/密码,我会返回一个 401 Unauthorized,这很好,但是当我使用正确的用户名/密码时,调用会挂起,我永远不会得到响应!

请求看起来是这样的(用netcat捕获的,所以主机不同,没有https):
POST / HTTP/1.1
Content-type: application/soap+xml;charset="utf-8";action="http://xmlns.example.com/services/ICustomerService/GetCustomer"
Password: [password]
Authorization: Basic [auth]
Username: [username]
Accept: application/soap+xml, multipart/related, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
User-Agent: JAX-WS RI 2.1.7-b01-
Cache-Control: no-cache
Pragma: no-cache
Host: localhost:5500
Connection: keep-alive
Content-Length: 603

[xml follows]

我也尝试过 wget 1.12(听说 1.11 有 NTLM 问题),但它也从未产生响应,只是等待。
[...]
---request end---
[writing POST file customerRequest.xml ... done]
HTTP request sent, awaiting response...

我已经看到 others 之前有过这种行为,但我一直无法找出原因。任何人都可以对此有所了解吗? Linux 上的 JDK 1.6。

最佳答案

我发现我在生成的客户端代码中遗漏了一行启用 Addressing并将其传递给 getPort super 方法:

WebServiceFeature wsAddressing = new AddressingFeature(true);

ICustomerService service =
super.getPort(new QName("http://xmlns.example.com/services/Customer",
"WSHttpBinding_ICustomerService"), ICustomerService.class,
wsAddressing);

为什么地铁没有产生这个超出我的范围。该方法最终看起来像这样:
@WebEndpoint(name = "WSHttpBinding_ICustomerService")
public ICustomerService getWSHttpBindingICustomerService() {
WebServiceFeature wsAddressing = new AddressingFeature(true);

ICustomerService service =
super.getPort(new QName("http://xmlns.example.com/services/Customer",
"WSHttpBinding_ICustomerService"), ICustomerService.class,
wsAddressing);

NtlmAuthenticator auth = new NtlmAuthenticator(username, password);
Authenticator.setDefault(auth);

return service;
}

这反过来又向消息添加了一个 SOAP header :
<S:Header>
<To xmlns="http://www.w3.org/2005/08/addressing">https://services.example.com/CustomerService.svc</To>
<Action xmlns="http://www.w3.org/2005/08/addressing">http://xmlns.example.com/services/ICustomerService/GetCustomer</Action>
<ReplyTo xmlns="http://www.w3.org/2005/08/addressing">
<Address>http://www.w3.org/2005/08/addressing/anonymous</Address>
</ReplyTo>
<MessageID xmlns="http://www.w3.org/2005/08/addressing">uuid:d33c2888-abfa-474d-8729-95d2bcd17a96</MessageID>
</S:Header>

关于wcf - Metro 客户端在使用 wsHttpBinding 调用 WCF 网络服务器时挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7067637/

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