WCF Session Configuration error - wcf

i want to enable (SessionMode=SessionMode.Required) in my service, so when i have enabled it then test the service using WCF Client Test it raise the following error:
The message could not be processed. This is most likely because the action 'http://schemas.xmlsoap.org/ws/2004/09/transfer/Get' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.HTTP GET Error
URI: http://localhost:7645/PublisherService.svc
The HTML document does not contain Web service discovery information.
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="myBasicBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" closeTimeout="00:01:00" openTimeout="00:01:00" sendTimeout="00:01:00" receiveTimeout="00:01:00">
<readerQuotas maxDepth="128" maxStringContentLength="8388608" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="2147483647"/>
</binding>
</basicHttpBinding>
<!--enable WSHTTPBinding session-->
<wsHttpBinding>
<binding name="bindingAction" transactionFlow="false" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" sendTimeout="00:01:00" receiveTimeout="00:01:00" closeTimeout="00:01:00" openTimeout="00:01:00">
<readerQuotas maxDepth="128" maxStringContentLength="8388608" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="2147483647"/>
<reliableSession enabled="true"/>
<security mode="Transport">
<message establishSecurityContext="false" clientCredentialType="IssuedToken"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<protocolMapping>
<add scheme="http" binding="wsHttpBinding"/>
</protocolMapping>
<!-- \\\\\\\\\\\\\\\\\\\\\\\\\\\ -->
<services>
<service name="AllChatService.PublisherService" behaviorConfiguration="metadataSupport">
<host>
<baseAddresses>
<add baseAddress ="http://localhost:7645/"/>
</baseAddresses>
</host>
<endpoint contract="AllChatService.PublisherService" binding="wsHttpBinding" address=""/>
<!--Enable Meta Data Publishing-->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="metadataSupport">
<serviceDebug includeExceptionDetailInFaults="False" />
<!--Enable WSDL Data Binding-->
<serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
[ServiceBehaviorAttribute(InstanceContextMode = InstanceContextMode.PerCall)]
public class PublisherService : IPublisher
{
}
[ServiceContract(SessionMode = SessionMode.Required)]
public interface IPublisher
{
}
So can any one help me to solve this problem.

remove the line
<security mode="Transport">
from your web.config file. because Transport seems to require HTTPS to encrypt credentials.

Related

WCF - Return large data set to Client

The goal is to send the contents of a table as a data set to the client. I get an error from the client application:
"The maximum message size quota for incoming messages (65536) has been exceeded."
Although in the same WCF application retrieving large data amount from the client there is no error.
Please see the config file.
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true"/>
<bindings>
<wsHttpBinding>
<binding name="TeansferBinding"
messageEncoding="Mtom"
maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647"
receiveTimeout="00:10:00">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"/>
<!--
For forced HTTPS
change the security mode from None to Transport and add Transport key with clientCredentialType="None"
<security mode="Transport">
<transport clientCredentialType="None"/>
</security
-->
<security mode="None" />
</binding>
<binding name="ProjectBinding"
messageEncoding="Text"
maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647"
receiveTimeout="00:10:00">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"/>
<!--
For forced HTTPS
change the security mode from None to Transport and add Transport key with clientCredentialType="None"
<security mode="Transport">
<transport clientCredentialType="None"/>
</security
-->
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="TransferBehavior">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false"/>
<!-- 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"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="500" maxConcurrentInstances="500"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="TransferBehavior" name="TransferServer.Restore" >
<endpoint address=""
binding="wsHttpBinding"
bindingConfiguration="TeansferBinding"
contract="TransferServer.IRestore"/>
<!-- remove mex endpoint of production server -->
<endpoint address="mex"
binding="mexHttpBinding"
name="Mex"
contract="IMetadataExchange"/>
<host>
<timeouts closeTimeout="00:10:00" openTimeout="00:10:00"/>
</host>
</service>
<service behaviorConfiguration="TransferBehavior" name="TransferServer.ProjectProvider">
<endpoint address=""
binding="wsHttpBinding"
bindingConfiguration="ProjectBinding"
contract="TransferServer.IProjectProvider"/>
<!-- remove mex endpoint of production server -->
<endpoint address="mex"
binding="mexHttpBinding"
name="Mex"
contract="IMetadataExchange"/>
<host>
<timeouts closeTimeout="00:10:00" openTimeout="00:10:00"/>
</host>
</service>
</services>
I've searched for a solution but only come back to the adjustment of the config file. The WCF application is not reporting any error and the client is reporting the error.
I've tried using wsHttpBinding and basicHttpBinding with no success. I've tried MTOM and Text message encoding.
#Abraham Qian
App Config File for Client
Here is the App.Config file for the client.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IRestore" messageEncoding="Mtom">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
<binding name="WSHttpBinding_IProjectProvider">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://myServer.com/Restore.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IRestore"
contract="RestoreProvider.IRestore" name="WSHttpBinding_IRestore" />
<endpoint address="https://myServer.com/ProjectProvider.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IProjectProvider"
contract="ProjectProvider.IProjectProvider" name="WSHttpBinding_IProjectProvider" />
</client>
</system.serviceModel>
</configuration>
As for the binding information for the ProjectProvider service the only difference is "maxBufferSize" which when inserted creates an error.
Usage code in the Client
Public sub GetZips()
'Get the information from Ops
Using oProjectProvider As New ProjectProvider.ProjectProviderClient
MyDataSet = oProjectProvider.GetZipCodeData
oProjectProvider.Close()
End Using
Application.DoEvents()
End sub
I would like to know the client configuration. how do you create a call to the service? We had better apply the configuration on both the client-side and the server-side. Besides, I suspect there is something wrong with the client service endpoint address. Please post the complete client configuration.
In addition, please refer to the below configuration.
<binding maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
Feel free to let me know if the problem still exists.

Max read depth issue when sending objects to WCF service

I am getting the below exception while sending objects to the WCF service, could anyone help me out to resolve this issue.
Exception:
The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:xxxx(class object). The InnerException message was 'There was an error deserializing the object of xxxxx.xx.xxx.xxxx(class). The maximum read depth (200) has been exceeded because XML data being read has more levels of nesting than is allowed by the quota. This quota may be increased by changing the MaxDepth property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 2, position 59349.'. Please see InnerException for more details.
Inner Exception:
The maximum read depth (200) has been exceeded because XML data being read has more levels of nesting than is allowed by the quota. This quota may be increased by changing the MaxDepth property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 2, position 59349.
I have tried by setting the below readerQuotas in bindings both in client and server
<readerQuotas maxDepth="200" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
My Service Configuration:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
<bindings>
<basicHttpBinding>
<binding name="secureHttpBinding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="200" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="mexBehavior" name="Service">
<endpoint address="Service" binding="basicHttpBinding" bindingConfiguration="secureHttpBinding" contract="IService"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/Service"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
My Client Configuration:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService" closeTimeout="00:05:00" openTimeout="00:05:00" receiveTimeout="00:10:00" sendTimeout="00:05:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="200" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:50259/Service.svc/Service"
behaviorConfiguration="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
contract="IService" name="BasicHttpBinding_IService" />
</client>
</system.serviceModel>
Also, I have added maxRequestLength in httpRuntime both in client and service config
<system.web>
<httpRuntime targetFramework="4.6" maxRequestLength="2147483646"/>
</system.web>

Contract requires Session, but Binding 'WSHttpBinding' doesn't support it; 404 with TransportWithMessageCredential

I am trying to enable my WCF service to communicate via HTTPS.
Server config:
<system.serviceModel>
<services>
<service name="PortalServiceLibrary.PortalService" behaviorConfiguration="PortalServiceBehavior">
<endpoint address="" binding="wsHttpBinding" contract="PortalServiceLibrary.IPortalService">
<identity>
<dns value="vmserver"/>
</identity>
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/PortalServiceLibrary/PortalService/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="PortalServiceBehavior">
<serviceMetadata httpsGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="bindingAction" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
</binding>
</wsHttpBinding>
</bindings>
<protocolMapping>
<add scheme="http" binding="wsHttpBinding"/>
<add scheme="https" binding="wsHttpBinding"/>
</protocolMapping>
</system.serviceModel>
Client Config:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IPortalService" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32" maxStringContentLength="100000" maxArrayLength="2147483647"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="TransportWithMessageCredential">
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://vmserver/PortalService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IPortalService"
contract="PortalService.IPortalService" name="WSHttpBinding_IPortalService">
</endpoint>
</client>
</system.serviceModel>
When I use:
<security mode="Transport">
I receive the following error:
Contract requires Session, but Binding 'WSHttpBinding' doesn't support it or isn't configured properly to support it.
But when I change it to:
<security mode="TransportWithMessageCredential">
I receive the following exception:
[WebException: The remote server returned an error: (404) Not Found.]
System.Net.HttpWebRequest.GetResponse() +6592536
System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +55
[EndpointNotFoundException: There was no endpoint listening at https://vmserver/PortalService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +10733331
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +336
Portal.PortalService.IPortalService.GetToken(TokenRequest request) +0
...
I'm really not sure what direction to go in here as I appear quite stuck. Any help will be greatly appreciated.
First of all,
The <wsHttpBinding> bindings specified in your Client config is different from what is specified in your service config.
Please copy the bindings from your client config and paste it in your service config.
<wsHttpBinding>
<binding name="WSHttpBinding_IPortalService" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32" maxStringContentLength="100000" maxArrayLength="2147483647"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="TransportWithMessageCredential">
</security>
</binding>
</wsHttpBinding>
Also,
Update your service endpoints (which you have not posted here) to bindingConfiguration="WSHttpBinding_IPortalService" and also the endpoint address.
This should atleast resolve the not found issue.
Hope this helps

WCF call times out when the returned message is large

We have a system where a client flash application is calling an asmx based Search web service which in turn calls a wcf service hosted in a windows service using NetTcpBinding. This is working fine when the no. of search results are small. But when the Search results are going large, in the range of 2000 records, we are getting an exception in the asmx service where it calls the wcf:
`The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.`
In order to troubleshoot the error, we enabled service tracing and found that the error reported is:
`The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:01:00'.`
We have increased the timeout values in both server and client configs and also increased the maxItemsInObjectGraph value. There are no errors happening at the wcf call as we can debug it and the observed behavior is, when the wcf call returns, the code in the asmx service is hitting the exception block and reporting the above error.
Server Side Config:
<system.serviceModel>
<services>
<service name="***.SearchController" behaviorConfiguration="serviceBehavior">
<endpoint address="net.tcp://localhost:8228/SearchController" binding="netTcpBinding" contract="***.ISearch" name="SearchController" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceDebug includeExceptionDetailInFaults="True" />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="LargeMessageBinding"
maxBufferPoolSize="2147483647"
maxBufferSize="2147483647"
maxConnections="2147483647"
maxReceivedMessageSize="2147483647"
portSharingEnabled="false"
transactionFlow="false"
listenBacklog="2147483647"
closeTimeout="infinite"
openTimeout="infinite"
receiveTimeout="infinite"
sendTimeout="infinite">
<security mode="None">
<message clientCredentialType="None"/>
<transport protectionLevel="None" clientCredentialType="None"/>
</security>
<reliableSession enabled="false"/>
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
</netTcpBinding>
</bindings>
<diagnostics wmiProviderEnabled="true">
<messageLogging
logEntireMessage="true"
logMalformedMessages="true"
logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="true"
maxMessagesToLog="3000"
/>
</diagnostics>
<client></client>
Client(axms) Side Config:
<system.serviceModel>
<client>
<endpoint address="net.tcp://localhost:8228/SearchController" binding="netTcpBinding" behaviorConfiguration="endpointBehavior" contract="***.ISearch" name="NewSearch"/>
</client>
<bindings>
<netTcpBinding>
<binding name="LargeMessageBinding"
maxBufferPoolSize="2147483647"
maxBufferSize="2147483647"
maxConnections="2147483647"
maxReceivedMessageSize="2147483647"
portSharingEnabled="false"
transactionFlow="false"
listenBacklog="2147483647"
closeTimeout="infinite"
openTimeout="infinite"
receiveTimeout="infinite"
sendTimeout="infinite">
<security mode="None">
<message clientCredentialType="None"/>
<transport protectionLevel="None" clientCredentialType="None"/>
</security>
<reliableSession enabled="false"/>
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="endpointBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
The code using which the wcf gets called from the asmx service:
List<***.SearchResult> results;
using (var searchFactory = new ChannelFactory<***.ISearch>("NewSearch"))
{
Legacy.ISearch searchProxy = searchFactory.CreateChannel();
results = searchProxy.Search(searchOption);
}
This call is reporting the exception.
We are not sure why we are getting a timeout issue even after increasing the thresholds in the config. Could it be that the service is not picking up our binding config and using some default config values and hence throwing the error. Not sure what is the way to validate if the service has actually picked up our config at runtime.
Need help in troubleshooting this issue.
you must use binding in your application, but you declare it only, use bindingConfiguration property
<endpoint address="net.tcp://localhost:8228/SearchController" binding="netTcpBinding" contract="***.ISearch" name="SearchController" bindingConfiguration="LargeMessageBinding" />
and bindingConfiguration="LargeMessageBinding" to client config too

Wcf service configuration issue

I am getting an issue with WCF service I have created. Issue is not coming on all clients - i.e. on some systems it is working others not.
Error 1:
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.
Error 2:
On some system the operation contract is not exposed properly. A red symbol is coming across operation contract. And unable to call it using wcftestclient.
Config File:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" >
<readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="ExternalService.Service.MyDashboardService">
<host>
<baseAddresses>
<add baseAddress = "http://****/ExternalService.Service/MyDashboardService/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpBinding" contract="ExternalService.ServiceInterface.IMyDashboardService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
Now the client config I am getting in wcftestclient for Error 1:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IMyDashboardService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://****/ExternalService.Service/MyDashboardService/"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyDashboardService"
contract="IMyDashboardService" name="BasicHttpBinding_IMyDashboardService" />
</client>
</system.serviceModel>
</configuration>
Client Config when service is working:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IMyDashboardService" 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://****/ExternalService.Service/MyDashboardService/"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyDashboardService"
contract="IMyDashboardService" name="BasicHttpBinding_IMyDashboardService" />
</client>
</system.serviceModel>
</configuration>
Please suggest what could be the reason for different behavior of service on different machines.
you should use same bindingConfiguration on both sides clients and service