WSHttp binding and ReliableSession / MaxRetryCount - wcf

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

Related

WCF customBinding is BasicHTTPBinding when adding service reference

I have a WCF service with a customBinding endpoint.
<customBinding>
<binding name="customBinding" receiveTimeout="00:10:00" sendTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00">
<binaryMessageEncoding>
<readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647" />
</binaryMessageEncoding>
<httpTransport maxReceivedMessageSize="40194304" />
</binding>
</customBinding>
My service is :
<services>
<service name="Test2">
<endpoint address="" binding="customBinding" bindingConfiguration="customBinding" contract="MyServiceContract.ContractInterface">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
However, in my client application, whenever I add a Service Reference, the resulting reference is a BasicHTTPBinding (in app.config)
What can I do to "force" the client to use custombinding?
Thanks
Alex
The service is not using the binding you specified. My guess is that the service name is actually "MyServiceContract.Test2" (or something similar) instead of just "Test2", so when WCF didn't find any matching <service> element to the service class, it simply used the default endpoint, which happens to use basicHttpBinding.
Have you defined a class for your custom binding (a class derived from System.ServiceModel.Channels.Binding)?
If so, have you added the new binding into the config binding extensions?
<extensions>
<bindingExtensions>
<add name="myCustomeBinding" type="MyCustomeBinding, MyCustomeBindingLibrary" />
</bindingExtensions>
</extensions>
The job of the binding is to define the "recipe" for creating the WCF channel. Basically the recipe consists of a list of binding elements.
Which bindings elements you select in your recipe decides the nature of the communication that the WCF channel will implement.
At the absolute minimum your recipe of binding elements needs to include:
Message encoding (text/binary etc)
Transport (HTTP/TCP etc)
If you don't have a class defining your binding then WCF has no option but to create a channel based on the default values for these two binding elements, and so has probably been designed to switch to basicHttpBinding when no binding has is defined.
That would be my guess.

TransactionFlow in WCF from Visual Studio 2010 Express

I'm trying to get started with transactions in WCF, using the free Microsoft Visual Web Developer 2010 Express. It gives me the option to create a "WCF Service Application" but it doesn't appear to give me many options for hosting it or configuring different bindings. If I F5 the project I get the error:
At least one operation on the 'Service' contract is configured with the TransactionFlowAttribute attribute set to Mandatory but the channel's binding 'BasicHttpBinding' is not configured with a TransactionFlowBindingElement. The TransactionFlowAttribute attribute set to Mandatory cannot be used without a TransactionFlowBindingElement.
I've tried adding in */services/service/endpoint configuration into the web.config but it appears to just be ignored. I also tried to change the default startup application to WcfSvcHost.exe but this option is greyed out. I'm beginning to suspect the Express edition of some failings but am optimistic that it's just me being a dunce. Is there a trick I need to learn, or will splashing out on the full version of Visual Studio 2010 be enough to get me over this hurdle and onto the next one?
Thanks!
Without knowing your configuration and service contract it is almost impossible to make targeted answer. If you think that your configuration is ignored make sure that names used in service and endpoint/#contract contains CLR namespaces.
WCF 4 uses nice simplified configuration which IMHO made real configuration much bigger pain then it was before. You can switch defaults by adding this to your web config:
<protocolMapping>
<remove scheme="http" />
<add scheme="http" binding="wsHttpBinding" bindingConfiguration="transactionFlowEnabled"/>
</protocolMapping>
<bindings>
<wsHttpBinding>
<binding name="transactionFlowEnabled" transactionFlow="true" />
</wsHttpBinding>
</bindings>
This is workaround which should use defined binding as default instead of basicHttpBinding.
Thanks to Ladislav's suggestion, I was able to solve this by adding the following entries into the Web.config file:
<services>
<service name="WcfService1.Service1">
<endpoint
address=""
binding="wsHttpBinding"
contract="WcfService1.IService1"
/>
</service>
</services>
and:
<bindings>
<wsHttpBinding>
<binding transactionFlow="true"/>
</wsHttpBinding>
</bindings>

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>

Custom MTOM Binding in WCF 4

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.

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