We are getting following exception in the .svclog file generated through system diagnostics config settings at server side.
Exception: System.ServiceModel.ProtocolException
Message: The number of bytes available is inconsistent with the HTTP Content-Length
header. There may have been a network error or the client may be
sending invalid requests.
We have observed that the data sent by WCF client is broken. We came to know about this by viewing the message xml in the .svclog file generated at WCF client side.
Actually we are sending data large data by dividing it into small chunks calling the WCF service method to send data in a loop. Following is the code for the same at WCF client side.
DataTable dtStockDetails = new DataTable("StockDetails");
sqlDataAdapter.Fill(dtStockDetails);
int stockDetailsBatchSize = 100;
DataTable dtStockDetailsBatch = dtStockDetails.Clone();
DataRow dr;
int stockDetailsBatchCount = 0;
int stockDetailsTotalRecords = dtStockDetails.Rows.Count;
while (dtStockDetails.Rows.Count > 0)
{
dr = dtStockDetails.Rows[0];
dtStockDetailsBatch.ImportRow(dr);
dtStockDetailsBatch.AcceptChanges();
dtStockDetails.Rows.Remove(dr);
dtStockDetails.AcceptChanges();
if ((dtStockDetailsBatch.Rows.Count == stockDetailsBatchSize) || (dtStockDetails.Rows.Count == 0))
{
stockDetailsBatchCount++;
sendStockDetailsResult = serviceClient.SendStockDetails(dtStockDetailsBatch);
dtStockDetailsBatch.Clear();
}
}
Now WCF client some times sends 7 batches of data, some times sends 9 batches of data, some times sends 10 batches of data, .... . In all cases lase message(data batch) xml gets corrupted. This behavior is random.
We are not sure why the message xml is getting corrupted and resulting into end of communication. It never sends all batches of data.
Following are config settings:
WCF Service config settings:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<service behaviorConfiguration="InventoryServices.InventoryImportServiceBehavior"
name="InventoryServices.InventoryImportService">
<endpoint address="https://www.domain.com/InventoryServices/InventoryImportService.svc" behaviorConfiguration="wsServiceEndpointBehavior"
binding="wsHttpBinding" bindingConfiguration="b1" contract="InventoryServices.IInventoryImportService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="https://www.domain.com" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="b1" closeTimeout="00:30:00" openTimeout="00:30:00"
receiveTimeout="00:30:00" sendTimeout="00:30:00" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<reliableSession inactivityTimeout="00:30:00" />
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Certificate">
</transport>
<message clientCredentialType="UserName" negotiateServiceCredential="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="wsServiceEndpointBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="InventoryServices.InventoryImportServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<serviceCertificate findValue="XyzClient" x509FindType="FindBySubjectName" />
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="InventoryServices.Helpers.CustomValidator, InventoryServices" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
WCF Client config settings:
<system.serviceModel>
<diagnostics>
<messageLogging logEntireMessage="true" logMalformedMessages="true"
logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true"
maxSizeOfMessageToLog="2147483647" />
</diagnostics>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IInventoryImportService"
closeTimeout="00:30:00" openTimeout="00:30:00" receiveTimeout="00:30:00"
sendTimeout="00:30:00" bypassProxyOnLocal="false" transactionFlow="false"
hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288"
maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8"
useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:30:00"
enabled="false" />
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="">
<extendedProtectionPolicy policyEnforcement="Never" />
</transport>
<message clientCredentialType="UserName" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://www.domain.com/InventoryServices/InventoryImportService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IInventoryImportService"
contract="InventoryImportService.IInventoryImportService"
name="WSHttpBinding_IInventoryImportService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Verbose, ActivityTracing"
propagateActivity="false">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="sharedListener">
<filter type="" />
</add>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="Verbose">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="sharedListener">
<filter type="" />
</add>
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="C:\Program Files\InventoryExportUtilitySetup\servicetrace.svclog"
type="System.Diagnostics.XmlWriterTraceListener" name="sharedListener">
<filter type="" />
</add>
</sharedListeners>
</system.diagnostics>
Can any one please suggest what should we do to resolve this problem?
Thanks in advance.
Looking at your configuration the Reader Quotas settings on Server and Client are different.
Make sure you have large values mostly same on client and server.
Just wanted to know if you have tried sending in any small payload data to make sure that the service is working fine?
I also noticed that you have your security set to "TransportWithMessageCredential" and you have the mex endpoint with mexHttpBinding. I guess that should have been mexHttpsBinding and also your httpGetEnabled attribute is set to true where as it should have been httpsGetEnabled to true.
Related
I have created WCF and Web Api REST full web services. In this web services i am getting
for Large data transmission.
EX: I have 25 columns and 25000 rows of fetch query in this scenario some times data is coming and some time
this error is coming in both of them.
My WCF Config. Like this
So can anyone suggest me on this.
Try set in web config reader quoata for binding
defualt is small for large transmision
Details : http://msdn.microsoft.com/en-us/library/ms731325(v=vs.110).aspx
Example
<binding name="myLargeBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" maxArrayLength="2147483647"/>
</binding>
Then don't forget set this bindningConfiguration to endpoint(s)
<endpoint .... binding="basicHttpBinding" bindingConfiguration="myLargeBinding" .... >
For your web.config it should be something like this.
I've created new binding configuration "RESTBinding" and set it to your endpoint.
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" />
<httpRuntime maxRequestLength ="1048576"/>
</system.web>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"></serviceHostingEnvironment>
<services>
<service behaviorConfiguration="" name="wcfTestHC.TestHC">
<endpoint address="" behaviorConfiguration="RestEndpointBehavior" binding="webHttpBinding" bindingConfiguration="RESTBinding" contract="wcfTestHC.ITestHC" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="RestEndpointBehavior">
<webHttp helpEnabled="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Default">
<serviceMetadata httpGetEnabled="true" />
<serviceThrottling maxConcurrentCalls="250" maxConcurrentInstances="75" maxConcurrentSessions="50"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="RESTBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00"
sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"
useDefaultWebProxy="true">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" maxArrayLength="2147483647"/>
</binding>
</webHttpBinding>
<wsHttpBinding>
<binding name="EndpointBehavior" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00"
sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8"
useDefaultWebProxy="true">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" maxArrayLength="2147483647"/>
<reliableSession enabled="True" ordered ="True "/>
</binding>
</wsHttpBinding>
</bindings>
<diagnostics>
<messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" maxMessagesToLog="3000" />
</diagnostics>
</system.serviceModel>
<system.diagnostics>
<switches>
<add name="XmlSerialization.Compilation" value="4"/>
</switches>
<sources>
<source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
<listeners>
<add name="xml" />
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="xml" />
</listeners>
</source>
</sources>
<sharedListeners>
<add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\temp\WCFLoging.svclog" />
</sharedListeners>
</system.diagnostics>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength ="1073741824"></requestLimits>
</requestFiltering>
</security>
</system.webServer>
</configuration>
If you still getting a error. Maybe problem is somewhere else.
Try insert these settings to your web.config. This will provide you a detailed logging and exceptions details for your service and there we will see what problem is. I've set a location for logs to c:\temp\WCFLoging.svclog, plese change it if you want and I've edited a example of web.config with these settings - copy and paste ready :-)
<system.serviceModel>
<diagnostics>
<messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" maxMessagesToLog="3000" />
</diagnostics>
</system.serviceModel>
and
<system.diagnostics>
<switches>
<add name="XmlSerialization.Compilation" value="4"/>
</switches>
<sources>
<source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
<listeners>
<add name="xml" />
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="xml" />
</listeners>
</source>
</sources>
<sharedListeners>
<add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\temp\WCFLoging.svclog" />
</sharedListeners>
</system.diagnostics>
I've been searching this problem, and I found similar problems posted by other users, but everything I've tried doesn't work, The problem is that I'm using a WCF service hosted on IIS, and a client that try to upload a serialized image on a string, the size of the image is 9mb aprox, everythin else works fine, I can send data without problem except the image.
I have enabled tracelog and the error message says that the MaxReceivedMessageSize exceed
Here is my config on service:
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true" >
<listeners>
<add name="xml"/>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="xml"/>
</listeners>
</source>
<source name="myUserTraceSource"
switchValue="Information, ActivityTracing, All">
<listeners>
<add name="xml"/>
</listeners>
</source>
</sources>
<trace autoflush="true" />
<sharedListeners>
<add name="xml"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="ErrorSvcLog.svclog" />
</sharedListeners>
</system.diagnostics>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IServicioSalud" closeTimeout="10:01:00"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" openTimeout="10:01:00"
receiveTimeout="10:10:00" sendTimeout="10:01:00"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="ServiceBehavior" name="ServicioSalud">
<endpoint address="" binding="basicHttpBinding" contract="IServicioSalud" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="200000" />
</behavior>
</serviceBehaviors>
</behaviors>
<diagnostics>
<messageLogging
logEntireMessage="true"
logMalformedMessages="false"
logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="false"
maxMessagesToLog="3000"
maxSizeOfMessageToLog="2000"/>
</diagnostics>
</system.serviceModel>
</configuration>
And the client config
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IServicioSalud" closeTimeout="10:01:00"
openTimeout="10:01:00" receiveTimeout="10:10:00" sendTimeout="10:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true"
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="4096" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://xxx.xxx.x.xxx:xxxx/wcfservicesalud/Service.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IServicioSalud"
contract="IServicioSalud" name="BasicHttpBinding_IServicioSalud" />
</client>
</system.serviceModel>
In your config file you have not assigned the binding configuration you created, so the default values for BasicHttpBinding are being used. You need to explicitly assign the binding you defined (BasicHttpBinding_IServicioSalud) to your endpoint, like this:
<endpoint address="" bindingConfiguration="BasicHttpBinding_IServicioSalud" binding="basicHttpBinding" contract="IServicioSalud" />
Do this for your service config, as the service needs to be set to accept larger data.
This is my version. Make sure you have have the bindingConfiguration specified in the service you want. In my case I have to specify the name basicHttpBinding.
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding" maxBufferSize="64000000" maxReceivedMessageSize="64000000" maxBufferPoolSize="64000000">
<readerQuotas maxDepth="64000000" maxStringContentLength="64000000" maxArrayLength="64000000" maxBytesPerRead="64000000" />
<security mode="None"/>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="WS.Service1Behavior" name="WS.EasyStockWS">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpBinding" contract="WS.IEasyStockWS">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
For me, the cause was the fact that in my request I had not set the content type.
The server did not provide a meaningful reply this might be caused by
a contract mismath, a premature session shutdown or an internal server
error
Hey, I got an exception after calling a wcf service. I know this exception can get found a lot on stackoverflow, but I have a special behaviour. I also tried nearly all solution which are recommended, without success...
My project does the following: The module is like a normal chat, a wpf and asp usercontrol calls the service every 5 seconds and gets the online users. this normally worked fine on my windows 7 workstation. After I started to develope software on my new workstation with win 8 on it, I got this exception. The IIS Configuration are still the same. After the first user starts to frequently call the service everything works, until a second user calls the same service the exception above shows up.
I set up a testmachine on win 7 and look what happens... Everything works again... I don't have a clue what to do ...
Service web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchName="Information, ActivityTracing" propagateActivity="true">
<listeners>
<add name="xml" />
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="xml" />
</listeners>
</source>
<source name="myUserTraceSource" switchName="Information, ActivityTracing">
<listeners>
<add name="xml" />
</listeners>
</source>
</sources>
<sharedListeners>
<add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="hi5.PSA.ServiceLog.svclog" />
</sharedListeners>
</system.diagnostics>
<appSettings>
<add key="Log4NetPath" value="config.log4net" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />
<!-- that many MB should be enough :) -->
<httpRuntime maxRequestLength="2147483647" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IPmiLookup" />
</basicHttpBinding>
</bindings>
<services>
<service name="SolutionName.ChatService" behaviorConfiguration="chatServiceBehavior">
<endpoint address="" binding="wsDualHttpBinding" contract="SolutionName.contracts.Chat.IChatManager" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="chatServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"></modules>
</system.webServer>
<connectionStrings>
<add name="MyEntities" connectionString="metadata=res://*/Users.csdl|res://*/Users.ssdl|res://*/Users.msl;provider=System.Data.SqlClient;provider connection string="Data Source=localhost;Initial Catalog=MyDB;Integrated Security=SSPI;MultipleActiveResultSets=True"
" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
Client app.config:
<system.serviceModel>
<bindings>
<wsDualHttpBinding>
<binding name="WSDualHttpBinding_IChatManager" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" />
<security mode="Message">
<message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default" />
</security>
</binding>
</wsDualHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/SolutionName/ChatService.svc" binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IChatManager" contract="hi5.medview.server.contracts.Chat.IChatManager" name="WSDualHttpBinding_ChatManager">
<identity>
<servicePrincipalName value="host/MyName"/>
</identity>
</endpoint>
</client>
Does anyone has any idea. The thing which makes me crazy is that, the service works fine for the first user who is calling it, but after a second user calls it, the damn thing doesn't work anymore...
Please help...
Thx
I have a problem at hand where I get the message:
"There was no channel that could accept the message with action."
on the server side and
"The message could not be processed. This is most likely because the action."
on the client side.
I am invoking my WCF Service from a Windows service and I have hosted my WCF service in ISS on a server.
All this is working fine on my localhost. I think I am missing something in the configuration.
My Web.config looks like this:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<appSettings>
<add key="FileTransferPath" value="c:\FileServer\"/>
<add key="BackUpFileTransferPath" value="c:\BackedUpFiles\"/>
<add key="DBPath" value="C:\ProjectsSVN\Acso.accdb"/>
</appSettings>
<system.serviceModel>
<services>
<service name="FileTransfer.FileTransfer">
<endpoint address="" binding="wsHttpBinding" contract="FileTransfer.IFileTransfer">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:65051/FileTransfer/" />
</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="False" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="WSHttpBinding_IFileTransfer"
maxReceivedMessageSize="2147483647">
<readerQuotas
maxDepth="64"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="4096"
maxNameTableCharCount="16384"/>
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<!--Turn on to log Trace-->
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "c:\logs\FileTransferTraces.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
</configuration>
My App.config looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="cs"
connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\ProjectsSVN\Acso.accdb;Persist Security Info=True"
providerName="System.Data.OleDb" />
<add name="csc"
connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\ProjectsSVN\AcsoGPClient.accdb;Persist Security Info=True"
providerName="System.Data.OleDb" />
</connectionStrings>
<appSettings>
<add key="FromEmail" value="abc#igi.com.au"/>
<add key="Subject" value="Your Password"/>
<add key="DBPath" value="C:\Program Files\Default Company Name\GPWindowServiceSetup\AccersoGPClient.accdb"/>
</appSettings>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService11" 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://ws2008.igi.aus/AcsoService/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService11" contract="AccersoService.IService1"
name="BasicHttpBinding_IService11" />
</client>
</system.serviceModel>
</configuration>
Try to make the client binding definition <basicHttpBinding/> an exact copy of the same definition from the service config.
I am trying to create a WCF service that uses certificate authentication over SSL to create a Business to Business gateway. I have created a CA and a client certificate and put them in the Trusted root and personal folders respectively. I have set up the SSL routing but I keep getting the following error ‘The security protocol cannot verify the incoming message.’ And I can’t figure out why.
Below is my service configuration:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="B2BGateway.SSOBackChannel" behaviorConfiguration="B2B">
<endpoint binding="wsHttpBinding"
bindingConfiguration="WSCertificateSecurity"
contract="B2BGateway.Contracts.ISSOBackChannel"
address="https://blah.com/SSOBackChannel.svc"></endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="B2B">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<serviceCertificate />
<clientCertificate>
<authentication certificateValidationMode="PeerTrust" />
</clientCertificate>
</serviceCredentials>
<serviceAuthorization principalPermissionMode="None"></serviceAuthorization>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="B2B">
<clientCredentials>
<clientCertificate findValue="2e2ecba0f33265085cc53cb53c0b00977aaa9e9e" storeName="My" storeLocation="LocalMachine" x509FindType="FindByThumbprint" />
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="WSCertificateSecurity">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="Certificate" />
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
<system.diagnostics>
<sources>
<!-- See here for recommended diagnostics settings: http://msdn.microsoft.com/en-us/library/aa702726.aspx -->
<source name="System.ServiceModel" switchValue="Warning,Information,ActivityTracing,Verbose" propagateActivity="true">
<listeners>
<add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="d:\logs\gah.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
<system.webServer>
<directoryBrowse enabled="true" />
</system.webServer>
</configuration>
And the client configuration is just the autogenerated code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_ISSOBackChannel" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Certificate" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://blah.com/SSOBackChannel.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ISSOBackChannel"
contract="SSOBackChannelService.ISSOBackChannel" name="WSHttpBinding_ISSOBackChannel" />
</client>
</system.serviceModel>
</configuration>
I wrote a unit test to see if the thing works which is where I’m getting the error...
[TestMethod]
public void Should_Call_Service_As_Machine_Does_Have_x509Certificate()
{
SSOBackChannelClient service = new SSOBackChannelClient();;
service.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindByThumbprint, "2e2ecba0f33265085cc53cb53c0b00977aaa9e9e");
var result = service.CheckBackChannelToken("123456789");
}
Any help would be so greatly appreciated!!
Josh
You are using wsHttpBinding but you havent specified the certificate it needs to use to secure your transport channel. Try to specify a certificate it needs to use. i.e. for SSL
Also try enabling tracing on your service. See here how to enable tracing.