How to consume multiple binding WCF Service method without mentioning the endpoint name - wcf-binding

Currently I’m using BaciHttpBinding and WsHttpBindin for same Service. Before introduce the BasicHttpBing, My Client Windows app consuming the WsHttpBindin, so i didn't mention the endpoint name. After introduce the BasicHttpBinding i need to mension the Name of the endpoint in my client when it going to consume the Desired Service. My problem is, I have to change all the existing code with endpoint name. How can i overcome this situation or is there any method which i can set the default binding in config level and it'll use when i didn't supply the endpoint name.

You can not define multiple endpoints on same address, assign two different address for both the bindings.
You can leave the address blank in case of contracts and it will automatically points to the address of mex endpoint, which is being used for defining your metadata.
Similarly you can BindingConfiguration tag to configure the bindings.

Do something like this, i am using binding configuration and transmode is streamed and using this binding configuration in my endpoints
<binding name="StreamBinding" closeTimeout="00:59:00" openTimeout="00:10:00"
sendTimeout="00:10:00" maxBufferPoolSize="700000000" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647" transferMode="Streamed">
<readerQuotas maxStringContentLength="2147483647" maxArrayLength="1000" />
<reliableSession inactivityTimeout="02:00:00" />
<security mode="None"></security> </binding>
<endpoint address="" binding="netTcpBinding" bindingConfiguration="StreamBinding"
bindingName="" contract="DBSInterface.Common.IFileTransfer">
<identity>
<dns value="localhost" />
</identity>
</endpoint>

Related

maxReceivedMessageSize not fixing 413: Request Entity Too Large

My call to my WCF web service is failing with System.Net.WebException: The request failed with HTTP status 413: Request Entity Too Large.
Checking Fiddler, I see that I'm sending:
Content-Length: 149839
Which is over 65KB.
Enabling WCF tracing on the server, I see:
System.ServiceModel.ProtocolException: The maximum message size quota
for incoming messages (65536) has been exceeded. To increase the
quota, use the MaxReceivedMessageSize property on the appropriate
binding element.
Adding this property doesn't solve the issue.
I've tried with just that property, and (later) with various others that posts have suggested. Here's what I have currently (on the server):
<basicHttpBinding>
<binding name="PricerServiceSoap"
closeTimeout="00:10:00" openTimeout="00:10:00"
receiveTimeout="00:10:00" sendTimeout="00:10:00"
maxBufferSize="2147483647"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
My sole endpoint (under <client>) is:
<endpoint address="/NetPricingService/Service.asmx"
binding="basicHttpBinding" bindingConfiguration="PricerServiceSoap"
contract="Pricing.PricerService.PricerServiceSoap"
name="PricerServiceSoap" />
I've also added:
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
under <behavior>.
I've even run (for IIS 7):
%windir%\system32\inetsrv\appcmd set config "WebServicesDev/PricingService"
-section:requestFiltering -requestLimits.maxAllowedContentLength:104857600
-commitpath:apphost
Nothing makes any difference.
One catch is that this is a WCF service meant to replace an older ASMX service. The service skeleton was generated with svcutil from existing WSDL. I can't change the client configurations (and the clients are in multiple languages). My test client project imported the service with Add Web Reference (under Add Service Reference / Advanced), so I have no WCF configuration. However, the test client works if I point it at the older ASMX service.
How can I fix or diagnose this?
Additional info
If I use the Microsoft Service Configuration Editor to generate the config (setting maxReceivedMessageSize and maxBufferSize), it works. The problem is that the endpoint is then specified under <service>, and it won't let me specify the /NetPricingService/Service.asmx relative address. If I edit the bindings in the svcutil-generated config (where the endpoint is under <client>), it doesn't work with large requests.
The answer was staring me in the face.
The config generated by svcutil was for the client. I was using it on the server.
I was editing the bindings for the endpoints specified under <client>, which made absolutely no difference to the service.
Adding a proper <service> endpoint and setting the maxReceivedMessageSize and maxBufferSize on its binding resolved the issue.
I had a similar problem.
For me, the problem was that my endpoint did not explicitly name the binding using bindingConfiguration and so must have been using some default one somewhere.
I had:
<webHttpBinding>
<binding
name="myXmlHttpBinding"
maxReceivedMessageSize="10485760"
maxBufferSize="10485760">
<readerQuotas
maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
<security mode="None"/>
</binding>
</webHttpBinding>
and my endpoint defined as:
<service
name="blah.SomeService">
<endpoint
address=""
behaviorConfiguration="WebHttpBehavior"
binding="webHttpBinding"
contract="blah.ISomeService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
</service>
It worked once I changed the endpoint to:
<service name="blah.SomeService">
<endpoint address=""
behaviorConfiguration="WebHttpBehavior"
binding="webHttpBinding"
bindingConfiguration="myXmlHttpBinding"
contract="blah.ISomeService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
</service>
I also had this problem and realized in fiddler that the max Content-Length that was working ended up being 30000000.
After verifying that my WCF configuration was correct I found an article suggesting a modification to the IIS setting, Request Filtering.
Large file upload failure for Web application calling WCF service – 413 Request entity too large
Open IIS Manager
Select your application
Select the Request Filtering icon.
Select Edit Feature Settings... (Right Panel)
Adjust the Maximum allowed content length (Bytes) Default Appears to be 30000000
or web.config file example
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="50000000" />
</requestFiltering>
</security>
</system.webServer>
tried things from 10 different blogs and my coworker figured it out.
we had to add a basicHttpsBinding section inside of in addition to the basicHttpBinding section. We have a webapi service calling wcf. the webapi method was catching the entity too large error when it called the wcf service method. This change was applied in the web.config file of the wcf service.
None of the suggestions worked for me. What solved the issue was to increase the MaxReceivedMessageSize in System.ServiceModel.Channels.HttpTransportBindingElement
There are two different MaxReceivedMessageSize parameters:
MaxReceivedMessageSize in
System.ServiceModel.Configuration.BasicHttpBindingElement
MaxReceivedMessageSize in
System.ServiceModel.Channels.HttpTransportBindingElement
In the dump file, I saw that it was failing because of the limitation in HttpTransportBindingElement
Adding this to my web.config fixed the issue:
<customBinding>
<binding closeTimeout="00:10:00" openTimeout="00:10:00" sendTimeout="00:10:00">
<httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" useDefaultWebProxy="true" transferMode="Buffered" />
</binding>
</customBinding>
Source: WCF service shows 413 Request Entity Too Large error when uploading files over 64 KB
Add this solve it for me:
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_Example"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
</binding>
</basicHttpBinding>
</bindings>

Issue with multiple interfaces in a single service

I am using WCF with NetTcpBinding on a solution where both client and server are windows forms. The service is hosted by one of them. I am using VS.2012.
On the server side I have several service contracts (related) all of which are implemented in a single service class. Like this:
public class MyService : IServiceA, IServiceB
{
}
and they should be accessible via net.tcp://localhost:4545/control/ which would lead to the following service addresses:
IServiceA (endpoint alphaEP) : net.tcp://localhost:4545/control/ASvc/
IServiceB (endpoint betaEP) : net.tcp://localhost:4545/control/BSvc/
And when I use svcutil.exe to generate the client stuff I see that it generates TWO service client classes, one for each interface, so when I use the ServiceBClient it generates an exception inidicating it could not find a 'betaEP' with contract 'IServiceB' even though the app.config has the same binding configuration and has both endpoints defined
<bindings>
<netTcpBinding>
<binding name="alphaEP">
<reliableSession enabled="true" />
<security mode="None" />
</binding>
<binding name="betaEP">
<reliableSession enabled="true" />
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
and this
<client>
<endpoint address="net.tcp://localhost:4545/control/ASvc"
binding="netTcpBinding" bindingConfiguration="alphaEP"
contract="CodeDom.IServiceA" name="alphaEP">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="net.tcp://localhost:4545/control/BSvc"
binding="netTcpBinding" bindingConfiguration="betaEP" contract="CodeDom.IServiceB"
name="betaEP">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
Why can't it find the endpoint if this client app.config was generated by svcutil.exe based on the server configuration?
Why does it generates two client classes instead of a single one? would that be the source of the problem? I have multiple related services to expose and I don't want to occupy more than one port on that. Do note, this is Net TCP Binding.

WCF customBinding is BasicHTTPBinding when adding service reference

I have a WCF service with a customBinding endpoint.
<customBinding>
<binding name="customBinding" receiveTimeout="00:10:00" sendTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00">
<binaryMessageEncoding>
<readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647" />
</binaryMessageEncoding>
<httpTransport maxReceivedMessageSize="40194304" />
</binding>
</customBinding>
My service is :
<services>
<service name="Test2">
<endpoint address="" binding="customBinding" bindingConfiguration="customBinding" contract="MyServiceContract.ContractInterface">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
However, in my client application, whenever I add a Service Reference, the resulting reference is a BasicHTTPBinding (in app.config)
What can I do to "force" the client to use custombinding?
Thanks
Alex
The service is not using the binding you specified. My guess is that the service name is actually "MyServiceContract.Test2" (or something similar) instead of just "Test2", so when WCF didn't find any matching <service> element to the service class, it simply used the default endpoint, which happens to use basicHttpBinding.
Have you defined a class for your custom binding (a class derived from System.ServiceModel.Channels.Binding)?
If so, have you added the new binding into the config binding extensions?
<extensions>
<bindingExtensions>
<add name="myCustomeBinding" type="MyCustomeBinding, MyCustomeBindingLibrary" />
</bindingExtensions>
</extensions>
The job of the binding is to define the "recipe" for creating the WCF channel. Basically the recipe consists of a list of binding elements.
Which bindings elements you select in your recipe decides the nature of the communication that the WCF channel will implement.
At the absolute minimum your recipe of binding elements needs to include:
Message encoding (text/binary etc)
Transport (HTTP/TCP etc)
If you don't have a class defining your binding then WCF has no option but to create a channel based on the default values for these two binding elements, and so has probably been designed to switch to basicHttpBinding when no binding has is defined.
That would be my guess.

How can I bypass Operation Contract limitation of a WCF Service when calling "Update Service Reference" in VS 2008

I am having trouble with a single Wcf Service that we have in an application. It has about 150 [OperactionContract] within it. I can now no longer Update Service Reference within Visual Studio 2008.
I receive all kinds of strange errors, varying from "Socket Forcibly Closed" to "Invalid Type" and other strange messages when I try to call an update. If I comment out 10-20 operations it works fine.
I have read all kinds of posts here, on MSDN, and many blogs. They all point to binding configurations that need to be changed, either on the main binding or on the MetadataExchange binding.
My problem is that I have tried all of this and have yet to get it to work reliably.
I am self hosting the service in an application, and that same application is also the client. They share the same configuration file (currently) because we are in the process of breaking the application into 2 pieces via the Wcf service layer.
Here is an excerpt showing my bindings I have defined:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IRhinoServices"
closeTimeout="00:05:00"
openTimeout="00:05:00"
receiveTimeout="00:15:00"
sendTimeout="00:05:00"
transactionFlow="false"
transferMode="Buffered"
transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard"
listenBacklog="100"
maxBufferPoolSize="2147483647"
maxBufferSize="2147483647"
maxConnections="100"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<reliableSession ordered="true"
inactivityTimeout="00:10:00"
enabled="false" />
<security mode="None">
</security>
</binding>
</netTcpBinding>
<customBinding>
<binding name="customMex">
<textMessageEncoding>
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</textMessageEncoding>
<tcpTransport transferMode="Buffered"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647"/>
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="net.tcp://localhost:8523/RhinoServices"
binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IRhinoServices"
contract="RhinoServicesReference.IRhinoServices"
name="NetTcpBinding_IRhinoServices">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
<services>
<service behaviorConfiguration="CounterSketchServer.RhinoServicesBehavior"
name="CounterSketchServer.RhinoServices">
<endpoint address=""
binding="netTcpBinding"
contract="CounterSketchServer.IRhinoServices">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex"
binding="customBinding"
contract="IMetadataExchange"
name=""
bindingConfiguration="customMex"
listenUriMode="Explicit" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8523/RhinoServices" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CounterSketchServer.RhinoServicesBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
I need to be able to generate the proxy class by clicking on Update Service Reference, which has worked well this past 2 weeks, till I hit this mysterious limit.
Most of the examples I have seen to resolve this talk about http bindings for mex, but I would like to stick with just netTcp if possible since I am self hosting.
Can anyone please help me?
Thank you.
* UPDATE *
I have tried #Aliostad suggestion, and it appeared to work well at first. Until I tried some of our Wcf calls which update UI elements. These happened to work when using NetTCP bindings with the Proxy Class generated by Visual Studios (Add Service Reference) tool. But when using the Channel Factory it does not work.
I have tried looking at the SyncrhonizationContext in Juval's WCF book, but nothing I did seemed to work.
I have tried using both Named Pipes and NetTCP as the binding for the Channel I create using the ChannelFactory, and they do seem to behave very differently from eachother related to long running Wcf operations, but neither work to update UI elements.
My services are actually running in a plugin for the Rhino 3D CAD engine, and ceratin calls (Render, etc.) trigger UI in Rhino to update. I assume this is causing a thread boundary issue. The exception I receive is:
attempted to read or write protected memory
If anyone has any suggestions to use the ChannelFactory method effectively in this scenario or to fix my problem with too many Operations in a given Wcf class to generate the Service Proxy I would appreciate your help.
Thank You!
First of all, I believe the only solution is to remove the reference, and add it back again.
Alternatively, if you own both the Client and the Service - which I seem to get from reading your question that you do - may I strongly suggest that you share you service interfaces with your clients - instead of using a service reference?
This is definitely the preferred approach when you own both client and the server (and will save you from all the troubles you are having) and I believe it is also preferred if you do not own the client, you just share the entities/dtos and the interfaces.
This requires you to:
Create a class library project for you entities/dtos. Share it with the client.
Create a class library project for you service interfaces. Share it with the client.
Create a class library project for you service implementation. Stays only on the server.
The client uses ChannelFactory<T> to create factory and then create a proxy by calling CreateChannel()
I have got the Update Service Reference working again from both SvcUtil.exe and from Visual Studio 2008.
To do so I added the following section to the config files for both devenv.exe.config and SvcUtil.exe.config:
<!-- CUSTOM MetaDataExchaning Binding to all for LARGE WCF Services -->
<client>
<endpoint name="net.tcp" binding="netTcpBinding" bindingConfiguration="GenericBinding"
contract="IMetadataExchange" />
<endpoint name="http" binding="wsHttpBinding" bindingConfiguration="SecureBinding" contract="IMetadataExchange" />
</client>
<bindings>
<netTcpBinding>
<binding name="GenericBinding" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" >
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="None"/>
</binding>
</netTcpBinding>
<wsHttpBinding>
<binding name="SecureBinding" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" >
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="Message">
<transport clientCredentialType="Windows" />
</security>
</binding>
</wsHttpBinding>
</bindings>
Then in my application Server plugin, I am still programmatically creating the ServiceHost so to enable meta data exchange I added another endpoint:
// DATA ENDPOINT
NetTcpBinding binding = new NetTcpBinding(SecurityMode.Transport, true);
Uri baseAddress = new Uri("net.tcp://localhost:8555/RhinoServices");
_rhinoServicesHost = new ServiceHost(typeof(RhinoServices), baseAddress);
_rhinoServicesHost.AddServiceEndpoint(typeof(IRhinoServices), binding, baseAddress);
// META ENDPOINT
BindingElement bindingElement = new TcpTransportBindingElement();
CustomBinding customBinding = new CustomBinding(bindingElement);
ServiceMetadataBehavior metadataBehavior = _rhinoServicesHost.Description.Behaviors.Find<ServiceMetadataBehavior>();
if (metadataBehavior == null)
{
metadataBehavior = new ServiceMetadataBehavior();
_rhinoServicesHost.Description.Behaviors.Add(metadataBehavior);
}
_rhinoServicesHost.AddServiceEndpoint(typeof(IMetadataExchange), customBinding, "MEX");
_rhinoServicesHost.Faulted += RhinoServicesHost_Faulted;
_rhinoServicesHost.Open();
I can now update the references regardless of the number of contracts.
I have to admit though, during this whole process the Attempted to read or write protected memory error that cropped up hasn't gone away since I switched back to this method.
So I guess I have to still track that down...
Also I found this solution on a different question (click to view), answered by #trendl. Thank you for your help.

Calling webservice from WCF service

I am having an issue consuming a webservice (c#.net) from a WCF service.
The error i am getting is EndPointNotFoundException "TCP error code 10061: No connection could be made because the target machine actively refused it"
I wrote a unit test to check if i could send a request to the web service and it worked fine
[The unit test is using the same binding configuration as my WCF service]
The web service and WCF service (client) have basichttp binding.
Did anyone had similar kind of issue calling a webservice from a WCF service?
The service Model section is as follows
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="DataService" closeTimeout="00:05:00" openTimeout="00:05:00" receiveTimeout="00:10:00" sendTimeout="00:05: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://10.22.33.67/Service/DataService.asmx" binding="basicHttpBinding"
bindingConfiguration="DataService" contract="Service.DataService" name="DataService"/>
</client>
<services>
<service name="TestToConsumeDataService.WCFHost.Service1" behaviorConfiguration="TestToConsumeDataService.WCFHost.Service1Behavior">
<!-- Service Endpoints -->
<endpoint address="" binding="basicHttpBinding" contract="TestToConsumeDataService.WCFHost.IService1">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="TestToConsumeDataService.WCFHost.Service1Behavior">
<!-- 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>
</system.serviceModel>
The unit test project is also using the same service model section and it works. The only issue is while calling the service from another WCF service. Could you please suggest.
You mentioned "webservice" and "WCF service" - so the "webservice" is a old-style ASMX web service??
How is your WCF service hosted? In IIS? Do you have the necessary endpoint information for the webservice you're calling from WCF inside your web.config ??
Can you show us your relevant configs, e.g. the <system.serviceModel> section of your web.config (or app.config, if you're self-hosting the WCF service), please?
The error means there's either no webservice listening at the address you're using, or you don't have access rights to it. Are you missing some security or something?
MArc
It looks like there is some configuration that you need to call your web service.
This configuration is correct in the configuration file of your unit test.
But it is not correct or missing in the configuration file of your WCF service.
When you have two dll's where one calls the other, then it is the config file of the first dll that is used. However, when you go over a WCF hop, it is the config file of the WCF service that takes over.
Hope this helps
Shiraz