Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wcf 是否在不使用代理的情况下设置ClientCredentials?_Wcf - Fatal编程技术网

Wcf 是否在不使用代理的情况下设置ClientCredentials?

Wcf 是否在不使用代理的情况下设置ClientCredentials?,wcf,Wcf,是否可以在不使用生成的代理的情况下设置ClientCredentials?我已经了解了使用ChannelFactory的一些情况,但是没有它也可以这样做吗?为了从客户端调用WCF服务,您需要一个代理(除非您想自己硬编码SOAP请求,这不是一件很容易的事,尤其是在处理安全性的情况下)。可以使用生成代理的工具之一(添加服务引用、svcuti等)或使用ChannelFactory创建代理。如果您使用生成的代理,您将使用代理的ClientCredentials属性(继承自基类ClientBase。如果您

是否可以在不使用生成的代理的情况下设置ClientCredentials?我已经了解了使用ChannelFactory的一些情况,但是没有它也可以这样做吗?

为了从客户端调用WCF服务,您需要一个代理(除非您想自己硬编码SOAP请求,这不是一件很容易的事,尤其是在处理安全性的情况下)。可以使用生成代理的工具之一(添加服务引用、svcuti等)或使用
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(“服务参数”);

此外,您需要在打开频道之前设置凭据。此外,您还需要在打开频道之前设置凭据。