I can't upload files larger than 45 KB using wcf - wcf

My code works perfect for files smaller than 45 Kb but when I upload files large files I get that error:
The remote server returned an error: (400) Bad Request.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.WebException: The remote server returned an error: (400) Bad Request.
Source Error:
Line 120: [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
Line 121: WebApplication2.ServiceReference1.uploadfileResponse WebApplication2.ServiceReference1.IService1.uploadfile(WebApplication2.ServiceReference1.RemoteFileInfo request) {
Line 122: return base.Channel.uploadfile(request);
Line 123: }
Line 124:
Source File: C:\Users\KHALED\documents\visual studio 2010\Projects\WcfServicefiles\WebApplication2\Service References\ServiceReference1\Reference.cs
Line: 122
Stack Trace:
[WebException: The remote server returned an error: (400) Bad Request.]
System.Net.HttpWebRequest.GetResponse() +6115427
System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +48
[ProtocolException: The remote server returned an unexpected response: (400) Bad Request.]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +9455983
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +345
WebApplication2.ServiceReference1.IService1.uploadfile(RemoteFileInfo request) +0
WebApplication2.ServiceReference1.Service1Client.WebApplication2.ServiceReference1.IService1.uploadfile(RemoteFileInfo request) in C:\Users\KHALED\documents\visual studio 2010\Projects\WcfServicefiles\WebApplication2\Service References\ServiceReference1\Reference.cs:122
WebApplication2._Default.Button2_Click(Object sender, EventArgs e) in C:\Users\KHALED\documents\visual studio 2010\Projects\WcfServicefiles\WebApplication2\Default.aspx.cs:38
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
This is my webconfig code for the server:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime maxRequestLength="2097151"
useFullyQualifiedRedirectUrl="true"
executionTimeout="14400"
/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="SomeServiceServiceBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="6553600"/>
<!-- 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 -->
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="Service1"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647" transferMode="Streamed">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
<security mode="None">
<transport clientCredentialType="Ntlm"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="Service1.svc.cs" >
<endpoint address="" binding="basicHttpBinding"
bindingConfiguration="Service1"
contract="IService1" >
</endpoint>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
And this the web.config for the client
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime maxRequestLength="2097150" />
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</providers>
</roleManager>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="SomeServiceServiceBehavior">
<dataContractSerializer maxItemsInObjectGraph="6553600"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="SomeServiceServiceBehavior">
<dataContractSerializer maxItemsInObjectGraph="6553600"/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" closeTimeout="04:01:00"
openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed"
useDefaultWebProxy="true">
<readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/WcfServicefiles/Service1.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
</configuration>

The below section of your servers web.config
<services>
<service name="Service1.svc.cs" >
<endpoint address="" binding="basicHttpBinding"
bindingConfiguration="Service1"
contract="IService1" >
</endpoint>
</service>
</services>
has some values for attributes that are wrong. The value for the name attribute of service element needs to be namespace.Service1 and similarly the contract attribute value of endpoint element needs to be namespace.IService1 as shown below:
<services>
<service name="<namespace>.Service1" >
<endpoint address="" binding="basicHttpBinding"
bindingConfiguration="Service1"
contract="<namespace>.IService1" >
</endpoint>
</service>
</services>
Just replace with the namespace of Service1 class. And that should work

Try follwing this example: http://www.codeproject.com/Articles/166763/WCF-Streaming-Upload-Download-Files-Over-HTTP

Related

WCF - error Security processor was unable to find a security header in the message

I am trying to cal WCF service using SOAP UI and get the following error; not sure what is the wrong.
error:Security processor was unable to find a security header in the message. This might be because the message is an unsecured fault or because there is a binding mismatch between the communicating parties. This can occur if the service is configured for security and the client is not using security.
web.config
<system.serviceModel>
<diagnostics performanceCounters="All">
<messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true"/>
<endToEndTracing propagateActivity="true" messageFlowTracing="true"/>
</diagnostics>
<behaviors>
<serviceBehaviors>
<behavior name="DefaultBehavior">
<!--<serviceThrottling maxConcurrentCalls="100" maxConcurrentInstances="200" maxConcurrentSessions="100"/>-->
<serviceAuthorization principalPermissionMode="Always"/>
<serviceCredentials useIdentityConfiguration="true">
<serviceCertificate findValue="localhost" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/>
<issuedTokenAuthentication audienceUriMode="BearerKeyOnly" certificateValidationMode="PeerOrChainTrust" revocationMode="NoCheck"
trustedStoreLocation="LocalMachine" allowUntrustedRsaIssuers="false"></issuedTokenAuthentication>
</serviceCredentials>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false"/>
<bindings>
<ws2007FederationHttpBinding>
<binding name="wsFedBinding" receiveTimeout="00:10:00" sendTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00"
maxReceivedMessageSize="262144" maxBufferPoolSize="262144">
<readerQuotas maxArrayLength="16384" maxDepth="32" maxStringContentLength="262144" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
<security mode="TransportWithMessageCredential">
<message issuedKeyType="BearerKey" issuedTokenType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0"
negotiateServiceCredential="false" establishSecurityContext="false"/>
</security>
<security mode="None">
<!--<message negotiateServiceCredential="true"></message>-->
</security>
</binding>
</ws2007FederationHttpBinding>
<wsHttpBinding>
<binding name="wsHttpClientServiceBinding" receiveTimeout="00:10:00" sendTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00"
maxReceivedMessageSize="262144" maxBufferPoolSize="262144">
<readerQuotas maxArrayLength="16384" maxDepth="32" maxStringContentLength="262144" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
<security mode="Transport">
<transport clientCredentialType="None"></transport>
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="XXX.Service" behaviorConfiguration="DefaultBehavior">
<host>
<baseAddresses>
<add baseAddress="https://ws40022517..intranet/XXXX.Service/" />
</baseAddresses>
</host>
<endpoint address="" binding="ws2007FederationHttpBinding" bindingConfiguration="wsFedBinding"
contract="XXX.Contract.Vault.ServiceContract.IVaultService"/>
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="false"/>
<httpProtocol>
<customHeaders>
<add name="X-Content-Type-Options" value="nosniff"/>
</customHeaders>
</httpProtocol>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="NHibernate" publicKeyToken="aa95f207798dfdb4" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.3.1.4000" newVersion="3.3.1.4000"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.identityModel>
<identityConfiguration saveBootstrapContext="true">
<issuerNameRegistry type="System.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<trustedIssuers>
<add thumbprint="XXXXC" name="SignCertificate"/>
</trustedIssuers>
</issuerNameRegistry>
<securityTokenHandlers>
<remove type="System.IdentityModel.Tokens.Saml2SecurityTokenHandler, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<add type="XXXX.OcdSaml2SecurityTokenHandler, XXX.WCFExtension"/>
</securityTokenHandlers>
<claimsAuthenticationManager type="XXXX.Security.SoapClaimsAuthenticationManager, XXXX"/>
</identityConfiguration>
</system.identityModel>
If I comment the TranportwithMessagesecurity and add just transport and none then it shows that channel endpoint not found.
Add the following code in webconfig and try it:
<security enableUnsecuredResponse="true"
authenticationMode="MutualCertificateDuplex"
defaultAlgorithmSuite="TripleDesRsa15"
includeTimestamp="false"
messageSecurityVersion="Default" >
</security>

413 Entity too large exception, wcf service

My code crashes with this exception:
An unhandled exception of type 'System.ServiceModel.ProtocolException' occurred in mscorlib.dll
Additional information: The remote server returned an unexpected response: (413) Request Entity Too Large.
This is my web.config file:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="WcfService1.Service1Behavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="WcfService1.CustomValidator, WcfService1"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="WcfService1.Service1" behaviorConfiguration="WcfService1.Service1Behavior" >
<endpoint address="wsHttp" binding="wsHttpBinding" contract="WcfService1.IService1"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses >
<add baseAddress="http://localhost/Service1.svc/wsHttp"/>
</baseAddresses>
</host>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="SafeServiceConf" maxReceivedMessageSize="2147483647">
<readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" />
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
And this is my client app.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="WindowsFormsApplication.Properties.Settings.TestTestConnectionString" connectionString="Data Source=;Initial Catalog=TestTest;Persist Security Info=True;User ID=;Password=" providerName="" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<system.serviceModel>
<client>
<endpoint address="http://localhost/Service1.svc/wsHttp"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
contract="ServiceReference2.IService1" name="WSHttpBinding_IService1">
<identity>
<userPrincipalName value="Administrator" />
</identity>
</endpoint>
</client>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IService1" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" />
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
</configuration>
What am i not seeing?
Thanks in advance for your help.
One problem is that you never assign the binding you defined in your service config to the endpoint, so the service will use the default values for wsHttpBinding. Try assigning the "SafeServiceConf" binding configuration to your endpoint via the bindingConfiguration attribute:
<endpoint address="wsHttp"
binding="wsHttpBinding"
bindingConfiguration="SafeServiceConf"
contract="WcfService1.IService1" />
The service will then use the values you specified rather than the default values.

WCF sql dataset Over 50 records will not save

Have spent over 20 hrs searching the web and still cant get basichttpbinding to save when
has a number of records (okay when a small number of records)
The service Web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="false" strict="false" explicit="true" targetFramework="4.0" />
<pages>
<namespaces>
<add namespace="System.Runtime.Serialization" />
<add namespace="System.ServiceModel" />
<add namespace="System.ServiceModel.Web" />
</namespaces>
</pages>
<httpRuntime executionTimeout="600" maxRequestLength="102400"/>
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="IncidentServiceBehavior" name="NewIncidentService_IService">
<endpoint address=""
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
contract="IncidentServiceReference.ServiceClient" />
<endpoint binding="wsHttpBinding" bindingConfiguration="wsHttpBinding_Incident"
name="" contract="IncidentServiceReference.ServiceClient" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<timeouts closeTimeout="01:10:00" />
</host>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService" closeTimeout="01:10:00"
openTimeout="01:10:00" receiveTimeout="01:10:00" sendTimeout="01:10:00"
hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288"
maxBufferSize="524288" maxReceivedMessageSize="524288" transferMode="Streamed">
<readerQuotas maxDepth="524288" maxStringContentLength="524288"
maxArrayLength="524288" maxBytesPerRead="524288" maxNameTableCharCount="524288" />
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="wsHttpBinding_Incident" maxReceivedMessageSize="524288"
useDefaultWebProxy="false">
<readerQuotas maxDepth="524288" maxStringContentLength="524288"
maxArrayLength="524288" maxBytesPerRead="524288" maxNameTableCharCount="524288" />
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="IncidentServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="524288" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647"/>
</requestFiltering>
</security>
</system.webServer>
</configuration>
The client App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
</startup>
<system.web>
<httpRuntime executionTimeout="600"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService"
maxReceivedMessageSize="524288"
maxBufferSize="524288"
maxBufferPoolSize="524288"
receiveTimeout="01:10:00"
transferMode="Streamed"
sendTimeout="01:10:00"
closeTimeout="01:10:00"
hostNameComparisonMode="StrongWildcard"
openTimeout="01:10:00"
messageEncoding="Text"
textEncoding="utf-8"
allowCookies="false"
bypassProxyOnLocal="false"
useDefaultWebProxy="false">
<security mode="None">
<transport clientCredentialType="None"
proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName"
algorithmSuite="Default"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="IncidentServiceBehavior">
<dataContractSerializer maxItemsInObjectGraph="524288"/>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="---Removed for security-----"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
contract="IncidentServiceReference.IService" name="BasicHttpBinding_IService" behaviorConfiguration="IncidentServiceBehavior" />
</client>
</system.serviceModel>
</configuration>
Has a 413 error - changed to streamed, now get a 400. Error from WCF Test Client
The remote server returned an unexpected response: (400) Bad Request.
Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory`1 factory, WebException responseException, ChannelBinding channelBinding)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at IService.saveTasks(saveTasksRequest request)
at ServiceClient.IService.saveTasks(saveTasksRequest request)
Inner Exception:
The remote server returned an error: (400) Bad Request.
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
Yes it appears to be a time out, any changes not affect. Have added a timeout in the connectionstring and in IIS 7.0 have added 'serverruntime uploadreadaheadsize="20480000" '
any thoughts would be appreciated
Andrew
May have a solution for this.
Found this
binding name="" openTimeout="00:10:00" closeTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" maxBufferSize="2147483647">
at this site
http://www.codeproject.com/Questions/481526/Theplusremoteplusserverplusreturnedplusanplusunexp
Needs to before any other basichttpbinding and note that there is no name. I think this set the default values. have set up a test to see if it work and has not failed yet. I will (when time permits) change the values from 2gigs to lower values.
Hope this helps anyone with a similar issue.
Andrew

WCF File Upload Large File

I've been doing a fair bit of research over the last two days to find a solution to my problem but to no avail.
I have created a WCF service like so:
[OperationContract]
void CopyMemberFile(string memberNumber, string fileName, byte[] fileBytes);
And I call it from my client like so from a page_load event:
byte[] filebytes = null;
using (Stream fs = new FileStream(file, FileMode.Open, FileAccess.Read))
{
filebytes = new byte[fs.Length];
fs.Read(filebytes, (int)0, (int)fs.Length);
}
client.CopyMemberFile(memberNumber, Path.GetFileName(file), filebytes);
My configuration is like so:
Client Config:
<configuration>
<system.web>
<authorization>
<allow users="*"/>
</authorization>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Speech, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="300" cookieless="UseUri" />
</authentication>
<membership>
<providers>
<clear />
<add name="AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="ApplicationServices"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
<profile>
<properties>
<add name="FirstName"/>
<add name="LastName"/>
<add name="MemberNumber"/>
<add name="LastVisit" type="System.DateTime"/>
</properties>
<providers>
<clear />
<add name="AspNetSqlProfileProvider"
type="System.Web.Profile.SqlProfileProvider"
connectionStringName="ApplicationServices"
applicationName="/" />
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear />
<add name="AspNetSqlRoleProvider"
type="System.Web.Security.SqlRoleProvider"
connectionStringName="ApplicationServices"
applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider"
type="System.Web.Security.WindowsTokenRoleProvider"
applicationName="/" />
</providers>
</roleManager>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false"
type="System.Web.Script.Services.ScriptHandlerFactory" />
<add path="Telerik.Web.UI.WebResource.axd"
type="Telerik.Web.UI.WebResource" verb="*" validate="false" />
</httpHandlers>
<httpRuntime maxRequestLength="1048576"/>
</system.web>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="online.members.asp.Services.MembersOnlineSeviceAjaxAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="online.members.asp.Services.MembersOnlineSeviceAjax">
<endpoint address="" behaviorConfiguration="online.members.asp.Services.MembersOnlineSeviceAjaxAspNetAjaxBehavior"
binding="webHttpBinding"
contract="online.members.asp.Services.MembersOnlineSeviceAjax" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IMembershipApplications"
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="128"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None"
proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName"
algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:58119/MembershipApplications.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IMembershipApplications"
contract="MembershipApplicationsServiceReference.IMembershipApplications"
name="BasicHttpBinding_IMembershipApplications" />
</client>
</system.serviceModel>
Service Config:
<configuration>
<system.web>
<roleManager enabled="true" />
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
The error I'm getting is this:
3/02/2013 11:12:39 AM: Upload.aspx Error: The remote server returned an unexpect
ed response: (400) Bad Request.
Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResp
onse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factor
y, WebException responseException, ChannelBinding channelBinding)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpCha
nnelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeS
pan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message messag
e, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean on
eway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan tim
eout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCall
Message methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage req
Msg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgDa
ta, Int32 type)
at online.members.asp.MembershipApplicationsServiceReference.IMembershipAppli
cations.CopyMemberFile(String memberNumber, String fileName, Byte[] fileBytes)`
I can upload files at only a few KB each but any larger than say 8KB and thing just fails
Any help would be fantastic.
Calling code:
protected void Page_Load(object sender, EventArgs e)
{
var file = Request.Form["name"];
var memberNumber = Request.Form["memberNumber"];
var tempId = Guid.NewGuid();
var client = new MembershipApplicationsServiceReference.MembershipApplicationsClient();
client.LogEvent("Entered Upload.aspx");
try
{
byte[] filebytes = null;
using (Stream fs = new FileStream(file, FileMode.Open, FileAccess.Read))
{
filebytes = new byte[fs.Length];
fs.Read(filebytes, (int)0, (int)fs.Length);
client.LogEvent("Starting service call from Upload.aspx");
client.CopyMemberFile(memberNumber, Path.GetFileName(file), filebytes);
}
client.LogEvent("Completed service call from Upload.aspx");
}
catch (Exception ex)
{
Debug.WriteLine(ex.StackTrace);
client.LogEvent("Upload.aspx Error: " + ex.Message + ex.StackTrace);
StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
}
finally
{
client.LogEvent("Finishing up");
}
}
Looking at your service's config file, you're using .NET 4.0 and you're not specifying any binding, so you're going to receive the default settings for basicHttpBinding. As suggested in the comments above, update your config file for your service like this:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IMembershipApplications"
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="128"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None"
proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName"
algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="YourServiceName">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IMembershipApplications"
contract="YourFullyQualifiedContractName" />
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
This will tell WCF to use your settings for the basicHttpBinding rather than the .NET defaults.
Alternatively, you can omit the name attribute on the binding definition and WCF will use it as the default binding for all services handled by the config file (if you have more than one).
If that doesn't help, or if you're getting a different error now, let us know and we'll take it from there.

WCF Service : There was no channel that could accept the message with action

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.