如何在ASP.NET Core Web应用程序中消费基于凭据的Web服务(ASMX)



我在.netcore Console应用程序中添加ASMX服务时面临问题。我正在使用WCF连接的服务扩展程序作为添加Web参考。因此,我遵循了以下链接中建议的相同步骤https://blogs.msdn.microsoft.com/webdev/2016/06/26/wcf-connected-service-service-for-net-net-core-net-core-net-core-1-0-0-0-0-0-b,-asp-net-core-core-1-0--0-is-now-vailable/

完成所有步骤后,它提供了自动生成的参考类,其中包含所有方法作为异步方法。我的ASMX服务需要每种方法的用户名和密码身份验证,我们将凭据作为任何方法的第一个参数。

例如,使用Web参考我的方法看起来像GetData(凭据凭据),但此处自动生成的类显示了此方法GetDataAsync(),所以我使用以下代码在调用我的Web服务方法之前通过凭据

client.clientcredentials.username.username =" myusername";client.clientcredentials.username.password =" mypassword";

这是我发现的断点后,我发现凭据没有获得ASMX服务。

请建议一些解决方案。

我采用的上一项方法:
我遇到了一个类似的问题。我有一个MVC Core Web应用程序(Targinaling .NET Framework 4.6.1),并且无法以我以前的(非核心)应用程序中的方式添加Web参考。我无法获得连接的服务来添加对ASMX的引用,并允许通过凭据。

为了解决这个问题,我创建了一个附加的项目(类项目也针对.NET Framework 4.6.1)。从那里,我能够按照过去的方式添加网络参考。在这个项目中,我创建了一个使用公共访问方法的类,该类调用ASMX服务。

然后,在我的MVC核心项目中,我设置了对这个附加项目的引用,并能够在另一个项目上调用公共方法。

我发现的最新和最佳方法:
我完全更新了VS 2017,并去此站点以获取最新的WCF连接服务扩展(https://marketplace.visualstudio.com/items?itemname = wcfcoreteam.visualstudiowcffconnectedservice)。

oferizationsoapheader易于访问和设置。

MySoapClient.EndpointConfiguration endpoint = new MySoapClient.EndpointConfiguration();  
MySoapClient myService = new MySoapClient(endpoint, myURL);              
AuthorizationSoapHeader MyAuthHeader = new AuthorizationSoapHeader();
MyAuthHeader.AppName = FDSServiceAppName;
MyAuthHeader.AppID = Guid.Parse(MyAppID); 
Entry[] entries = MyService.GetUsers().Result;

我遇到了同样的问题,我解决了它拥有的github问题:

在Reference.cs替代

System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding()

 System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding(System.ServiceModel.BasicHttpSecurityMode.TransportCredentialOnly);
            result.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Basic;

这确实在用于肥皂Web Services的.NET核心客户端应用中

相关内容

最新更新