Custom MTOM Binding in WCF 4 - wcf

Since WPF 4 provides default configuration out of the box, I'm having difficulty trying to create a custom MTOM binding for my service. In short, my WCF library hosts several services that are using basic HTTP. One of the services is used for file uploads and requires MTOM. What can I do so that only my file upload service uses a custom defined MTOM binding and the rest use the default?
This is what I have so far:
<bindings>
<basicHttpBinding>
<binding
name="FileTransferBinding"
transferMode="Streamed"
messageEncoding="Mtom"
maxBufferSize="65536"
maxReceivedMessageSize="10485760">
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="FileTransferService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="FileTransferBinding" contract="MyServices.IFileTransfer"/>
</service>
</services>
Thanks in advance!

In order to configure a service, the service name in the <service> element needs to be the type fully qualified name of the class implementing the service, in order to identify the service that is being configured administratively.
<service name="MyNamcespace.FileTransferService">
Service element MSDN:
Name : Required String attribute that
specifies the type of the service to
be instantiated. This setting must
equate to a valid type. The format
should be Namespace.Class.

Related

WCF service hosted in IIS 7 - binding configuration settings are ignored

I have a WCF service operation that accepts a byte array as part of its data contract. The service is only exposed internally (not to the internet), and I want to increase the quotas to allow for a 10MB byte array.
The service is hosted in IIS7. When I try to send a byte array over the default length, I get the following exception message:
There was an error deserializing the object of type
MyService.ServiceContracts.Data. The maximum array length quota
(16384) has been exceeded while reading XML data. This quota may be
increased by changing the MaxArrayLength property on the
XmlDictionaryReaderQuotas object used when creating the XML reader.
Line 1, position 22991.
Here's the configuration:
<system.serviceModel>
<netTcpBinding>
<binding name="largeBinaryBinding" maxReceivedMessageSize="10001000"
maxBufferPoolSize="80008000" maxBufferSize="10001000"
receiveTimeout="00:01:00" openTimeout="00:01:00"
closeTimeout="00:01:00" sendTimeout="00:01:00">
<readerQuotas maxArrayLength="10000000" />
</binding>
</netTcpBinding>
<services>
<service name="MyService">
<endpoint binding="netTcpBinding"
bindingConfiguration="largeBinaryBinding"
bindingNamespace="http://my.services.co.uk/MyService"
contract="Services.MyService.ServiceContracts.IMyService" />
</service>
</services>
</system.serviceModel>
So my configuration allows for larger messages, but IIS seems to be ignoring this - how do I stop this and allow large messages through?
Again, just after I post a question I discover the answer!
When using WAS, you need to specify the full class name of the service in the configuration's service name. So in my example, I had my service implementation class called MyService, in the namespace Services. Therefore, in the configuration, I need
<service name="Services.MyService">
...
Otherwise IIS silently ignores your carefully crafted configuration! How convenient.

What is the bindingConfiguration attribute responsible for in a BasicHttpBinding endpoint config?

So I am working with configuring endpoints for a WCF service. I have almost no experience with services as a whole, but have been plopped in the middle of a project that uses them. I roughly understand what each attribute in the endpoint is doing except for one. "bindingConfiguration".
Here's an obscured version of my code (actual information is proprietary):
<endpoint address="http://localhost/SomeService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISomeService"
contract="SomeService.ICoreService" name="BasicHttpBinding_ISomeService" />
Here's MSDN's take on it (as in they don't specifically address it).
Microsoft's incomplete MSDN Entry
Of course Stackoverflow has a few questions containing a string match for "bindingConfiguration" but none explicetely address my question:
Most relative (I think) Stackoverflow question
Any ideas on what this is used for?
In the interest of learning I am willing to take a stab and be wrong here. I think it has something to with authentication or security. On Inspection of the Interface I notice nothing pertaining to this either.
Any help would be great!
Cheers
Matt
In your bindings section, you can have multiple "configurations" for the same binding type (in your case, basicHttpBinding). The binding configuration chooses among them which one to use.
In MSDN, you should try to find the reference for <endpoint> (since bindingConfiguration is is attribute), that will have a definition of what the attribute is supposed to do.
In the example below, the service defines two endpoints, both using basicHttpBinding. One of them is exposed over "normal" HTTP, the other is exposed over HTTPS. The bindingconfiguration attribute is the one which tells WCF which configuration to use.
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="SimpleBasic">
<security mode="None"/>
</binding>
<binding name="BasicOverHttps">
<security mode="Transport"/>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="MyNamespace.MyService">
<endpoint address="ep"
binding="basicHttpBinding"
bindingConfiguration="SimpleBasic"
contract="MyNamespace.IService" />
<endpoint address="secure"
binding="basicHttpBinding"
bindingConfiguration="BasicOverHttps"
contract="MyNamespace.IService" />
</service>
</services>
</system.serviceModel>

How to consume multiple binding WCF Service method without mentioning the endpoint name

Currently I’m using BaciHttpBinding and WsHttpBindin for same Service. Before introduce the BasicHttpBing, My Client Windows app consuming the WsHttpBindin, so i didn't mention the endpoint name. After introduce the BasicHttpBinding i need to mension the Name of the endpoint in my client when it going to consume the Desired Service. My problem is, I have to change all the existing code with endpoint name. How can i overcome this situation or is there any method which i can set the default binding in config level and it'll use when i didn't supply the endpoint name.
You can not define multiple endpoints on same address, assign two different address for both the bindings.
You can leave the address blank in case of contracts and it will automatically points to the address of mex endpoint, which is being used for defining your metadata.
Similarly you can BindingConfiguration tag to configure the bindings.
Do something like this, i am using binding configuration and transmode is streamed and using this binding configuration in my endpoints
<binding name="StreamBinding" closeTimeout="00:59:00" openTimeout="00:10:00"
sendTimeout="00:10:00" maxBufferPoolSize="700000000" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647" transferMode="Streamed">
<readerQuotas maxStringContentLength="2147483647" maxArrayLength="1000" />
<reliableSession inactivityTimeout="02:00:00" />
<security mode="None"></security> </binding>
<endpoint address="" binding="netTcpBinding" bindingConfiguration="StreamBinding"
bindingName="" contract="DBSInterface.Common.IFileTransfer">
<identity>
<dns value="localhost" />
</identity>
</endpoint>

WSHttp binding and ReliableSession / MaxRetryCount

When using a WSHttpBinding in WCF with reliableSessions enabled, my service reference updates itself to:
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="true">
</reliableSession>
I cannot add the maxRetryCount attribute to the reliableSession as long as the binding is configured as a WSHttpBinding.
Now my question: what is the value of maxRetryCount when using a WSHttpBinding, and is there any way to change this in config; without the use of a CustomBinding?
You cannot set the maxRetryCount on a standard wsHttpBinding configuration. In order to set that value, you need to create a separate custom binding and then reference that from your service or client config:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="wsCustomBinding">
<reliableSession maxRetryCount="15"/>
<textMessageEncoding/>
<httpTransport />
</binding>
</customBinding>
</bindings>
<services>
<service name="MyService">
<endpoint address="http://localhost:7878/MyServoce"
binding="customBinding"
bindingConfiguration="wsCustomBinding"
contract="IMyService" />
</service>
</services>
</system.serviceModel>
Defining a custom binding isn't hard - but you need to make sure you specify the elements that make up the binding in the right order - see the MSDN docs on custom bindings for a reference.
If you want to share the custom binding configuration between server and client, you could also put that <bindings> section into a separate bindings.config file, and then reference that external file from your web.config/app.config:
<system.serviceModel>
<bindings configSource="bindings.config">
Visual Studio will complain about this and show red squiggly underlines - but trust me - the technique works, I use it in production every day (the Visual Studio XML schema describing the config stuff isn't complete and accurate).
Marc

WCF Error: Stream Security is required at http://www.w3.org/2005/08/addressing/anonymous, but no security context was negotiated

We have a windows service that we are trying to use as WCF host for a WPF application. It works fine in development but when we have tried to move to our production environment we have had nothing but problems. From reading posts from others, we figured out how to turn on WCF logging and this was a big help. It turned out that our security bindings on the service and the client did not match. We set them both to use windows security but still no luck now we are trying to set the security mode to 'None' but it still is not working. Here is the bindings section of our service config file:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="netTcp">
<security mode='None'>
</security>
</binding>
</netTcpBinding >
</bindings>
<services>
<service name="CompanyService">
<endpoint
address= "our.url.com/CompanyService"
binding="netTcpBinding"
contract="CompanyServices.ICompanyService" />
</service>
</services>
</system.serviceModel>
Here is the serviceModel section of our client app config:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_Config" >
<security mode="None">
</security>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="our.url.com/CompanyService" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_Config" contract="CompanyServiceProxy.ICompanyService" name="NetTcpBinding_ICompanyService" />
</client>
</system.serviceModel>
If I need to supply additional infor please tell me what I need to supply.
Thanks
Standard net.tcp binding uses Windows credentials by default, and those really require client and service to be in the same Windows domain. Is this the case here??
OK, sorry, you mentioned security=None (your listings weren't properly formatted so I only saw a fraction of the actual config).
I guess your problem really lies in the addresses used:
address= "our.url.com/CompanyService"
When using net.tcp binding, you have to specify that before the address, so change this on both the client and the server to:
address= "net.tcp://our.url.com/CompanyService"
Also, what I don't quite understand is your title: it mentions "streaming" - have you specified streaming mode anywhere? In your config or your service contracts?
Marc