【发布时间】:2018-07-15 11:29:32
【问题描述】:
我正在将 .net 4.6.2 代码移植到调用 SOAP 服务的 .net Core 项目。在新代码中,我使用的是 C#(由于某些配置原因,我现在不记得为什么了)。
但我遇到了以下异常。
接收到https://someurl.com/ws/Thing.pub.ws:Something 的 HTTP 响应时出错。 这可能是由于服务端点绑定未使用 HTTP 协议。 这也可能是由于服务器中止了 HTTP 请求上下文(可能是由于服务关闭)。 有关详细信息,请参阅服务器日志。
抛出它的代码是
try
{
var binding = new BasicHttpsBinding(BasicHttpsSecurityMode.Transport);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
var endpoint = new EndpointAddress(new Uri("https://someurl.com/ws/TheEndpoint.pub.ws:AService"));
var thing= new TheEndpoint.AService_PortTypeClient(binding, endpoint);
thing.ClientCredentials.UserName.UserName = "usrn";
thing.ClientCredentials.UserName.Password = "passw";
var response = await thing.getSomethingAsync("id").ConfigureAwait(false);
}
finally
{
await thing.CloseAsync().ConfigureAwait(false);
}
基于调用服务的旧配置是这样的,我错过了什么?
<bindings>
<basicHttpsBinding>
<binding name="TheEndpoint_pub_ws_AService_Binder" closeTimeout="00:02:00"
openTimeout="00:02:00" receiveTimeout="00:03:00" sendTimeout="00:03:00">
<security mode="Transport">
<transport clientCredentialType="Basic" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpsBinding>
</bindings>
<client>
<endpoint address="https://someurl.com/ws/Thing.pub.ws:AService"
binding="basicHttpsBinding" bindingConfiguration="TheEndpoint_pub_ws_AService_Binder"
contract="TheEndpoint.AService_PortType" name="TheEndpoint_pub_ws_AService_Port" />
</client>
我只是无法在网上找到很多关于此的信息。希望你能帮助我。
更新 根据 Sixto Saez 的建议,我得到了端点来揭示它的错误,它是
使用客户端身份验证方案“基本”未授权 HTTP 请求。从服务器收到的身份验证标头是 'Basic realm="Integration Server", encoding="UTF-8"'。
如果成功,我会尝试找出该怎么做并在此处发布结果。
更新 2
好的,现在我尝试使用这里的代码转移到新语法
ChannelFactory<IAService> factory = null;
IAService serviceProxy = null;
Binding binding = null;
try
{
binding = new BasicHttpsBinding(BasicHttpsSecurityMode.Transport);
factory = new ChannelFactory<IAService>(binding, new EndpointAddress(new Uri("https://someurl.com/ws/TheEndpoint.pub.ws:AService")));
factory.Credentials.UserName.UserName = "usrn";
factory.Credentials.UserName.Password = "passw";
serviceProxy = factory.CreateChannel();
var result = await serviceProxy.getSomethingAsync("id").ConfigureAwait(false);
factory.Close();
((ICommunicationObject)serviceProxy).Close();
}
catch (MessageSecurityException ex)
{
//error caught here
throw;
}
但我仍然遇到相同(略有不同)的错误。它现在有 'Anonymous' 而不是 'Basic' 并且现在缺少最后的 ", encoding="UTF-8"。
HTTP 请求未经客户端身份验证方案“匿名”授权。从服务器收到的身份验证标头是“Basic realm="Integration Server"”。
是我的问题还是服务器的问题?
显然,我现在的 SOAP“技能”非常缺乏,但我几乎尝试了所有我能想到的使用这种新方法的配置组合,但没有运气。希望有人能指出我正确的方向。
【问题讨论】:
-
该错误似乎是服务器端问题。在客户端,不清楚
Thing.Authorization_PortTypeClient类是否封装了ChannelFactory的创建和Channel实例的生成。请参阅此test code,了解如何在 .NET Core 中创建和调用 WCF 客户端。这个GitHub repo for WCF client libraries 可能包含您正在寻找的文件,文档方面。 -
谢谢@SixtoSaez。我更新了问题。但现在我得到另一个错误,我只是无法找出真正的意思。我已经联系了服务器人员,以检查他们是否有问题,但是如果您有任何见解,我将不胜感激。