It is possible to create multiple endpoints in WCF from one service contract declaratively (by declaring it in the configuration file), but it is also possible to do it programmatically (I think almost everything that can be done declaratively can also be done programmatically, but I’m not very sure about this one though).
Declarative settings
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.serviceModel> <bindings> <netMsmqBinding> <binding name="MyBinding" exactlyOnce="false" maxReceivedMessageSize="131072"> <!-- ... --> </binding> </netMsmqBinding> </bindings> <services> <service behaviorConfiguration="ServiceConfiguration" name="MyApp.MyService"> <endpoint address="endpoint_address1" binding="netMsmqBinding" bindingConfiguration="MyBinding" contract="MyAssembly.IContract" /> <endpoint address="endpoint_address2" binding="netMsmqBinding" bindingConfiguration="MyBinding" contract="MyAssembly.IContract" /> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name="ServiceConfiguration" > <!-- Add the following element to your service behavior configuration. --> <serviceMetadata httpGetEnabled="true" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration> |
You can specify as many endpoints as you want to each service here.
Programmatically
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.serviceModel> <bindings> <netMsmqBinding> <binding name="MyBinding" exactlyOnce="false" maxReceivedMessageSize="131072"> <!-- ... --> </binding> </netMsmqBinding> </bindings> <services> <service behaviorConfiguration="ServiceConfiguration" name="MyApp.MyService"> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name="ServiceConfiguration" > <!-- Add the following element to your service behavior configuration. --> <serviceMetadata httpGetEnabled="true" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration> |
Note that I removed the endpoints part. This is to ensure that the endpoints created are from my code, instead of my configuration file. Next is the ServiceHost creation, where I will define the endpoints.
MyService ms = new MyService(); ServiceHost svc = new ServiceHost(ms, new Uri("http://myuri.org")); svc.AddServiceEndpoint(typeof(MyAssembly.IContract), new System.ServiceModel.NetMsmqBinding("MyBinding"), "endpoint_address1"); svc.AddServiceEndpoint(typeof(MyAssembly.IContract), new System.ServiceModel.NetMsmqBinding("MyBinding"), "endpoint_address2"); svc.Open(); |
Best Regards,
Ferry Mulyono
I'm using WCF configured with netMsmqBinding, and I needed to send a message containing binary data (specifically for image file). When I tried to send a dummy message (i.e. new byte[] { 0, 1, 2, 3 } ), it worked, but when I tried to send a real image file (around 90 kb), it didn't work at all. When I checked the queue (MSMQ), it turns out empty, so I suspect my WCF ServiceHost already consumed the message, but still, why the message was ignored?
After doing *stupid* experiment by sending various sized binary message, turns out that it will ignore fields (in my case array of byte) sized over 16384 bytes (that is, 2^14). Please note that I was using the default configuration. But after doing experiments on various configuration, I found out that in the binding element, you can configure readerQuotas element.
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
In this case, I'm particularly interested in maxArrayLength attribute. Note that the size specified here doesn't relate to the overall message size, but only the individual field of the message. Turns out that the it refused to serialized any field sized over the specified size resulting in WCF skips the serialization of that particular message (bottom line, it ignores the message). So, what I did here is just specify the size, and it worked automagically.
For more information, check Security Considerations for Data
Best Regards,
Ferry Mulyono
This was my project for course "
Technique of Parsing and Translation" previous semester. It turns out that my group was the only group that was successfully utilizing .NET Platform, right from the lexer down to its code gen. Next tuesday my group will be invited as guest lecturer in the same course for my juniors. I've attached the executables if any of you are interested in low-level IL stuff; this could be a good start =)