大佬教程收集整理的这篇文章主要介绍了在WCF中,对于webHttpBinding,当服务器使用基本身份验证时,如何在客户端web.config中指定凭据?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<system.serviceModel> <bindings> <webhttpBinding> <binding name="general" maxReceivedmessageSize="2147483647"> <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" /> <security mode="None"> <transport clientCredentialType="None" /> </security> </binding> <binding name="admin" maxReceivedmessageSize="2147483647"> <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" /> <security mode="Transport"> <transport clientCredentialType="Basic" /> </security> </binding> </webhttpBinding> </bindings> <behaviors> <serviceBehaviors> <behavior> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="false"/> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name="web"> <webhttp/> </behavior> </endpointBehaviors> </behaviors> <services> <service name="MyNamespace.Appservices.Generalservice"> <endpoint address="" binding="webhttpBinding" contract="MyNamespace.Contracts.IGeneralservice" behaviorConfiguration="web" bindingConfiguration="general" /> </service> <service name="MyNamespace.Appservices.Adminservice"> <endpoint address="" binding="webhttpBinding" contract="MyNamespace.Contracts.IAdminservice" behaviorConfiguration="web" bindingConfiguration="admin" /> </service> </services> </system.serviceModel>
在客户端,我目前的代码如下:
private static IGeneralservice GetGeneralChAnnel() { WebhttpBinding binding = new WebhttpBinding(); binding.Security.Mode = WebhttpSecuritymode.None; binding.Security.Transport.ClientCredentialType = httpClientCredentialType.None; binding.MaxReceivedmessageSize = Int32.MaxValue; binding.ReaderQuotas.MaxStringContentLength = Int32.MaxValue; binding.ReaderQuotas.MaxArrayLength = Int32.MaxValue; WebChAnnelFactory<IGeneralservice> cf = new WebChAnnelFactory<IGeneralservice>(binding,new Uri("http://localhost:1066/Generalservice")); IGeneralservice chAnnel = cf.CreateChAnnel(); return chAnnel; } private static IAdminservice GetAdminChAnnel() { WebhttpBinding binding = new WebhttpBinding(); binding.Security.Mode = WebhttpSecuritymode.Transport; binding.Security.Transport.ClientCredentialType = httpClientCredentialType.basic; binding.MaxReceivedmessageSize = Int32.MaxValue; binding.ReaderQuotas.MaxStringContentLength = Int32.MaxValue; binding.ReaderQuotas.MaxArrayLength = Int32.MaxValue; WebChAnnelFactory<IAdminservice> cf = new WebChAnnelFactory<IAdminservice>(binding,new Uri("http://localhost:1066/Adminservice")); cf.Credentials.username.UserName = "myUserName"; cf.Credentials.username.password = "mypassword"; IAdminservice chAnnel = cf.CreateChAnnel(); return chAnnel; }
问题是,由于我显然不想硬编码所有这些配置信息,我需要如何在客户端的web.config中提供它?对于我来说,绑定元素在客户端上看起来和服务器上看起来完全相同,这是非常明显的.但是,在哪里可以指定分配给WebChAnnelFactory的凭据?
任何帮助和/或洞察将不胜感激.
谢谢,
史蒂夫
以上是大佬教程为你收集整理的在WCF中,对于webHttpBinding,当服务器使用基本身份验证时,如何在客户端web.config中指定凭据?全部内容,希望文章能够帮你解决在WCF中,对于webHttpBinding,当服务器使用基本身份验证时,如何在客户端web.config中指定凭据?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。