问题描述
我们已经在多台服务器上运行了相同的代码,并且只有在生产服务器上,身份验证才会导致:
HTTP请求未经客户端身份验证方案“基本”授权。从服务器收到的身份验证标头是“ Basic realm =“ NuSOAP server””。
带有未提供数据提供者信息的当前绑定设置:
private ***PortType.***TypeClient LogIn() { BasicHttpBinding myBinding = new BasicHttpBinding(); myBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; myBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName; myBinding.MaxBufferSize = int.MaxValue; myBinding.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max; myBinding.MaxReceivedMessageSize = int.MaxValue; myBinding.AllowCookies = true; myBinding.CloseTimeout = new TimeSpan(0,5,0); myBinding.OpenTimeout = new TimeSpan(0,0); myBinding.ReceiveTimeout = new TimeSpan(0,0); myBinding.SendTimeout = new TimeSpan(0,0); var portType = new ***TypeClient(myBinding,new EndpointAddress(***)); portType.ClientCredentials.UserName.UserName = _login; portType.ClientCredentials.UserName.Password = _password; portType.Endpoint.EndpointBehaviors.Add(new FaultFormatingBehavior()); return portType; } internal class FaultFormatingBehavior : IEndpointBehavior { public void Validate(ServiceEndpoint endpoint) { } public void AddBindingParameters(ServiceEndpoint endpoint,BindingParameterCollection bindingParameters) { } public void ApplydispatchBehavior(ServiceEndpoint endpoint,Endpointdispatcher endpointdispatcher) { } public void ApplyClientBehavior(ServiceEndpoint endpoint,ClientRuntime clientRuntime) { clientRuntime.ClientMessageInspectors.Add(new FaultMessageInspector()); } } public class FaultMessageInspector : IClientMessageInspector { public object BeforeSendRequest(ref Message request,IClientChannel channel) { return null; } public void AfterReceiveReply(ref Message reply,object correlationState) { if (reply.IsFault) { var erratr = reply.GetBody<XElement>(); var error = erratr.Elements().Where(p => p.Name == "faultstring").FirstOrDefault()?.Value; Message newFaultMessage = Message.CreateMessage(reply.Version,error,error); reply = newFaultMessage; throw new Exception("Remote service response returned error: " + error); } } }
@H_502_9@由于必须保持兼容性,因此代码是用netcoreapp2.1编写的。 我正在寻找代码中潜在的错误,或者可能会导致这种行为的服务器设置建议。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)