C# .net core 3.1无法对远程服务进行身份验证

C# .net core 3.1无法对远程服务进行身份验证,c#,.net,web-services,.net-core,webservice-client,C#,.net,Web Services,.net Core,Webservice Client,问题就在这里。我正在将出站服务调用从Framework 4.7转换为Core 3.1。框架中的一切都可以完美工作,但无法在Core3.1中对其进行身份验证。我通过将远程服务添加到连接的服务中使用了它。WSDL在核心中构建了所有相同的类等。在任何人询问之前,我在框架和核心中使用相同的用户名和密码,并且它在框架中工作。我基本上是将代码直接从框架项目复制到核心项目,并进行了一些小的调整以使其能够编译 我试过几种变体,但都没有成功。我希望所有设置都在ConnectedService.json中,但我对如

问题就在这里。我正在将出站服务调用从Framework 4.7转换为Core 3.1。框架中的一切都可以完美工作,但无法在Core3.1中对其进行身份验证。我通过将远程服务添加到连接的服务中使用了它。WSDL在核心中构建了所有相同的类等。在任何人询问之前,我在框架和核心中使用相同的用户名和密码,并且它在框架中工作。我基本上是将代码直接从框架项目复制到核心项目,并进行了一些小的调整以使其能够编译

我试过几种变体,但都没有成功。我希望所有设置都在ConnectedService.json中,但我对如何设置的搜索没有返回任何有用的结果

任何帮助都将不胜感激,因为在过去的3天里,我一直在旋转我的轮子

提前谢谢

web.config中的框架设置(有效):

ConnectedService.json中的核心设置(失败):

核心代码尝试1初始化客户端(失败):

核心代码尝试2初始化客户端(失败):

初始化尝试1时发生身份验证错误:

The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Basic Realm'.
初始化尝试2的身份验证错误:

The HTTP request is unauthorized with client authentication scheme 'Basic'. The authentication header received from the server was 'Basic Realm'.
{
  "ProviderId": "Microsoft.VisualStudio.ConnectedService.Wcf",
  "Version": "15.0.40203.910",
  "ExtendedData": {
    "inputs": [
      "xxxxx.svc"
    ],
    "collectionTypes": [
      "System.Array",
      "System.Collections.Generic.Dictionary`2"
    ],
    "namespaceMappings": [
      "*, PatientService"
    ],
    "references": [
      "System.ServiceModel, {System.ServiceModel.Primitives, 4.4.4}",
      "System.ServiceModel.Duplex, {System.ServiceModel.Duplex, 4.4.4}",
      "System.ServiceModel.Http, {System.ServiceModel.Http, 4.4.4}",
      "System.ServiceModel.NetTcp, {System.ServiceModel.NetTcp, 4.4.4}",
      "System.ServiceModel.Primitives, {System.ServiceModel.Primitives, 4.4.4}",
      "System.ServiceModel.Security, {System.ServiceModel.Security, 4.4.4}"
    ],
    "targetFramework": "netcoreapp3.1",
    "typeReuseMode": "All"
  }
}
 public PatientServiceHelper(string UserName, string Password)
        {
            // Force TLS1.2
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            // Authenticate
            client.ClientCredentials.UserName.UserName = UserName;
            client.ClientCredentials.UserName.Password = Password;
}
public PatientServiceHelper(string UserName, string Password)
        {
            // Force TLS1.2
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            ClientCredentials myCredentials = new ClientCredentials();
            myCredentials.UserName.UserName = UserName;
            myCredentials.UserName.Password = Password;
            
            BasicHttpsBinding myBinding = new BasicHttpsBinding(BasicHttpsSecurityMode.Transport);
            myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;

            myBinding.CloseTimeout = TimeSpan.Parse("00:10:00");
            myBinding.OpenTimeout = TimeSpan.Parse("00:10:00");
            myBinding.ReceiveTimeout = TimeSpan.Parse("00:10:00");
            myBinding.SendTimeout = TimeSpan.Parse("00:10:00");
            myBinding.AllowCookies = false;
            myBinding.BypassProxyOnLocal = false;
            //hostnamecomparisonmode = StrongWildCard - Default Value
            myBinding.MaxBufferSize = 2147483647;
            myBinding.MaxBufferPoolSize = 524288;
            myBinding.MaxReceivedMessageSize = 2147483647;
            //MessageEncoding = Text - Default Value
            myBinding.TextEncoding = Encoding.UTF8;
            myBinding.TransferMode = TransferMode.Buffered;
            myBinding.UseDefaultWebProxy = true;
            myBinding.ReaderQuotas.MaxDepth = 32;
            myBinding.ReaderQuotas.MaxStringContentLength = 8192;
            myBinding.ReaderQuotas.MaxArrayLength = 16384;
            myBinding.ReaderQuotas.MaxBytesPerRead = 4096;
            myBinding.ReaderQuotas.MaxNameTableCharCount = 16384;
            
            EndpointAddress myEndpoint = new EndpointAddress("xxxxx.svc");
            ChannelFactory<IPatientService> myChannel = new ChannelFactory<IPatientService>(myBinding, myEndpoint);
            myChannel.Endpoint.EndpointBehaviors.Clear();
            myChannel.Endpoint.EndpointBehaviors.Add(myCredentials);
            IPatientService myClient = myChannel.CreateChannel();
            
            client = myClient;            
        }
 public bool TestPatientServiceModule()
        {
            PatientService.PatientPhoneNumberSearchRequest patientPhoneNumberSearchRequest = new PatientService.PatientPhoneNumberSearchRequest();
            patientPhoneNumberSearchRequest.PatientID = 1;
            PatientService.PatientPhoneSearchSortParameter[] patientPhoneSearchSortParameter = new PatientPhoneSearchSortParameter[1];
            patientPhoneSearchSortParameter[0] = new PatientPhoneSearchSortParameter();
            patientPhoneSearchSortParameter[0].SortOrder = SortOrder.Ascending;
            
            var results = client.PatientPhoneNumberSearchAsync(patientPhoneNumberSearchRequest, patientPhoneSearchSortParameter, 1, 1);
            results.Wait();
            return results.Result.Success;
        }
The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Basic Realm'.
The HTTP request is unauthorized with client authentication scheme 'Basic'. The authentication header received from the server was 'Basic Realm'.