WCF customBinding problem - wcf

I've been playing around with a pollingDuplex example that is driving me nuts. I'm using a customBinding to integrate the readerQuotas element and I keep getting the error: "Contract requires Duplex, but binding 'BasicHttpBinding' doesn't support it or isn't configured properly to support it."
Where is that BasicHttpBinding coming from when I am using customBinding ? I've checked countless examples and my configuration file matches what they had but it doesn't work. Can anyone help me with this ?
Thanks.
<configuration>
<system.serviceModel>
<extensions>
<bindingElementExtensions>
<add name="pollingDuplex" type="System.ServiceModel.Configuration.PollingDuplexElement, System.ServiceModel.PollingDuplex"/>
</bindingElementExtensions>
</extensions>
<bindings>
<customBinding>
<binding name="DBNotification" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00">
<httpsTransport maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647"/>
<pollingDuplex duplexMode="MultipleMessagesPerPoll" maxPendingSessions="2147483647" maxPendingMessagesPerSession="2147483647"/>
<binaryMessageEncoding>
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binaryMessageEncoding>
</binding>
</customBinding>
</bindings>
<services>
<service name="AdminWebService" behaviorConfiguration="DBNotificationServiceBehavior">
<endpoint address="adminservice" binding="customBinding" bindingConfiguration="DBNotification" contract="AdminWebService.IAdminWebService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DBNotificationServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceThrottling maxConcurrentSessions="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

You're probably running into the "simplified configuration" problem - described in details at http://blogs.msdn.com/b/endpoint/archive/2009/11/09/common-user-mistake-in-net-4-mistyping-the-service-configuration-name.aspx. The "name" attribute in the <service> element must be the fully-qualified name of the service. Since your interface is AdminWebService.IAdminWebService, isn't your service name AdminWebService.AdminWebService? If so, fixing the name attribute should fix the issue.

Is it possible that httpGetEnabled="true" implies using BasicHttpBinding? Do you really need this feature? Does the error goes away if you comment this line?

Related

WCF throws exception that the server has rejected the client credentials, what is the default security mode for NetTCP in WCF

The WCF is deployed as a windows service in the server. And the client is a windows form applicaiton. When the client is interacting with the WCF server, is there any kind of authentication going on here?
I got how to resolve this here
I want to know what is the default security mode for NetTCP in WCF? I had nothing related with security in my config file as below. So what is the default?
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<behaviors>
<serviceBehaviors>
<behavior name="BasicServiceBehavior">
<serviceMetadata httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="HCCNetTcpBinding" >
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="BasicServiceBehavior" name="HCC.SMS4.SERVICES.BASIC.MainServices">
<endpoint address="" binding="netTcpBinding" contract="HCC.SMS4.SERVICES.BASIC.IMainServices" bindingConfiguration="HCCNetTcpBinding" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://xxxx:44008/HCsmsBasicServices/"/>
<add baseAddress="net.tcp://xxxx:45008/HCsmsBasicServices/"/>
</baseAddresses>
</host>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="HCCNetTcpBinding" maxConnections="1000" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"
openTimeout="14:00:00" receiveTimeout="14:00:00" sendTimeout="14:00:00">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
The transport security mode of the NetTcpBinding is Transport and the ClientCredentialType is Windows. This is equivalent to the following settings.
<netTcpBinding>
<binding name="netTcp">
<security mode="Transport">
<transport clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
So when you use the client proxy class to call the service, you could refer to the following code.
ServiceReference1.ServiceClient client = new ServiceReference1.ServiceClient();
client.ClientCredentials.Windows.ClientCredential.UserName = "administrator";
client.ClientCredentials.Windows.ClientCredential.Password = "abcd1234!";
var result = client.SayHello();
https://learn.microsoft.com/en-us/dotnet/framework/wcf/system-provided-bindings
https://learn.microsoft.com/zh-cn/dotnet/framework/wcf/feature-details/bindings-and-security
Feel free to contact me if you have any questions.
WCF, its default authentication is Windows if there is none config about it.
Per Microsoft documentation for NetTcpBinding the default security is TLS with Windows security.

WCF REST - maxMessageSize exceeded

Here are parts of the configuration file:
<services>
<service name="MMC.API2.MMCApi" behaviorConfiguration="restBehaviorConfig">
<endpoint address="" binding="webHttpBinding" contract="MMC.API2.IMMCApi" behaviorConfiguration="web" bindingConfiguration="LargeData">
</endpoint>
<host>
<timeouts openTimeout="01:20:00" closeTimeout="01:20:00" />
</host>
</service>
</services>
...
<webHttpBinding>
<binding name="LargeData" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="32" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/>
</binding>
</webHttpBinding>
Problem:
The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.
The fragments of the service’s binding configuration seem to be set ok, so you may want to look into the clients’ binding configurations to make sure they have similar settings for the readerQuotas and maxBuffer* settings.
Notes:
You may want to provide a bit more information about the overall environment/configuration.
If you haven’t already, enabling WCF trace logging may help you identify the issue.
It looks fine to me. Try to change the behavior configuration as below;
<serviceBehaviors>
<behavior name="web">
<dataContractSerializer ignoreExtensionDataObject="true" maxItemsInObjectGraph="2147483647" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceTimeouts transactionTimeout="00:10:00" />
<serviceThrottling maxConcurrentCalls="200" maxConcurrentSessions="100"
maxConcurrentInstances="100" />
</behavior>
</serviceBehaviors>

WCF - When object to transfer has a list of more than 127 objects

i use WCF with Code First (VS 2012, .NET 4.0, WCF 5). Everything works fine unless i want to transfer an large object. It contains a list of many other objects. Every object has only small content. If this list is longer than 127 objects, i get an exception:
The server did not provide a meaningful reply; this might be caused by
a contract mismatch, a premature session shutdown or an internal
server error.
I found that out by reducing column count in database (try and error).
I use the following configuration on the client:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_****_Service" closeTimeout="00:00:10"
openTimeout="00:00:10" receiveTimeout="00:05:00" sendTimeout="00:05:00"
maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://localhost:8000/****" binding="netTcpBinding"
bindingConfiguration="****" contract="****"
name="NetTcpBinding_****Service">
<identity>
<userPrincipalName value="****" />
</identity>
</endpoint>
</client>
</system.serviceModel>
The server configuration looks as follows:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_****_Service" closeTimeout="00:00:10"
openTimeout="00:00:10" receiveTimeout="00:05:00" sendTimeout="00:05:00"
transferMode="Buffered" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
maxConnections="0" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="100000" maxStringContentLength="100000"
maxArrayLength="100000" maxBytesPerRead="100000" maxNameTableCharCount="100000" />
<reliableSession enabled="false" />
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="****">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_****_Service"
contract="****" />
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8000/****" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Please excuse the masking of some names. I need to avoid that one can draw inferences from these names about the project. :D
At first, set this property on server side (just for dev)
<serviceDebug includeExceptionDetailInFaults="true" />
that specifies whether to include managed exception information in the detail of SOAP faults returned to the client for debugging purposes.
It's sure there is something wrong when processing your request but you don't have any debug information. That's why you have to set this property. You can also turn on WCF Tracing but it's a bit more difficult.
WCF have many quotas : A quota is a hard limit that prevents the use of additional resources once the quota value is exceeded.
There are especially two quotas you need to be aware when sending large data : maxReceivedMessageSize and MaxItemsInObjectGraph.

Transfer large amount of data in WCF service

I have created a web service in WCF which returns more than 54000 data-rows with 10 data in each row. I have used the wsHttpBinding for communication. The service works well with less data (i.e. 2000 rows) but it bombs out when attempting to send large record set with 50000+ rows(~2MB). The exception message is like this
An error occurred while receiving the HTTP response to http://localhost:9002/MyService.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.
Please don't tell me to use pagination on the client side - I know that it will solve the problem. But I need the whole chunk of data in the client-end.
My service configuration on server is as
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="MyWsHttpBinding" />
</wsHttpBinding>
</bindings>
<services>
<service name="AdminService">
<endpoint address="AdminSrv"
binding="wsHttpBinding"
contract="IAdminService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="/Bus/IRfotoWCF" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"></serviceHostingEnvironment>
</system.serviceModel>
My client configuration is as
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IAdminService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/TestService/AdminService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAdminService"
contract="IAdminService" name="BasicHttpBinding_IAdminService" />
</client>
</system.serviceModel>
Would someone help me out with excact configuration both in the client and server side. Even if i need to change binding from wsHttpBinding to netTcpBinding - i have no problem doing that. Thanks in advance.
After a lot of investigation finnally i got the solution. Actually a number of things need to be changed.
The following changes needed to be done in Server-side.
First I had to set a maxRequestLength to a larger value in my httpRuntime element to run the request for longer period.
<system.web>
<httpRuntime maxRequestLength="102400" />
</system.web>
Second i introduced netTcpBinding binnding with custom changes on maxBufferSize, maxBufferPoolSize, maxReceivedMessageSize with a large value of 2147483647.
<binding name="myNetTcpBinding"
maxBufferPoolSize="2147483647"
maxBufferSize="524288"
maxReceivedMessageSize="2147483647">
Third add maxItemsInObjectGraph in both of the serviceBehaviors and endpointBehaviors like bellow (dont forget to mention the behaviour names in the service and endpoint node)
<behaviors>
<serviceBehaviors>
<behavior name="myNetTcpBehaviour">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="myNetTcpEndPointBehaviour">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
Finally my server configuration looks like this
<system.web>
<httpRuntime maxRequestLength="102400" />
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="MyWsHttpBinding" />
</wsHttpBinding>
<netTcpBinding>
<binding name="myNetTcpBinding"
closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="00:10:00"
sendTimeout="00:01:00"
transactionFlow="false"
transferMode="Buffered"
transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard"
listenBacklog="10"
maxBufferPoolSize="2147483647"
maxBufferSize="524288"
maxConnections="10"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32"
maxStringContentLength="8192"
maxArrayLength="16384"
maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<reliableSession ordered="true"
inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
</security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="AdminService" behaviorConfiguration="myNetTcpBehaviour">
<endpoint address="AdminSrv"
binding="netTcpBinding"
bindingConfiguration="myNetTcpBinding"
contract="IAdminService"
behaviorConfiguration="myNetTcpEndPointBehaviour"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="/Bus/IRfotoWCF" />
</baseAddresses>
</host>
</service>
<behaviors>
<serviceBehaviors>
<behavior name="myNetTcpBehaviour">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="myNetTcpEndPointBehaviour">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"></serviceHostingEnvironment>
</system.serviceModel>
Now on the client-side configuratioin you need to change the maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
and also you need to add maxItemsInObjectGraph="2147483647" in endpoint behaviour configuration.
<endpointBehaviors>
<behavior name="myEndPointBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</endpointBehaviors>
Now i can transmit 30000 rows within 5.30 min where the query executed for 10 sec so the transmission time is 5.20 min - still a lot.
Feel free to comment and any suggestion for improvement.
If you look at the binding details they do not match entirely on the server and that of the client side. The attributes for maxBufferSize, maxBufferPoolSize, maxReceivedMessageSize are to be defined in the server side as well. And then you need to put the values according to the size you are looking at.
Instead of using for loop over WCF for bulky data , Use user defined table type ( if you are using SQL) . It will reduce the time from 6 min to 15-20 sec.

WCF Service Communication Exception Due to Parameter Size

I've got a WCF Web MEthod that takes in an XElement object as a parameter. For one of my XML files (sized at 600KB or so) this works just fine, however, for this bigger XML file (about 5MB) I get a CommunicationException right away.
I've already increased the message sizes for my binding. Below is the ServiceModel section of my web.config:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="BIMIntegrationWS.metadataBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="BIMIntegrationWS.IntegrationService.customBinding0"
closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:10:00">
<binaryMessageEncoding>
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binaryMessageEncoding>
<httpTransport maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647" />
</binding>
</customBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service name="BIMIntegrationWS.BIMIntegrationWS" behaviorConfiguration="BIMIntegrationWS.metadataBehavior">
<endpoint address="" binding="customBinding" bindingConfiguration="BIMIntegrationWS.IntegrationService.customBinding0"
contract="BIMIntegrationWS.IBIMIntegrationService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
On the client, my ClientConfig looks like this:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CustomBinding_IBIMIntegrationService">
<binaryMessageEncoding />
<httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://localhost:1895/IntegrationService.svc"
binding="customBinding" bindingConfiguration="CustomBinding_IBIMIntegrationService"
contract="BIMIntegrationService.IBIMIntegrationService" name="customBindingEndpoint" />
</client>
</system.serviceModel>
Thanks in advance!
try to add following snippet into your web.config for the service application:
<system.web>
<httpRuntime maxRequestLength="16384" /> <!-- 16MB -->
</system.web>
When you host the service in web server you also have to tweak allowed request size for the web server.
Best regards,
Ladislav
Maybe your XElement has too many nodes/child elements, and you need to set the maxItemsInObjectGraph attribute under dataContractSerializer to something larger?
You probably need to change the values of the attributes of the <readerQuotas /> sub element of <binaryMessageEncoding />.
For more information, see:
http://msdn.microsoft.com/en-us/library/ms731325.aspx
http://forums.silverlight.net/forums/p/88704/205040.aspx
Update:
Can you try to increase the maxAllowedContentLength as described here:
http://social.msdn.microsoft.com/Forums/en/wcf/thread/e6e21132-ad3f-4135-8ab9-77923b099907
Do you know how to turn off VS host and to just deploy to IIS and give it a ping. Normal IIS 7 on your dev box will do just fine. You can still attach debugger etc, just won't have instantaneous F5 gratification but since your ocode is not dying on startup you don't need to see if from the fist line anyway :-)
If you would need to attach very early you could could make a mimimal method that doesn't tounch anything at all and just returns int constnat - just to bring up app pool so you can attach.