Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.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服务的URL时,如何使用它_Wcf - Fatal编程技术网

当我只知道wcf服务的URL时,如何使用它

当我只知道wcf服务的URL时,如何使用它,wcf,Wcf,当我只知道wcf服务的URL时,我需要动态地使用它。我没有创建服务引用或web引用的选项,因为客户端代码从配置文件中获取URL。我可以使用System.ServiceModel命名空间中的哪些类和方法来执行此操作。如果您了解合同,则可以执行以下操作: using (WebChannelFactory<IService> wcf = new WebChannelFactory<IService>(new Uri("http://localhost:8000/Web")))

当我只知道wcf服务的URL时,我需要动态地使用它。我没有创建服务引用或web引用的选项,因为客户端代码从配置文件中获取URL。我可以使用System.ServiceModel命名空间中的哪些类和方法来执行此操作。

如果您了解合同,则可以执行以下操作:

using (WebChannelFactory<IService> wcf = new WebChannelFactory<IService>(new Uri("http://localhost:8000/Web")))
Message input = Message.CreateMessage( .... );

ChannelFactory<IRequestChannel> factory = new ChannelFactory<IRequestChannel>(binding, endpoint);
IRequestChannel channel - factory.CreateChannel();

Message output = channel.Send(input);
使用(WebChannelFactory wcf=新的WebChannelFactory(新的Uri(“http://localhost:8000/Web")))

更多

如果您了解合同,那么您可以执行以下操作:

using (WebChannelFactory<IService> wcf = new WebChannelFactory<IService>(new Uri("http://localhost:8000/Web")))
Message input = Message.CreateMessage( .... );

ChannelFactory<IRequestChannel> factory = new ChannelFactory<IRequestChannel>(binding, endpoint);
IRequestChannel channel - factory.CreateChannel();

Message output = channel.Send(input);
使用(WebChannelFactory wcf=新的WebChannelFactory(新的Uri(“http://localhost:8000/Web")))

更多

如果您没有服务接口,您至少必须了解服务器期望的消息是什么样子;否则很难做到:)

但肯定有办法做到这一点。您可以首先创建服务器期望作为输入的原始消息,然后在消息对象(我指的是System.ServiceModel.Channels.message)中创建它。确保您为它设置了所有必要的头,这取决于您希望用来调用客户机的绑定(比如设置正确的凭据、正确的消息版本等等)

然后,您可以简单地使用一种标准的通用通道形状(如IRequestChannel或IInputChannel,用于单向服务)创建通道工厂,并使用通道工厂创建新通道并调用服务。例如:

using (WebChannelFactory<IService> wcf = new WebChannelFactory<IService>(new Uri("http://localhost:8000/Web")))
Message input = Message.CreateMessage( .... );

ChannelFactory<IRequestChannel> factory = new ChannelFactory<IRequestChannel>(binding, endpoint);
IRequestChannel channel - factory.CreateChannel();

Message output = channel.Send(input);
Message input=Message.CreateMessage(…);
ChannelFactory=新的ChannelFactory(绑定,端点);
IRequestChannel-factory.CreateChannel();
消息输出=通道发送(输入);

如果您没有服务接口,您至少必须了解服务器期望的消息是什么样子;否则很难做到:)

但肯定有办法做到这一点。您可以首先创建服务器期望作为输入的原始消息,然后在消息对象(我指的是System.ServiceModel.Channels.message)中创建它。确保您为它设置了所有必要的头,这取决于您希望用来调用客户机的绑定(比如设置正确的凭据、正确的消息版本等等)

然后,您可以简单地使用一种标准的通用通道形状(如IRequestChannel或IInputChannel,用于单向服务)创建通道工厂,并使用通道工厂创建新通道并调用服务。例如:

using (WebChannelFactory<IService> wcf = new WebChannelFactory<IService>(new Uri("http://localhost:8000/Web")))
Message input = Message.CreateMessage( .... );

ChannelFactory<IRequestChannel> factory = new ChannelFactory<IRequestChannel>(binding, endpoint);
IRequestChannel channel - factory.CreateChannel();

Message output = channel.Send(input);
Message input=Message.CreateMessage(…);
ChannelFactory=新的ChannelFactory(绑定,端点);
IRequestChannel-factory.CreateChannel();
消息输出=通道发送(输入);

这需要客户端了解iSeries设备接口这需要客户端了解iSeries设备接口