Wcf 是否在不使用代理的情况下设置ClientCredentials?
是否可以在不使用生成的代理的情况下设置ClientCredentials?我已经了解了使用ChannelFactory的一些情况,但是没有它也可以这样做吗?为了从客户端调用WCF服务,您需要一个代理(除非您想自己硬编码SOAP请求,这不是一件很容易的事,尤其是在处理安全性的情况下)。可以使用生成代理的工具之一(添加服务引用、svcuti等)或使用Wcf 是否在不使用代理的情况下设置ClientCredentials?,wcf,Wcf,是否可以在不使用生成的代理的情况下设置ClientCredentials?我已经了解了使用ChannelFactory的一些情况,但是没有它也可以这样做吗?为了从客户端调用WCF服务,您需要一个代理(除非您想自己硬编码SOAP请求,这不是一件很容易的事,尤其是在处理安全性的情况下)。可以使用生成代理的工具之一(添加服务引用、svcuti等)或使用ChannelFactory创建代理。如果您使用生成的代理,您将使用代理的ClientCredentials属性(继承自基类ClientBase。如果您
ChannelFactory
创建代理。如果您使用生成的代理,您将使用代理的ClientCredentials属性(继承自基类ClientBase
。如果您使用ChannelFactory
,您将在channel factory的Credentials
属性中设置它们。为了从客户端调用WCF服务,您需要一个代理(除非您想自己硬编码SOAP请求,这不是一件容易的事情,尤其是在处理安全性的情况下)。可以使用以下工具之一创建代理来生成代理(添加服务引用、svcutil等),或使用ChannelFactory
。如果使用生成的代理,则使用代理的ClientCredentials属性(从基类ClientBase
继承)。如果使用ChannelFactory
,则在通道工厂的Credentials
属性中设置它们。以下是示例代码:
EndpointAddress endpointAddress = new EndpointAddress("http://localhost:8888/TestSevice");
WSHttpBinding wsHttpBinding = new WSHttpBinding();
ChannelFactory<ISomeServiceInterface> iFactory = new ChannelFactory<ISomeServiceInterface>(wsHttpBinding, endpointAddress);
var clientCredentials = new ClientCredentials();
clientCredentials.UserName.UserName = "sudipto";
clientCredentials.UserName.Password = "sudipto";
iFactory.Endpoint.Behaviors.RemoveAll<ClientCredentials>();
iFactory.Endpoint.Behaviors.Add(clientCredentials);
var isomeService= iFactory.CreateChannel();
isomeService.SomeFunctionToCall("parameterToTheService");
EndpointAddress EndpointAddress=新的EndpointAddress(“http://localhost:8888/TestSevice");
WSHttpBinding WSHttpBinding=新的WSHttpBinding();
ChannelFactory iFactory=新的ChannelFactory(wsHttpBinding,endpointAddress);
var clientCredentials=新的clientCredentials();
clientCredentials.UserName.UserName=“sudipto”;
clientCredentials.UserName.Password=“sudipto”;
iFactory.Endpoint.Behaviors.RemoveAll();
iFactory.Endpoint.Behaviors.Add(clientCredentials);
var isomoservice=iFactory.CreateChannel();
isomeService.SomeFunctionToCall(“服务参数”);
以下是示例代码:
EndpointAddress endpointAddress = new EndpointAddress("http://localhost:8888/TestSevice");
WSHttpBinding wsHttpBinding = new WSHttpBinding();
ChannelFactory<ISomeServiceInterface> iFactory = new ChannelFactory<ISomeServiceInterface>(wsHttpBinding, endpointAddress);
var clientCredentials = new ClientCredentials();
clientCredentials.UserName.UserName = "sudipto";
clientCredentials.UserName.Password = "sudipto";
iFactory.Endpoint.Behaviors.RemoveAll<ClientCredentials>();
iFactory.Endpoint.Behaviors.Add(clientCredentials);
var isomeService= iFactory.CreateChannel();
isomeService.SomeFunctionToCall("parameterToTheService");
EndpointAddress EndpointAddress=新的EndpointAddress(“http://localhost:8888/TestSevice");
WSHttpBinding WSHttpBinding=新的WSHttpBinding();
ChannelFactory iFactory=新的ChannelFactory(wsHttpBinding,endpointAddress);
var clientCredentials=新的clientCredentials();
clientCredentials.UserName.UserName=“sudipto”;
clientCredentials.UserName.Password=“sudipto”;
iFactory.Endpoint.Behaviors.RemoveAll();
iFactory.Endpoint.Behaviors.Add(clientCredentials);
var isomoservice=iFactory.CreateChannel();
isomeService.SomeFunctionToCall(“服务参数”);
此外,您需要在打开频道之前设置凭据。此外,您还需要在打开频道之前设置凭据。