WCF bindings at service side - wcf

How can we define bindings with Max buffer size at WCF service side rather than doing at client side. Can somebody let me know if this is feasible? I do not want to customize bindings at client side.

This may help you! Add maxRequestLength=214748364 in Web.Config.
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" maxRequestLength="2147483647" executionTimeout="300"/>
</system.web>
And if it doesn't work Add this in tag.
<bindings>
<webHttpBinding>
<binding name="webHttpBG" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"
maxBufferPoolSize="21474836470" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00">
<security mode="None"/>
</binding>
</webHttpBinding>
</bindings>
And in your tag. Do something like this.
<services>
<service behaviorConfiguration="" name="Your.Service.Name">
<endpoint address="" behaviorConfiguration="RESTBehavior" binding="webHttpBinding"
bindingConfiguration="webHttpBG" contract="Your.Package.IContract" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:51855/Contract.svc" />
</baseAddresses>
</host>
</service>

Related

C# WCF localhost The remote server returned an unexpected response: (413) Request Entity Too Large

I have asp web forms application and wcf service, both localhost. This is config from web application
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
<readerQuotas maxDepth="200" maxStringContentLength="8388608" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="16384" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:63251/Poruka.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService" contract="localhostPoruka.IPoruka" name="BasicHttp_IService"/>
</client>
This is web config from wcf service
<?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"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" openTimeout="00:20:00"
receiveTimeout="00:20:00" closeTimeout="00:20:00" sendTimeout="00:20:00">
<readerQuotas maxDepth="200" maxStringContentLength="8388608" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="16384" />
<security mode="Transport"/>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="MyServiceName">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService"
contract="localhostPoruka.IPoruka"
name="BasicHttp_IService"/>
</service>
</services>
Upload works for smaller size files (for example 30kb), but when I tried something bigger (pdf size 80kb), I got 413 Entity too large error.
I've tried adding messageSize on client and service, but it's not helping. I also addded to applicationHost file this lines
<location path="localhost">
<system.webServer>
<serverRuntime uploadReadAheadSize="2147483647" />
</system.webServer>
</location>
I also tried in IIS manager on default web site->configuration editor->system.webserver/runtime set uploadReadAheadSize.
None of this helped. Is something wrong in my config file or should I set some other property somewhere else? Should I try using wsHttpBinding?
Even though you've defined a binding in the WCF service config file, it doesn't appear that you've actually assigned that binding configuration to a service. In that case, WCF will use the default settings for basicHttpBinding.
Try adding a service endpoint explicitly to the WCF config file, and assigning your binding configuration via the bindingConfiguration attribute on the service <endpoint> element, like this:
<services>
<service name="MyServiceName">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService"
contract="localhostPoruka.IPoruka"
name="BasicHttp_IService"/>
</service>
</services>
This goes in the <system.serviceModel> section of the WCF service config.

WCF Hosted in IIS 7.0 Binding Issue

I have hosted a WCF Service on IIS7 by creating a WCFService Application Project Type.
In WCF Service Solution, there are two Project. 1) Actual *WCFService* *and 2) WCFService Application* for hosting it in IIS7.0
1) Actual WCFService Project. app.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="DHDocuments.DService">
<endpoint address="" binding="wsHttpBinding"
contract="DHDocuments.IDService" >
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/DHDocuments/DService/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
2) WCFService Application web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.serviceModel>
<services>
<service name="DHDocuments.DService">
<endpoint address="" binding="basicHttpBinding"
bindingConfiguration=""
name="basic"
contract="DHDocuments.IDService"/>
</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>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
In the IIS its being hosted. Its available at http://localhost:2004/DService.svc
Now Coming to the WCF Consuming Project,
I have added a Service Reference by Pointing to the http://localhost:2004/DService.svc. In my WCF Consuming client project this is the app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<client>
<endpoint address="http://localhost:2004/DService.svc"
binding="basicHttpBinding"
bindingConfiguration="basic1"
contract="WCFDHService.IDService"
name="basic" />
</client>
<bindings>
<basicHttpBinding>
<binding name="basic1" 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>
</system.serviceModel>
</configuration>
This now complains:
The binding at system.serviceModel/bindings/basicHttpBinding does not have a configured binding named 'basic1'. This is an invalid value for bindingConfiguration
**
Can someone point what is being missed?
There is no problem when I have utilised wcf service directly by debug mode, without hosting it in IIS. I am sure, the binding config is getting error.
It appears that you have configured your services for metadata discovery with a mex endpoint:
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
Another endpoint in the service configuration is defined as wsHttpBinding:
<endpoint address="" binding="wsHttpBinding" contract="DHDocuments.IDService" >
I am guessing since mex is enabled the client proxy will generate a wsdl, however, you need to specify https if using transport security. Or add a endpoint for basicHttpBinding in your wcf service.
It seems like you are trying to access your service in the client proxy using a basicHttpBinding configuration but the service is not configured to accept or listen for such.

silverlight + wcf deployment - development port interferes

I have a silverlight 5 application, with a (non RIA) WCF service in my web project.
Of course it works great on my machine ;-) - Windows 7, but when I deploy it to my dev server (a WinServer2008 with .NET 4 on it, using IIS 6), the application doesnt seem to finish loading - I get the initial silverlight Loading... then I just have a blank screen. I dont see any error messages.
I think the issue may be that the silveright app assumes that the port for the WCF service is the same as it was on my machine (46133).
Ive seen articles online that say that you should set the address of the endpoint in ServiceReferences.ClientConfig to ../Service.svc. If I change it to this, and deploy, nothing changes.
In the properties of the web project, on the web tab, I have Use Visual Studio Development Server checked, and specific port 46133, Virtual Path =/
I think that the deployed site, is still trying to use port 46133, because Fiddler shows a 502 red item for the clientaccesspolicy.xml file, with the message
[Fiddler] The socket connection to localhost failed. ErrorCode: 10061. No connection could be made because the target machine actively refused it 127.0.0.1:46133
Any suggestions?
Here's the ServiceReferences.ClientConfig file:
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="TransportCredentialOnly" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="../Service.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService" contract="ServiceReference1.IService"
name="BasicHttpBinding_IService" />
</client>
</system.serviceModel>
</configuration>
My web.config is
<system.web>
<httpRuntime executionTimeout="180" />
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpStreamingBinding" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647" transferMode="Streamed" receiveTimeout="01:00:00" sendTimeout="01:00:00">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" />
<!--<transport clientCredentialType="Windows" />-->
</security>
</binding>
</basicHttpBinding>
</bindings>
<client />
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment
multipleSiteBindingsEnabled="true" />
<services>
<service name="CitationAir.MissionPlanning.WebService.Service">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpStreamingBinding"
contract="CitationAir.MissionPlanning.WebService.IService" />
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

silverlight wcf service prompt for credentials

I have a silverlight app that calls a wcf service, and I'm having trouble deploying it.
I can publish the files, but when the app tries to access the service, it doesnt seem to get anything back.
The app is set for client credentials with Windows Authentication
What's weird is that its not throwing errors. The silverlight app just seems to stop with a blank screen.
To test the deployed service, I try to access it from a browser, and I'm prompted for credentials. I try putting in my name and password, but it just asks me for credentials again.
What credentials is it prompting me for?
How can I get past this?
Here's the client config:
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="TransportCredentialOnly" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="../Service.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService" contract="ServiceReference1.IService"
name="BasicHttpBinding_IService" />
</client>
</system.serviceModel>
</configuration>
Here's the web config:
<configuration>
<system.web>
<httpRuntime executionTimeout="180" />
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpStreamingBinding" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647" transferMode="Streamed" receiveTimeout="01:00:00" sendTimeout="01:00:00">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
<!--<transport clientCredentialType="Ntlm" />-->
</security>
</binding>
</basicHttpBinding>
</bindings>
<client />
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment
multipleSiteBindingsEnabled="true" />
<services>
<service name="CitationAir.MissionPlanning.WebService.Service">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpStreamingBinding"
contract="CitationAir.MissionPlanning.WebService.IService" />
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
Using Windows Authentication, you will get a password prompt if Integrated Windows Authentication is turned off`, which can be because you are using a browser other than Internet Explorer.
The password wont work if your account is locked out, if you are connecting to a service in an untrusted domain, or if your account does not have sufficient permissions to access the resource.
Could it be any of those in this case?

Unable to access WCF Service from Client machine

Unable to access WCF Service from Client machine
I have three projects : WCF Service (VS-2008), Windows Service (VS-2008), Client (VS-2005)
The WCF service has netTcpBinding
This service is hosted as a windows service and not on IIS
The base address for both the service (WCF and Windows) is
net.tcp://localhost:8010/WCFService.Service1/
Now when i add a service reference to the client project which is on VS-2005, It updates my app.config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="netTcpEndPoint" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"
transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10"
maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
maxReceivedMessageSize="65536">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://localhost:8010/WCFService.Service1/"
binding="netTcpBinding" bindingConfiguration="netTcpEndPoint"
contract="Client.Service1.IService1"
name="netTcpEndPoint">
<identity>
<servicePrincipalName value="host/server17.domain.com" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
And adds Service1.map file as
<?xml version="1.0" encoding="utf-8"?>
<ServiceReference>
<ProxyGenerationParameters
ServiceReferenceUri="net.tcp://server17:8010/WCFService.Service1/"
Name="Service1"
NotifyPropertyChange="False"
UseObservableCollection="False">
</ProxyGenerationParameters>
<EndPoints>
<EndPoint
Address="net.tcp://localhost:8010/WCFService.Service1/"
BindingConfiguration="netTcpEndPoint"
Contract="Client.Service1.IService1"
>
</EndPoint>
</EndPoints>
</ServiceReference>
When I call any of the service methods I get an error stating
Could not connect to net.tcp://localhost:8010/WCFService.Service1/.
The connection attempt lasted for a time span of 00:00:02.0063936. TCP
error code 10061: No connection could be made because the target
machine actively refused it 127.0.0.1:8010.
At least it should be net.tcp://server17:8010/WCFService.Service1/
I have already tried to replace localhost with server17 in the client project... but no luck
What should I change to make it working? please help.
This is my WCF Service's App.config which is same as windows service's
app.config : as requested by Tim
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="WCFService.ServiceBehavior"
name="WCFService.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration=""
name="netTcpEndPoint" contract="WCFService.IService1" />
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
name="mexTcpEndPoint" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8010/WCFService.Service1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WCFService.ServiceBehavior">
<serviceMetadata httpGetEnabled="False" />
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
At a guess I'd check three things:
When you add the service reference to your client, are you adding it from net.tcp://localhost:8010/WCFService.Service1/, or are you adding it from net.tcp://server17:8010/WCFService.Service1/?
If you're adding it from server17, try using the fully qualified name of the server - i.e., server17.mydomain.com or whatever it is.
The connection error is probably related to the endpoint address you're using - the client is passing in a serverPrincipalName of "host/server17.domain.com", but you're attempting to connect to localhost.
No guarantees any of the above are the root cause, but it gives you a place to start.
EDIT
You specify the locahost in the baseAddress element, but you don't specify anything in the address attribute of the endpiont element. That's probably why it's still going to localhost.
Modify the config file for your service to either change the baseAddress to:
<baseAddresses>
<add baseAddress="net.tcp://server17:8010/WCFService.Service1/" />
</baseAddresses>
or drop the baseAddresses and specify the address in your endpoint:
<endpoint address="net.tcp://server17:8010/WCFService.Service1/"
binding="netTcpBinding"
bindingConfiguration=""
name="netTcpEndPoint"
contract="WCFService.IService1" />
Give that a try.