2017-08-08 75 views
1

當我嘗試創建的dotnet核2.0的WCF客戶端的連接,我收到一個平臺不支持的錯誤:WCF在.net中的核心(TransportWithMessageCredential)

System.PlatformNotSupportedException: 'The value 'TransportWithMessageCredential' is not supported in this context for the binding security property 'securityMode'.' 

如果我刪除BasicHttpSecurityMode,我收到參數異常: System.ArgumentException:'提供的URI方案'https'無效;預計'http'。''

代碼:

ChannelFactory<BlackBoxContract> factory = null; 
BlackBoxContract serviceProxy = null; 
Binding binding = null; 

binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential); 

factory = new ChannelFactory<BlackBoxContract>(binding, new EndpointAddress("https:......."));; 
serviceProxy = factory.CreateChannel(); 

是任何人發現,因爲這可能是長遠路線圖解決方法? https://github.com/dotnet/wcf/issues/8

+0

能WCF客戶端代碼進入一個面向.NET標準的類庫?然後你可以從.NET Core調用庫。這[SO回答](https://stackoverflow.com/a/45550508/444244)可能是相關的。 – Boggin

+0

您是否使用WCF連接的服務? https://marketplace.visualstudio.com/items?itemName=WCFCORETEAM.VisualStudioWCFConnectedService – Tseng

+0

WCF連接服務給我一個錯誤,出於同樣的原因。不支持,該錯誤信息只是略有不同.. https://github.com/dotnet/wcf/issues/1274 –

回答

0

居然找到一個有效的解決辦法,有一個包,你可以使用這個: https://github.com/gravity00/SimpleSOAPClient

using SimpleSOAPClient; 
using SimpleSOAPClient.Handlers; 
using SimpleSOAPClient.Helpers; 
using SimpleSOAPClient.Models; 
using SimpleSOAPClient.Models.Headers; 

... 

_client = SoapClient.Prepare().WithHandler(new DelegatingSoapHandler()); 
_client.HttpClient.DefaultRequestHeaders.Clear(); 
_client.HttpClient.DefaultRequestHeaders.Add("SOAPAction", "Action..."); 

var requestEnvelope = SoapEnvelope 
    .Prepare() 
    .Body(request) 
    .WithHeaders(KnownHeader.Oasis.Security.UsernameTokenAndPasswordText(Username, Password)); 

var responseEnvelope = _client.Send(Url, "CanNotBeEmpty", requestEnvelope); 

得到它這樣的工作,作爲一個魅力...

-1

你嘗試這樣設置呢?

var binding = new BasicHttpBinding(); 
binding.Security.Mode = SecurityMode.TransportWithMessageCredential; 

據我所知,這種方式在How to: Set the Security Mode中描述。此外,檢查How to: Use Transport Security and Message Credentials文章也很有意義。

+0

Nowp,仍然沒有平臺不支持的錯誤。 –

+0

我已經加入到https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-use-transport-security-and-message-credentials評論(見本頁底) –

+2

這不是.net核心文檔 –