以编程方式配置 wcf 服务
我有一个远程 wcf 服务,我通过 WSHttpBinding 连接它。如果我使用空服务构造函数,这意味着它将获取 app.config 中的所有配置,则一切正常(我的意思是 MyService s = new MyService())。 现在我想以编程方式配置 wcf。在我谈到身份验证问题之前,这很简单,但做到这一点非常困难。这是我使用的app.config,你可以在那里看到我的安全配置。
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="SecuredEndPoint" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="true" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://MyWcfService.svc"
binding="wsHttpBinding" bindingConfiguration="SecuredEndPoint"
contract="ServiceReference1.IMyService" name="SecuredEndPoint">
<identity>
<certificate encodedValue="*******************************************************************" />
</identity>
</endpoint>
</client>
</system.serviceModel>
I have a remote wcf service, I connect it by WSHttpBinding. If I use the empty service constructor which mean it will take all the configurations from the app.config , everything is ok, (I mean MyService s = new MyService()).
Now I want to configure the wcf programmatically . it's simple till I arrive to the authentication issue , it was so hard to do that . Here is the app.config which I use , you can see there my security configurations .
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="SecuredEndPoint" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="true" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://MyWcfService.svc"
binding="wsHttpBinding" bindingConfiguration="SecuredEndPoint"
contract="ServiceReference1.IMyService" name="SecuredEndPoint">
<identity>
<certificate encodedValue="*******************************************************************" />
</identity>
</endpoint>
</client>
</system.serviceModel>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经完成了此操作,您可能需要修改配置中的安全模式代码。
在此
proxy
对象上,您需要执行.CreateChannel()
才能使用它。希望这有帮助。
I have done this, you might have to modify your code for security mode you have in config
On this
proxy
object you will need to do.CreateChannel()
to use it.Hope this helps.