<binding name="XServiceSoap"
maxBufferPoolSize="16777216"。
maxBufferSize="16777216"。
maxReceivedMessageSize="16777216">
<security mode="TransportCredentialOnly"/span>>
<transport clientCredentialType="Ntlm"/span>
proxyCredentialType="None"/>
</security>/span>
</binding>
而客戶端則是這樣的:
<endpoint address="http://uri/XService.asmx"/span>
binding="basicHttpBinding"。
bindingConfiguration="XServiceSoap"。
contract="XService.XServiceSoap"。
name="XServiceSoap"/>
在代碼中,我很容易就能用
改變端點地址(和憑證)。using WPFApp.XService。
var xServiceSoapClient = new XServiceSoapClient("XServiceSoap"/span>)。
xServiceSoapClient.Endpoint.Address = new EndpointAddress(NEW_ENDPOINT)。
xServiceSoapClient
.ClientCredentials.Windows.ClientCredential.UserName = NEW_USERNAME;
xServiceSoapClient
.ClientCredentials.Windows.ClientCredential.Password = NEW_PASSWORD。
但如果我嘗試使用一個非http端點,我得到了一個例外提供的URI方案'https'無效;預期是'http'。
這個錯誤對我來說是有意義的(例如,從這里),但是我希望在改變端點時,同一個系結能夠同時支持HTTP和HTTPS(測驗與原型服務器)。我如何在代碼中用內置的soap客戶端做到這一點?我在xServiceSoapClient中沒有看到改變安全模式的選項,例如,我沒有看到XServiceSoapclient.Security.Mode選項可以改變它。
我可以確認,當我手動將app.config從TransportCredentialOnly改為Transport時,https連接可以正常作業而不會出現例外。
謝謝你!
uj5u.com熱心網友回復:
WCF客戶端的建構式有一個多載,需要兩個引數:binding和endpoint
你可以使用這個多載來傳遞你想要的安全模式:
WSHttpBinding binding = new WSHttpBinding()。
binding.Security.Mode = SecurityMode.Transport;
var xServiceSoapClient = new xServiceSoapClient(binding, "XServiceSoap"/span>)。
這就是一般的想法,使用指定的物件而不是服務客戶端物件,因為服務客戶端物件并不是為了進行上述的操作。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/316169.html
標籤:
上一篇:在第二個空格后選擇字串
