consume WCF in asp.net error - asp.net

I consumed wcf by adding service reference to my project then I changed the web.confing to be like that
<?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>
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.;initial catalog=Services;user id=sa;password=123;Connect Timeout=45;"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<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>
<services>
<service name="DreamServices.DreamService">
<endpoint address="" binding="webHttpBinding" contract="DreamServices.IServices" behaviorConfiguration="web">
</endpoint>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="defaultRest">
<readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="64" maxNameTableCharCount="2147483647" />
<security mode="None" />
</binding>
</webHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<appSettings>
<add key="JsonWebService" value="http://localhost:1381/PMAHost/Service.svc" />
</appSettings>
</configuration>
but I always get the exception
Could not find default endpoint element that references contract 'ServiceReference.IServices' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
the module system.serviceModel is repeated either in the library or the site
any idea how to fix that

This is a service-side configuration
<service name="DreamServices.DreamService">
What does the client-side configuration look like? It should have a client element with contract="DreamServices.IServices" or whatever the name of your contract is.

Related

WCF weHttpBinding - specifies multiple request body parameters to be serialized without any wrapper elements

i have searched the forum for a while now and tried a few different things, but i still am not able to call run the WCF from IIS5.
I set up passthrough auth.
Authentication IIS 7.5 settings
Here is the ASP.NET app weconfig:
<system.web>
<sessionState timeout="2000"></sessionState>
<compilation strict="false" explicit="true" targetFramework="4.0" />
<authentication mode="Windows" />
<authorization>
<allow users="d_torreggiani" />
<deny users="*, ?" />
<!-- explicitly deny all others, including anonymous -->
</authorization>
<!--
<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>
<customErrors mode="Off" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="webHttp">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<!--
<behaviors>
<endpointBehaviors>
<behavior name="webHttp">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
-->
<bindings>
<!--
<wsHttpBinding>
<binding name="wsHttpBinding_ISER_ProjectStructure" sendTimeout="00:25:00">
<security mode="Transport">
<transport clientCredentialType="Windows"/>
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
<basicHttpBinding>
<binding name="BasicHttpBinding_ISER_ProjectStructure" sendTimeout="00:25:00">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows"/>
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
-->
<webHttpBinding >
<binding name="WebHttpBinding_ISER_ProjectStructure" sendTimeout="00:25:00" >
<security mode="TransportCredentialOnly" >
<transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
<!--<message clientCredentialType="UserName" algorithmSuite="Default" />-->
</security>
</binding>
</webHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8085/SER_ProjectStructure.svc" binding="webHttpBinding" bindingConfiguration="WebHttpBinding_ISER_ProjectStructure" contract="SER_ProjectStructureRef.ISER_ProjectStructure" name="WebHttpBinding_ISER_ProjectStructure" behaviorConfiguration="webHttp"/>
</client>
</system.serviceModel>
</configuration>
and here is the WCF service web.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation strict="false" explicit="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<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>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
and here is the contract declaration
<ServiceContract()>
Public Interface ISER_ProjectStructure
<OperationContract()> _
<WebInvoke(BodyStyle:=WebMessageBodyStyle.WrappedRequest, Method:="POST", ResponseFormat:=WebMessageFormat.Json)> _
Function RunProcedure(ByVal pPath As String, ByVal pProjectName As String) As Result
End Interface
On my development machine it works just fine, but when i publish it i keep getting this error:
Operation 'RunProcedure' of contract 'ISER_ProjectStructure' specifies
multiple request body parameters to be serialized without any wrapper
elements. At most one body parameter can be serialized without wrapper
elements. Either remove the extra body parameters or set the BodyStyle
property on the WebGetAttribute/WebInvokeAttribute to Wrapped.
with this stack:
[InvalidOperationException: Operation 'RunProcedure' of contract 'ISER_ProjectStructure' specifies multiple request body parameters to be serialized without any wrapper elements. At most one body parameter can be serialized without wrapper elements. Either remove the extra body parameters or set the BodyStyle property on the WebGetAttribute/WebInvokeAttribute to Wrapped.]
System.ServiceModel.Description.WebHttpBehavior.TryGetNonMessageParameterType(MessageDescription message, OperationDescription declaringOperation, Boolean isRequest, Type& type) +972660
System.ServiceModel.Description.WebHttpBehavior.ValidateBodyStyle(OperationDescription operation, Boolean request) +209
System.ServiceModel.Description.<>c__DisplayClassa.<GetRequestClientFormatter>b__4() +83
System.ServiceModel.Description.<>c__DisplayClass7.<GetRequestClientFormatter>b__3() +244
System.ServiceModel.Description.WebHttpBehavior.GetRequestClientFormatter(OperationDescription operationDescription, ServiceEndpoint endpoint) +435
System.ServiceModel.Description.WebHttpBehavior.ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime) +321
System.ServiceModel.Description.DispatcherBuilder.ApplyClientBehavior(ServiceEndpoint serviceEndpoint, ClientRuntime clientRuntime) +259
System.ServiceModel.Description.DispatcherBuilder.BuildProxyBehavior(ServiceEndpoint serviceEndpoint, BindingParameterCollection& parameters) +432
System.ServiceModel.Channels.ServiceChannelFactory.BuildChannelFactory(ServiceEndpoint serviceEndpoint, Boolean useActiveAutoClose) +102
System.ServiceModel.ChannelFactory.CreateFactory() +46
System.ServiceModel.ChannelFactory.OnOpening() +86
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +570
System.ServiceModel.ChannelFactory.EnsureOpened() +117
System.ServiceModel.ChannelFactory`1.CreateChannel(EndpointAddress address, Uri via) +477
System.ServiceModel.ClientBase`1.CreateChannel() +58
System.ServiceModel.ClientBase`1.CreateChannelInternal() +48
System.ServiceModel.ClientBase`1.get_Channel() +464
WebInterfaceProjectStructureRoot._Default.Button1_Click(Object sender, EventArgs e) in C:\Users\d_torreggiani\Documents\Visual Studio 2010\Projects\USProjectStructure\WebApplication1\Default.aspx.vb:18
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +155
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3804
What can it be, i do not understand.
Thanks in advance for any hint.
AFAIK if you are using 'wrappedrequest' you should have only a single entity containing the input properties.
So you should create a DTO class having input properties,then you should pass this instance of class in wcf method.

Hosting a WCF service in a Windows service

Good day
I want to host a WCF service in a Windows service and as such I am following the tutorial: http://msdn.microsoft.com/en-us/library/ff649818.aspx
During "Step 8: Add a WCF Service Reference to the Client" I get the following errors:
Could not connect to net.tcp://localhost:100/Triggers.
The connection attempt lasted for a time span of 00:00:02.0058550.
TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:100
I tried most if not all of the solutions mentioned on the following site: http://social.msdn.microsoft.com/forums/en-US/wcf/thread/58e420e9-43a3-4119-b541-d18158038e36/
with no avail.
Can someone please shine some light on this matter please?
Following is the WCF config file:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<!-- <add name="ABSAConnectionString" connectionString="Data Source=192.168.0.18;Initial Catalog=ABSA;Integrated Security=False;user=Wimpie;password=menschen;" -->
<!-- Charlene -->
<!--<add name="ABSAConnectionString" connectionString="Data Source=ik-charlene\SQL2008;Initial Catalog=ABSA;Integrated Security=True" providerName="System.Data.SqlClient" />-->
<add name="ABSAConnectionString" connectionString="Data Source=.\;Initial Catalog=ABSANICO;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Forms"/>
<authorization>
<!--<deny users="?"/>-->
<allow users="?"/>
</authorization>
<membership defaultProvider="Membership">
<providers>
<clear/>
<add name="Membership" type="ABSAService.Membership"/>
</providers>
</membership>
</system.web>
<system.serviceModel>
<services>
<service name="ABSAService.Triggers" behaviorConfiguration="ABSAService.TriggersBehavior" >
<endpoint address="" binding="netTcpBinding" bindingConfiguration="" contract="ABSAService.ITriggers">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:100/Triggers" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ABSAService.TriggersBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
<listeners>
<add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData= "c:\log\Traces.svclog" />
</listeners>
</source>
<source name="CardSpace">
<listeners>
<add name="xml" />
</listeners>
</source>
<source name="System.IO.Log">
<listeners>
<add name="xml" />
</listeners>
</source>
<source name="System.Runtime.Serialization">
<listeners>
<add name="xml" />
</listeners>
</source>
<source name="System.IdentityModel">
<listeners>
<add name="xml" />
</listeners>
</source>
<source name="UserTraceSource" switchValue="Warning, ActivityTracing" >
<listeners>
<add name="xml"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="C:\logs\UserTraces.svclog" />
</listeners>
</source>
</sources>
<trace autoflush="true" />
<sharedListeners>
<add name="xml"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="c:\log\Traces.svclog" />
</sharedListeners>
</system.diagnostics>
</configuration>
Next is the Windows service config file (which is the same as above according to tutorial):
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<!-- <add name="ABSAConnectionString" connectionString="Data Source=192.168.0.18;Initial Catalog=ABSA;Integrated Security=False;user=Wimpie;password=menschen;" -->
<!-- Charlene -->
<!--<add name="ABSAConnectionString" connectionString="Data Source=ik-charlene\SQL2008;Initial Catalog=ABSA;Integrated Security=True" providerName="System.Data.SqlClient" />-->
<add name="ABSAConnectionString" connectionString="Data Source=.\;Initial Catalog=ABSANICO;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Forms"/>
<authorization>
<!--<deny users="?"/>-->
<allow users="?"/>
</authorization>
<membership defaultProvider="Membership">
<providers>
<clear/>
<add name="Membership" type="ABSAService.Membership"/>
</providers>
</membership>
</system.web>
<system.serviceModel>
<services>
<service name="ABSAService.Triggers" behaviorConfiguration="ABSAService.TriggersBehavior" >
<endpoint address="" binding="netTcpBinding" bindingConfiguration="" contract="ABSAService.ITriggers">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:100/Triggers" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ABSAService.TriggersBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>
Thanks to evgenyl for pointing out that I had to start the Windows Service.
Completely missed this step.

Error with uploading large files to windows azure storage using WCF Service

I have a sample web application through which i am consuming WCF service, which is intended to upload large capacity[upto 50mb] file to azure storage, I am getting error saying The remote server returned an unexpected response: (413) Request Entity Too Large.
This my sample Wcf service code:
Interface [IService1.cs]
namespace FileService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{
[OperationContract]
void UploadFile(Stream inputstream);
}
}
Service1.svc
public class Service1 : IService1
{
public void UploadFile(Stream inputstream)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("images");
// Retrieve reference to a blob named "myblob".
CloudBlockBlob blockBlob = container.GetBlockBlobReference("testfile");
blockBlob.UploadFromStream(inputstream);
}
}
Test.aspx page to consume the wcf service
protected void Button1_Click(object sender, EventArgs e)
{
ServiceReference1.IService1 clientUpload = new ServiceReference1.Service1Client();
clientUpload.UploadFile(FileUpload1.FileContent);
}
web.config file in wcf
<?xml version="1.0"?>
<configuration>
<configSections>
</configSections>
<!-- To collect diagnostic traces, uncomment the section below or merge with existing system.diagnostics section.
To persist the traces to storage, update the DiagnosticsConnectionString setting with your storage credentials.
To avoid performance degradation, remember to disable tracing on production deployments.
<system.diagnostics>
<sharedListeners>
<add name="AzureLocalStorage" type="FileService.AzureLocalStorageTraceListener, FileService"/>
</sharedListeners>
<sources>
<source name="System.ServiceModel" switchValue="Verbose, ActivityTracing">
<listeners>
<add name="AzureLocalStorage"/>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="Verbose">
<listeners>
<add name="AzureLocalStorage"/>
</listeners>
</source>
</sources>
</system.diagnostics> -->
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" transferMode="Streamed" >
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="None">
</security>
</binding>
</basicHttpBinding>
</bindings>
<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>
<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>
web.config File in web application
<?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>
<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>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" maxReceivedMessageSize="2147483647" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:50980/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
</configuration>
In your web.config check the binding you are using and in the transport section, add the maxReceivedMessageSize.
For instance if you are using httpTransport.
<httpTransport maxReceivedMessageSize="2147483647"/>

Large images with wcf - ThrowMaxReceivedMessageSizeExceeded()

I've created a WCF Service to upload images.
It works fine with vary small images.
But when I try it with image like 800KB I get
"The remote server returned an error: (400) Bad Request."
When I look on the log file I see this exception: ThrowMaxReceivedMessageSizeExceeded()
I've been looking for ages and tried lots of different things, including setting the maxRequestLength and several other settings.
I have WCFApp, WebApplocation-for my site, and classLibrary-for the BLClient that has the service referece.
These are my config files:
Web.config of the WCFApplication:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="photoShopEntities"
connectionString="metadata=res://*/photoShop.csdl|
res://*/photoShop.ssdl|
res://*/photoShop.msl;
provider=System.Data.SqlClient;provider connection string='Data Source=.\SQLEXPRESS;AttachDbFileName=|DataDirectory|photoShop.mdf;Integrated Security=True;User Instance=True'"
providerName="System.Data.EntityClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Web.config of the WebApplication:
<?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>
<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" />
<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="true">
<providers>
<clear />
<add connectionStringName="ApplicationServices" applicationName="/"
name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" />
<add applicationName="/" name="AspNetWindowsTokenRoleProvider"
type="System.Web.Security.WindowsTokenRoleProvider" />
</providers>
</roleManager>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IBLServer" 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="32" 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:50739/PhotoShopWS.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IBLServer" contract="PhotoShopWS.IBLServer"
name="BasicHttpBinding_IBLServer" />
</client>
</system.serviceModel>
</configuration>
App.config of the classLibrary:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IBLServer" 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="32" 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:50739/PhotoShopWS.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IBLServer" contract="PhotoShopWS.IBLServer"
name="BasicHttpBinding_IBLServer" />
</client>
</system.serviceModel>
</configuration>
I saw a lot of answers about it but my problem stil leave.
Any help is greatly appreciated!
It is in the web.config of the WCF application you have to specify the maxReceivedMessageSize to a higher value.
Ex.
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding transferMode="Streamed"
maxReceivedMessageSize="67108864">
<!-- other config here -->
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
I used mark help, now my site allow to upload large images.
This is the web.config of my WCFApplication after the changes.
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="photoShopEntities"
connectionString="metadata=res://*/photoShop.csdl|
res://*/photoShop.ssdl|
res://*/photoShop.msl;
provider=System.Data.SqlClient;provider connection string='Data Source=.\SQLEXPRESS;AttachDbFileName=|DataDirectory|photoShop.mdf;Integrated Security=True;User Instance=True'"
providerName="System.Data.EntityClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime maxRequestLength="2147483647"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding transferMode="Streamed"
maxReceivedMessageSize="67108864">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<!-- other config here -->
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Thanks a lot!!
Check
if it exist in httpTransport element, in App.config of the classLibrary:
maxReceivedMessageSize="104857600"

WCF Double Hop with ASP.NET Web sites using Delegation

I am trying to build a web service that cal handle Double Hop Delegate / impersonation. End goal is to have a Web Site, that can make a Web Service call to a Custom Sharepoint Web Service as a particular user (instead of using a specific user in an AppPool) and get a list of files in a particular folder on SharePoint that this user has access to. That way when our website makes the call as that user, we only retrieve the files they have access to.
The issue I am having right is that as I have read already, ASP.NET calls to a WCF service cannot by default pass the token information along (the Double Hop affect). I have been trying several tutorials on how to get around this security and have been unsuccessful so far.
Here is my Service Web.Config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<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"/>
<!--<serviceAuthorization impersonateCallerForAllOperations="true"/>-->
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Service GetData Call
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1 : IService1
{
[OperationBehavior(Impersonation = ImpersonationOption.Allowed)]
public string GetData(int value)
{
if (HttpContext.Current == null)
{
return "Failed to impersonate";
}
return string.Format("Your name is: " + WindowsIdentity.GetCurrent().Name + "... You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}
I have tried adding the ASPNet Compatability MetaData, removing it to no avail.
ASP.NET MVC Web.Config
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=152368
-->
<configuration>
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<identity impersonate="true"/>
<authentication mode="Windows">
</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>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages"/>
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<bindings>
<basicHttpBinding>
<binding name="winAuthBasicHttpBinding" 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="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" realm="" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://se-sandbox-dev/GreggColeman/WebServices/WCFDelegation/Service1.svc"
binding="basicHttpBinding" bindingConfiguration="winAuthBasicHttpBinding"
contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
</configuration>
MVC Home Controller
using (((WindowsIdentity)User.Identity).Impersonate())
{
ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
client.ClientCredentials.Windows.AllowedImpersonationLevel =
System.Security.Principal.TokenImpersonationLevel.Delegation;
returnData = client.GetData(5);
ViewBag.Message = returnData;
}
Every time, I either Get WindowsIdentity is equal to whatever the AppPool is set to OR the HTTPContext = null. Neither ever have t he correct data unless I use a Windows Application. Then it works fine. Any Help would be greatly appreciated

Resources