這是我在將使用WCF服務的Asp .Net函式應用程式轉換到.Net核心時面臨的一個問題。WCF服務期待著編碼型別為mtom的HTTP內容,但它不被.Net核心支持,所以它發出了一個例外。 一旦WCF服務被呼叫,"在這種情況下,系結屬性訊息不支持mtom值"。
我將在下面附上解決方法
。CodePudding
安裝WcfCoreMtomEncoder nuget包,然后 在參考檔案中,當你為端點創建系結時。 創建basicHttpBinding
var transportSecurityBindingElement = new BasicHttpBinding()。
設定所需的安全和傳輸模式
transportSecurityBindingElement.Security.Mode =BasicHttpSecurityMode.Transport;
transportSecurityBindingElement.Security.Transport.ClientCredentialType =System.ServiceModel.HttpClientCredentialType.Basic;
創建具有自定義系結型別的物件
var customTransportSecurityBinding = new CustomBinding(transportSecurityBindingElement)。
使用mtomMessage編碼器創建編碼元素
var encodingElement = new MtomMessageEncoderBindingElement(new TextMessageEncodingBindingElement())。
通過迭代系結的元素串列找到并替換編碼屬性
for(int i = 0; i < customTransportSecurityBinding.Elements.Count; i )
{
if (customTransportSecurityBinding.Elements[i] is TextMessageEncodingBindingElement) {
customTransportSecurityBinding.Elements[i] = encodingElement;
break。
}
}
回傳自定義系結,所以它可以從任何地方使用
return customTransportSecurityBinding
uj5u.com熱心網友回復:
我所知道的是,WCF目前不支持一些MTOM的功能,所以它必須等待。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/316161.html
標籤:
