![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Using channel stack Hello! I am evaluating Windows Communication Foundation framework to discover, if it can be used to develop web service intermediary. I am trying to use a channel stack alone (without instantiating a service host, associating a contract, etc) for receiving and processing incoming messages. Here is an example of code which is running on the service side: ---CUT HERE using System; using System.Collections.Generic; using System.Text; using System.ServiceModel.Channels; using System.ServiceModel.Description; namespace WCFServer { class Program { static void Main(string[] args) { try { Uri address = new Uri("http://testserver:8080/EchoService"); CustomBinding binding = new CustomBinding(); SymmetricSecurityBindingElement security = SecurityBindingElement.CreateAnonymousForCertificateBindingElement(); binding.Elements.Add(security); HttpTransportBindingElement transport = new HttpTransportBindingElement(); binding.Elements.Add(transport); BindingParameterCollection parameters = new BindingParameterCollection(); ServiceCredentials credintials = new ServiceCredentials(); credintials.ServiceCertificate.SetCertificate("C=US, S=AP New, L=Hyd New, OU=IT New, O=Wipro New, CN=TestServer", System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine, System.Security.Cryptography.X509Certificates.StoreName.My); parameters.Add(credintials); IChannelListener<IReplyChannel> listener = binding.BuildChannelListener<IReplyChannel>(address, parameters); listener.Open(); IReplyChannel channel = listener.AcceptChannel(); channel.Open(); RequestContext context = channel.ReceiveRequest(); Console.WriteLine(context.RequestMessage.ToString()); Console.WriteLine("----------"); Message message = Message.CreateMessage(MessageVersion.Soap12WSAddressing10, "http://service/actionResponse", "This is my response."); Console.WriteLine(message.ToString()); context.Reply(message); context.Close(); channel.Close(); listener.Close(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.WriteLine(); } } } } --CUT HERE The client side code may look like this: --CUT HERE using System; using System.Collections.Generic; using System.Text; using System.ServiceModel; using System.ServiceModel.Description; using System.ServiceModel.Channels; namespace WCFClient { class Program { static void Main(string[] args) { try { CustomBinding binding = new CustomBinding(); SymmetricSecurityBindingElement security = SecurityBindingElement.CreateAnonymousForCertificateBindingElement(); binding.Elements.Add(security); HttpTransportBindingElement transport = new HttpTransportBindingElement(); transport.KeepAliveEnabled = false; binding.Elements.Add(transport); EndpointAddress address = new EndpointAddress("http://testserver:8080/EchoService"); ChannelFactory<IRequestChannel> factory = new ChannelFactory<IRequestChannel>(binding, address); factory.Credentials.ServiceCertificate.SetDefaultCertificate("C=US, S=AP New, L=Hyd New, OU=IT New, O=Wipro New, CN=TestServer", System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine, System.Security.Cryptography.X509Certificates.StoreName.My); factory.Open(); IRequestChannel channel = factory.CreateChannel(); channel.Open(); Message message = Message.CreateMessage(MessageVersion.Soap12WSAddressing10, "http://service/action", "This is my request."); Console.WriteLine(message.ToString()); message = channel.Request(message); Console.WriteLine("----------"); Console.WriteLine(message.ToString()); channel.Close(); factory.Close(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.WriteLine(); } } } } --CUT HERE If I comment out the lines that add security binding to binding collections on both client's and server's sides, the code executes correctly and the service returns the response to the client. But if security binding is enabled, the service returns the following error: "The mesage could not be processed because the action 'http://service/action' is invalid or unrecognized." I suppose that this error is generated by Contract Filter, as it doesn't know, in fact, the contract of the service. To fix that problem we would normally create an endpoint behavior and properly set ContractFilter and AddressFilter properties of EndpointDispatcher object: public class MyEndpointBehavior: IEndpointBehavior { public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) { endpointDispatcher.ContractFilter = new MatchAllMessageFilter(); endpointDispatcher.AddressFilter = new MatchAllMessageFilter(); } [...] } Then this behavior could be added to endpoint's Behaviors collection through ServiceHost object: serviceHost.Description.Endpoints[0].Behaviors.Add(new MyEndpointBehavior()); Unfortunately we have neither ServiceHost object nor Endpoint object available, so it is not clear how to configure those filters. My questions are: 1. Is this a "legal" use of channel stack ? 2. What is the actual cause of the problem ? 3. How this problem can be solved ? Thank you! Best regards, Alexander Novokshanov |
My System Specs![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| TV Channel wont play at first - "The Channel May Not Be Supported" (it is) | Ex_Brit | Media Center | 14 | 08-15-2008 06:51 AM |
| 2 GB dual channel vs 3 GB single channel | FrozenEclipse | Vista hardware & devices | 2 | 07-29-2008 09:52 PM |
| ATA/ATAPI: IDE Channel and ATA Channel | Henrik | Vista hardware & devices | 0 | 03-27-2008 04:55 AM |
| Bluetooth, Changing from Toshiba stack to MS stack | Jan | Vista hardware & devices | 2 | 10-18-2007 12:55 PM |
| TCP Stack | Robert | Vista networking & sharing | 12 | 05-26-2007 11:09 PM |