Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Indigo

Vista - Using channel stack

 
 
Old 01-16-2007   #1 (permalink)
Alexander Novokshanov


 
 

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 SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Channel 9 to swallow Channel 8, Channel 10, and Coding4Fun Vista News
Bluetooth, Changing from Toshiba stack to MS stack Vista hardware & devices
TV Channel wont play at first - "The Channel May Not Be Supported" (it is) Media Center
2 GB dual channel vs 3 GB single channel Vista hardware & devices
ATA/ATAPI: IDE Channel and ATA Channel Vista hardware & devices


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46