1、.NET Core中使用WCF相关文档
2、调用示例代码
basicHttpBinding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; factory = new ChannelFactory(basicHttpBinding, new EndpointAddress(new Uri("https://someurl.com/ws/TheEndpoint.pub.ws:AService"))); factory.Credentials.UserName.UserName = "usern"; factory.Credentials.UserName.Password = "passw"; serviceProxy = factory.CreateChannel(); ((ICommunicationObject)serviceProxy).Open(); var opContext = new OperationContext((IClientChannel)serviceProxy); var prevOpContext = OperationContext.Current; // 可选的,如果没有办法,这可能已经设置 OperationContext.Current = opContext; try { var result = await serviceProxy.getSomethingAsync("id").ConfigureAwait(false); // cleanup factory.Close(); ((ICommunicationObject)serviceProxy).Close(); } finally { // *** ENSURE CLEANUP *** \\ CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory); OperationContext.Current = prevOpContext; // 或者设置为null(如果没有捕获前面的上下文) }