我需要通过app.config
代码重现此C#
服务文件。
<system.serviceModel>
....
<protocolMapping>
<add scheme="https" binding="wsHttpBinding" />
</protocolMapping>
...
特别是scheme
部分,所以我这样做了:
var binding = new WSHttpBinding();
binding.Security.Mode = SecurityMode.Transport;
...
但如果我尝试binding.Scheme = ...
,我会收到编译时错误the property Scheme has no setter
。
如何通过代码设置?
答案 0 :(得分:0)
设置binding.Scheme
时,班级会自动设置binding.Security.Mode
。例如,如果您设置binding.Security.Mode = SecurityMode.None;
,则会返回"http"
,如果您设置binding.Security.Mode = SecurityMode.Transport;
,则会返回"https"
。
WSHttpBinding参考:http://msdn.microsoft.com/en-us/library/system.servicemodel.wshttpbinding%28v=vs.110%29.aspx
此外,如果你谷歌setting up a wcf service in code
,似乎有很多有趣的例子可以帮助你。