【发布时间】:2014-09-03 08:43:27
【问题描述】:
我们有几个客户端(10 个)使用端点与我们的 WCF 服务器连接,目前他们都在使用下面给出的这段代码。
我们可以在 web.config 中指定所有设置吗?由于我们的 WCF Web 服务托管在单独的服务器上,并且只是忽略客户端为我们提供的内容,因此我希望它们不向我们提供超时和绑定等值,我查看了证书身份验证,但不是我们想要的,因为客户端将来会增加。 .
HttpClientCredentialType credType = myCred.httpClientCredentialType;
//Set the binding security & authentication type
BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = credType;
TimeSpan ts = new TimeSpan(0, 0, 10, 0);
binding.CloseTimeout = ts;
binding.OpenTimeout = ts;
binding.ReceiveTimeout = ts;
binding.SendTimeout = ts;
//set the webservice endpoint address
EndpointAddress endpoint = new EndpointAddress(someURL + "/_vti_bin/ourWCF/fruits.svc");
ChannelFactory<WebServices.Internal.IFruits> factory = new ChannelFactory<WebServices.Internal.IFruits>(binding);
factory.Credentials.Windows.ClientCredential = myCred;
factory.Credentials.UserName.UserName = myCred.UserName;
factory.Credentials.UserName.Password = myCred.Password;
WebServices.Internal.IFruits proxy = factory.CreateChannel(endpoint);
string someThing = proxy.GetFruitsList();
【问题讨论】: