How to design and implement a simple WCF service relay?

后端 未结 3 693
陌清茗
陌清茗 2020-12-18 11:18

We are in the process of designing a simple service-oriented architecture using WCF as the implementation framework. There are a handful of services that a few applications

3条回答
  •  萌比男神i
    2020-12-18 11:46

    It seems it is sufficient to build an interface as follows:

    [OperationContract(Action="*", ReplyAction="*")]
    Message CallThis(Message msg);
    

    I also found this post useful for implementing the CallThis method by "fiddling" with Message objects. A basic implementation of the CallThis method follows:

    public Message CallThis(Message message) {
        MessageBuffer buffer = message.CreateBufferedCopy(524288);
        Message output = buffer.CreateMessage();
        output.Headers.To = ;
    
        BasicHttpBinding binding = new BasicHttpBinding();
        IChannelFactory factory = binding.BuildChannelFactory();
        factory.Open();
    
        IRequestChannel channel = factory.CreateChannel(new EndpointAddress());
        channel.Open();
    
        Message result = channel.Request(output);
    
        message.Close();
        output.Close();
        factory.Close();
        channel.Close();
    
        return result;
    }
    

    Adding authentication and authorization should be quite straightforward.

提交回复
热议问题