I am developping a namedpipe Duplex WCF service.
For the basic things, the client and the server are communicating without issue. The server can callback the client sending him strings, and it does it without any issue.
But, when i want it to send a bitmap with byte[] or stream, everything is faulting. Just note i tried to use the stream because the byte[] is not working...
In server side, the byte[]/stream is generated without issue.
But when the server sends the byte[]/stream to the client,if the byte[]/stream is empty it goes through but when it has data it is faulting.
I already checked all my configurations, and tried to set a large buffer/message/poolsize/stringcontent/arraylenght/byteperread/whatever size/lenght because i know that's a classic issue in WCF.
Here is a C/P of the main part of my WCF Config file.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
<system.serviceModel>
<bindings>
<netNamedPipeBinding>
<binding name="NamedPipeBinding_ICameraService" closeTimeout="00:05:00" openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" maxConnections="10" maxBufferPoolSize="500000000" maxBufferSize="500000000" maxReceivedMessageSize="500000000">
<readerQuotas maxDepth="32" maxStringContentLength="500000000" maxArrayLength="500000000" maxBytesPerRead="500000000" maxNameTableCharCount="500000000"/>
<security mode="Transport"/>
</binding>
</netNamedPipeBinding>
</bindings>
<services>
<service name="EOSDigital.CameraService" behaviorConfiguration="MEX">
<endpoint address="net.pipe://localhost/EOSDigital/CameraService" binding="netNamedPipeBinding" bindingConfiguration="NamedPipeBinding_ICameraService" contract="EOSDigital.ICameraService"/>
<endpoint address="net.pipe://localhost/EOSDigital/CameraService/mex" binding="mexNamedPipeBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MEX">
<serviceMetadata httpGetEnabled="False"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Here is the service callback contract
[ServiceContract]
public interface ICameraServiceCallBack
{
[OperationContract(IsOneWay = true)]
void CallBackFunction(string str);
[OperationContract(IsOneWay = true)]
void LiveviewUpdated(byte[] img);
}
And here is the declaration of my Service contract.
[ServiceContract(CallbackContract = typeof(ICameraServiceCallBack))]
public interface ICameraService
I wont put everything, this is too huge.
This is how i use it
private void CurrentCamera_LiveViewUpdated(object sender, Stream img)
{
MemoryStream data = new MemoryStream();
img.CopyTo(data);
_callback = OperationContext.Current.GetCallbackChannel<ICameraServiceCallBack>();
_callback.CallBackFunction("this is a test"); // ok
_callback.LiveviewUpdated(data.ToArray()); //Faulted
}
I get the Stream from a Canon digital Camera and it is around byte[146242]. When i send a byte[10] it works.
It has to be a problem of size, and I guess i missed something in the config file ...
I also tried to generate and take a look to the scvclog file of my service to see some details of the occurring faulted exception.
But, well... There is not less than 50k characters in one line. This is not readable.
Thank you.
Check your client WCF configuration.
Your client configuration must have the same netNamedPipeBinding as your host.
Put that in your client config file
<netNamedPipeBinding>
<binding name ="duplexEndpoint" closeTimeout="00:05:00" openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="50000000" maxBufferSize="50000000" maxConnections="10" maxReceivedMessageSize="50000000">
<readerQuotas maxDepth="32" maxStringContentLength="50000000" maxArrayLength="50000000" maxBytesPerRead="50000000" maxNameTableCharCount="50000000"/>
</binding>
</netNamedPipeBinding>
This have to be put bellow the serviceModel.Bindings bracket.
Then, bind the configuration in your endpoint bracket
bindingConfiguration="duplexEndpoint"
That should do what you expected.
Related
I am hosting two services using NetTcpBinding on same port 5000 like below.
In my service app.config I have like below
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="netTcpBindingConfiguration"
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>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="netTcpServiceBehavior">
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<!--First Service [net.tcp://localhost:5000/MyService/FirstService] -->
<service behaviorConfiguration="netTcpServiceBehavior" name="FirstserviceLib">
<endpoint address="" binding="netTcpBinding" contract="IFirstService"
bindingConfiguration="netTcpBindingConfiguration" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:5000/MyService/FirstService" />
</baseAddresses>
</host>
</service>
<!--Second Service [net.tcp://localhost:5000/MyService/SecondService] -->
<service behaviorConfiguration="netTcpServiceBehavior" name="SecondserviceLib">
<endpoint address="" binding="netTcpBinding" contract="ISecondService"
bindingConfiguration="netTcpBindingConfiguration" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:5000/MyService/SecondService" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
I am using console application to self-host like below
static void Main(string[] args)
{
ServiceHost firstHost = new ServiceHost(typeof(IFirstService));
firstHost.Open();
ServiceHost secondHost = new ServiceHost(typeof(ISecondService));
secondHost.Open();
Console.WriteLine("Services Hosted");
}
When I run my console application I get Service Hosted message. I feel my services are running.
On client side, I have below in my app.config
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="netTcpBindingConfiguration"
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>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://localhost:5000/MyService/SecondService"
binding="netTcpBinding"
contract="ISecondService"
name="NetTcpBinding_SecondService"
bindingConfiguration="netTcpBindingConfiguration" />
</client>
</system.serviceModel>
I am calling a method in SecondService like below
string path = System.Reflection.Assembly.GetExecutingAssembly().Location;
Configuration config = ConfigurationManager.OpenExeConfiguration(path);
ConfigurationChannelFactory<ISecondService> chn =
new ConfigurationChannelFactory<ISecondService>(
"NetTcpBinding_SecondService",
config,
new EndpointAddress("net.tcp://localhost:5000/MyService/SecondService"));
ISecondService facade = chn.CreateChannel();
string fullName = facade.GetName();
I am getting exception like below
System.ServiceModel.EndpointNotFoundException: There was no endpoint listening at net.tcp://localhost:5000/MyService/SecondService that could accept the message. This is often caused by an incorrect address or SOAP action
Since I am working on Windows 10 I enabled and running below service
Note: If I host only 1 service everything is good. But when I add SecondService it is not working. Please let me know what mistake I am making.
I can test IFirstService but not ISecondService
UPDATE 1:
I opened command prompt and went to C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.2 Tools
I gave svcutil net.tcp://localhost:5000/MyService/SecondService
I do not get any error message like There was no endpoint listening at blah blah...
but when I give svcutil net.tcp://localhost:5000/MyService/FirstService
I do get error message like There was no endpoint listening at blah blah...
It seems my service itself is not hosted properly.
It works fine now.
In my consolehost app.config I made sure there are no spaces between <service> in <services> section.
I removed all references to FirstService in Main method in Program.cs of my console host and also in App.config.
I ran my consolehost exe and now ISecondService is hosted
I ran svcutil net.tcp://localhost:5000/MyService/SecondService and now I do not see endpoint not listening error message.
On client side, I was able to execute below line which threw exception in GetName()
ISecondService facade = chn.CreateChannel();
string fullName = facade.GetName();
I fixed my code and re-executed it and this time it was fine.
Now I re-added references to FirstService in Console Host app.config and in Main() of Program.cs
I ran consolehost exe to host both services and now both below did not show me no endpoint message
svcutil net.tcp://localhost:5000/MyService/FirstService
svcutil net.tcp://localhost:5000/MyService/SecondService
Now everything works fine.
I have been given a wcf service, and i built a local console applicattion to test it, but i keep getting this error shown in the title. My service runs in the browser as it should, showing the screen where it shows the example and the url where you can test it. Probably the error is in the Web.config or in the App.config. I have this two files:
Web.condig
<?xml version="1.0"?>
<configuration>
<appSettings>
...
</appSettings>
<system.web>
<compilation debug="false" targetFramework="4.0"/>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true"/>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<service name="RAHPEDWCFService.RAHPEDService">
<endpoint address="http://localhost:44184/RAHPEDService.svc" behaviorConfiguration="webHttpBehavior" binding="webHttpBinding" bindingConfiguration="webHttpBindingWithJsonP" contract="RAHPEDWCFService.IRAHPEDService"/>
</service>
</services>
</system.serviceModel>
</configuration>
App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IRAHPEDService" 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://localhost:44184/RAHPEDService.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IRAHPEDService"
contract="ServiceReference.IRAHPEDService"
name="BasicHttpBinding_IRAHPEDService" />
</client>
</system.serviceModel>
</configuration>
I hope someone could give me a hint.
Please follow the below steps to resolve it
Please browse your service and click on the Url whether it is showing the metadata or not.
ex:http: //oj:23/Myservice?wsdl
If metadata is not enabled then do the below changes to your service config file.
i. create a mex endpoint
ii. Name the service behavior
Ex:
< serviceBehaviors>
< behavior name="SerBehavior">
< serviceMetadata httpGetEnabled="true"/>
< /behavior>
< /serviceBehaviors>
iii. Add this behavior to your service
Ex:
< service name="RAHPEDWCFService.RAHPEDService" behaviorConfiguration="SerBehavior"> < /service>
iv. Build the service and browse click on url to check the metaData
In your console application right click on the project and click on Add Service Reference
Place the Url in the Address box, click on Go check whether you are able to see the service, select your service and give namespace and click OK
create the object of your ServiceClient
Call your method
able to see the wsdl metadata in the browser.
If you have multiple endpoints in your client configuration file then you have pass the name of the endpoint to the constructor of ServiceCleint Class
Open Visual studio CommandPrompt and type WcfTestClient, right click on MyServiceProjects, add the service and check whether you are able to add or not and once added call your method under the endpoint appears
You should check that you are accessing the correct address. Rather than specify the entire address in the Web.config, more common practice is to provide just a relative address (even
an empty "" is fine), and then you access the service with:
http://servername:[port]/[virtual directory]/RAHPEDWCF.svc/[relative address in Web.config]
E.g. if address in Web.config showed
endpoint address="MySVC"
the full URL for clients (assuming default port 80 and in root of virtual server) might be
http://servername/RAHPEDWCF.svc/MySVC
If you are able to modify Web.config, this is what I would advise.
I have one application server implementing a bunch of services using default transferMode="Buffered" and one Streamed service. It exposes endpoints for basicHttp and net.tcp protocols, and runs in production under dozens of IIS 7.0+ configurations without incident.
When I went to replicate the architecture for a new application's server, streaming over net.tcp simply refused to work, throwing the perfectly opaque and obtuse ProtocolException
The .Net Framing mode being used is not supported by MyNetTcpEndpointAddress. See the server logs for more details.
Yeah right, the "server logs". (There's nothing, whether traced or not.) Service architectures and web.configs for S1 and S2 are identical, except for
some name changes
a custom namespace in S2 (S1 using tempuri)
different ports (S1 and S2 both using ports in the 8000-9000 range)
Streaming service S2 works just fine under basicHttp.
Having tried everything and failed to make the error go away, I built a test client that does nothing but run my service architecture with some Ping methods. No custom namespace, no frills, just the original configs, and lite services, contracts, and hand-coded wrappers around the ChannelFactory proxies.
Same error:
The .Net Framing mode being used is not supported by 'net.tcp://localhost:9931/StreamingService.svc'. See the server logs for more details.
The buffered test service works under both protocols, and the streamed service works under basicHttp, as in S2.
All testing done on the same Win7 machine with a complete IIS setup. The test app is still too big to post here, but here are the complete configs, and the console code
web.config
<configuration>
<connectionStrings>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<!-- throttling of stream size is partially controlled by this setting -->
<httpRuntime maxRequestLength="1048576" /><!-- 1GB -->
</system.web>
<system.serviceModel>
<serviceHostingEnvironment>
<serviceActivations>
<add relativeAddress="FooService.svc" service="WcfTest.Services.FooService" />
<add relativeAddress="StreamingService.svc" service="WcfTest.Services.StreamingService" />
</serviceActivations>
</serviceHostingEnvironment>
<behaviors>
<serviceBehaviors>
<behavior>
<dataContractSerializer maxItemsInObjectGraph="200000" />
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding
openTimeout="00:20:00" sendTimeout="00:20:00" receiveTimeout="00:20:00" closeTimeout="00:20:00"
maxBufferSize="20000000" maxBufferPoolSize="20000000" maxReceivedMessageSize="20000000">
<readerQuotas maxStringContentLength="12000" />
</binding>
<binding name="WcfTest.Streaming.Http" transferMode="Streamed"
openTimeout="03:00:00" sendTimeout="03:00:00" receiveTimeout="03:00:00" closeTimeout="03:00:00"
maxReceivedMessageSize="1073741824" /><!-- 1GB -->
</basicHttpBinding>
<netTcpBinding>
<binding
openTimeout="00:20:00" sendTimeout="00:20:00" receiveTimeout="00:20:00" closeTimeout="00:20:00"
maxBufferSize="20000000" maxBufferPoolSize="20000000" maxReceivedMessageSize="20000000">
<readerQuotas maxStringContentLength="12000" />
</binding>
<binding name="WcfTest.Streaming.Tcp" transferMode="Streamed"
openTimeout="03:00:00" sendTimeout="03:00:00" receiveTimeout="03:00:00" closeTimeout="03:00:00"
maxReceivedMessageSize="1073741824"><!-- 1GB -->
</binding>
</netTcpBinding>
</bindings>
<protocolMapping>
<add scheme="http" binding="basicHttpBinding" />
<add scheme="net.tcp" binding="netTcpBinding"/>
</protocolMapping>
<services>
<service name="WcfTest.Services.Streaming">
<!-- http -->
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="WcfTest.Streaming.Http" contract="WcfTest.Contracts.IStreamingService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<!-- net.tcp -->
<endpoint address="" binding="netTcpBinding" bindingConfiguration="WcfTest.Streaming.Tcp" contract="WcfTest.Contracts.IStreamingService" />
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
</configuration>
app.config
<configuration>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior>
<dataContractSerializer maxItemsInObjectGraph="200000"/>
</behavior>
<behavior name="customQuotaBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding
openTimeout="00:20:00" sendTimeout="00:20:00" receiveTimeout="00:20:00" closeTimeout="00:20:00"
maxBufferSize="20000000" maxBufferPoolSize="20000000" maxReceivedMessageSize="20000000">
<readerQuotas maxStringContentLength="12000" />
</binding>
<binding name="WcfTest.Bindings.Streaming.Http" transferMode="Streamed"
openTimeout="03:00:00" sendTimeout="03:00:00" receiveTimeout="03:00:00" closeTimeout="03:00:00"
maxReceivedMessageSize="1073741824"><!-- 1GB -->
</binding>
</basicHttpBinding>
<netTcpBinding>
<binding
openTimeout="00:20:00" sendTimeout="00:20:00" receiveTimeout="00:20:00" closeTimeout="00:20:00"
maxBufferSize="20000000" maxBufferPoolSize="20000000" maxReceivedMessageSize="20000000">
<readerQuotas maxStringContentLength="12000" />
</binding>
<binding name="WcfTest.Bindings.Streaming.Tcp" transferMode="Streamed"
openTimeout="03:00:00" sendTimeout="03:00:00" receiveTimeout="03:00:00" closeTimeout="03:00:00"
maxReceivedMessageSize="1073741824"><!-- 1GB -->
</binding>
</netTcpBinding>
</bindings>
<client>
<!-- Foo -->
<endpoint name="WcfTest.Endpoints.Foo.Http" address="http://localhost:9930/FooService.svc" binding="basicHttpBinding" contract="WcfTest.Contracts.IFooService" />
<endpoint name="WcfTest.Endpoints.Foo.Tcp" address="net.tcp://localhost:9931/FooService.svc" binding="netTcpBinding" contract="WcfTest.Contracts.IFooService" />
<!-- Streaming -->
<endpoint name="WcfTest.Endpoints.Streaming.Http" address="http://localhost:9930/StreamingService.svc" binding="basicHttpBinding" bindingConfiguration="WcfTest.Bindings.Streaming.Http" contract="WcfTest.Contracts.IStreamingService" />
<endpoint name="WcfTest.Endpoints.Streaming.Tcp" address="net.tcp://localhost:9931/StreamingService.svc" binding="netTcpBinding" bindingConfiguration="WcfTest.Bindings.Streaming.Tcp" contract="WcfTest.Contracts.IStreamingService" />
</client>
</system.serviceModel>
</configuration>
console test call
static void Main(string[] args)
{
Console.WriteLine("starting WcfTest client...");
Console.WriteLine();
PingFoo(Contracts.Enums.Protocol.Http);
PingFoo(Contracts.Enums.Protocol.Tcp);
Console.WriteLine();
PingStreaming(Contracts.Enums.Protocol.Http);
// only this call errors:
PingStreaming(Contracts.Enums.Protocol.Tcp);
Console.WriteLine();
Console.Write("ENTER to exit WcfTest client...");
Console.ReadLine();
}
private static bool PingFoo(Contracts.Enums.Protocol protocol)
{
FooProxy pxy = new FooProxy(protocol);
return PingProxy<IFooService>(pxy, protocol);
}
private static bool PingStreaming(Contracts.Enums.Protocol protocol)
{
StreamingProxy pxy = new StreamingProxy(protocol);
return PingProxy<IStreamingService>(pxy, protocol);
}
private static bool PingProxy<T>(ProxyServiceBase<T> pxy, Contracts.Enums.Protocol protocol) where T : IServiceBase
{
bool success = pxy.Ping();
Console.WriteLine("ping {0} {1}: {2}", pxy.GetType().Name, protocol, success ? " success" : " FAILED");
if (pxy != null)
pxy.Close();
return success;
}
Any ideas why this would be failing on one IIS site, under one of two protocols, and not on another? (It is not this.)
EDIT: In preparation for taking this bounty-side, a couple clarifications on this test service and client:
First, per commenter's suggestion, svcutil works fine against http, but fails against net.tcp. Here is the complete output of that run:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin>svcutil
net.tcp://localhost:9931/StreamingService.svc Microsoft (R) Service
Model Metadata Tool [Microsoft (R) Windows (R) Communication
Foundation, Version 3.0.4506.2152] Copyright (c) Microsoft
Corporation. All rights reserved.
Attempting to download metadata from
'net.tcp://localhost:9931/StreamingService.svc' using WS-Metadata
Exchange. This UR L does not support DISCO. Microsoft (R) Service
Model Metadata Tool [Microsoft (R) Windows (R) Communication
Foundation, Version 3.0.4506.2152] Copyright (c) Microsoft
Corporation. All rights reserved.
Error: Cannot obtain Metadata from
net.tcp://localhost:9931/StreamingService.svc
If this is a Windows (R) Communication Foundation service to which you
have access, please check that you have enabled m etadata publishing
at the specified address. For help enabling metadata publishing,
please refer to the MSDN documentat ion at
http://go.microsoft.com/fwlink/?LinkId=65455.
WS-Metadata Exchange Error
URI: net.tcp://localhost:9931/StreamingService.svc
Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:9931/StreamingService.svc'.
The socket connection was aborted. This could be caused by an error processing your message or a receive timeout bei ng exceeded by
the remote host, or an underlying network resource issue. Local socket
timeout was '00:04:59.9929993'.
An existing connection was forcibly closed by the remote host
If you would like more help, type "svcutil /?"
Second, removing "transferMode="Streamed" from the Wcf.Bindings.Streaming.Tcp web and app configs pasted above allows the service to ping just fine. It does not improve the svcutil situation.
Finally, here are some other things I have tried, with no improvement:
Various versions of serviceMetadata attribute in serviceBehaviors (which I understand to be overridden by the existence of mex endpoints anyway)
Various named serviceBehaviors instead of the default I include
Various configurations of security mode= on the binding, especially None
Various disablings of all other bindings, endpoints, etc. in hopes that one thing might be getting in another's way
It seems that transferMode of tcp communication either at service side or client side to Streamed and the other side still uses the default mode which is Buffered.
Are you forgetting something in "StreamingProxy" in case of TCP?
May be this will help...
http://social.msdn.microsoft.com/Forums/vstudio/en-US/37e32166-63f3-4cb9-ab81-14caa50cd91e/help-with-error-message-the-net-framing-mode-being-used-is-not-supported-by-?forum=wcf
Also I am trying looking further for your solution...
Similar questions are flowing around and I looked at all of them. It appears none solve my issue.
-- UPDATE: --
I am trying to upload a document (pdf, doc, or whatever) to a database using WCF Service.
The call to the service looks like this:
using (var cw = new WCFClientWrapper<ICommonService>())
{
cw.Channel.DocumentInsert(content, filename, contentType);
}
Here is signature for the contract:
[OperationContract]
void DocumentInsert(byte[] content, string fileName, string contentType);
Please note that I am passing byte array for the content as this is what needs to be passed to store things in DB.
-- End of Update --
I can successfully upload a small file (couple kb). However, when I try to upload something larger (20kb), I get an Exception:
The formatter threw an exception while trying to deserialize the
message: Error in deserializing body of request message for operation
'DocumentInsert'. The maximum array length quota (16384) has been
exceeded while reading XML data. This quota may be increased by
changing the MaxArrayLength property on the XmlDictionaryReaderQuotas
object used when creating the XML reader. Line 1, position 31774.
The error seems to be obvious... just go and increase the MaxArrayLength. I have done that without any successful result. Below are the relevant parts from my web.configs
Client:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="SecureBehavior">
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="WSHttpBinding_Service" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="262144" messageEncoding="Text"
textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="5242880" maxArrayLength="2147483646" maxBytesPerRead="4096" maxNameTableCharCount="5242880" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://dev.svc.someurl.com/CommonService.svc"
binding="basicHttpBinding"
bindingConfiguration="WSHttpBinding_Service"
behaviorConfiguration="SecureBehavior"
contract="MyApp.Contracts.ServiceContracts.ICommonService"
name="MyApp.Contracts.ServiceContracts.ICommonService">
</endpoint>
</client>
</system.serviceModel>
Service:
<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>
<bindings>
<basicHttpBinding>
<binding name="MyBasicHttpBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="MyApp.WCFServices.CommonService">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="MyBasicHttpBinding"
contract="MyApp.Contracts.ServiceContracts.ICommonService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
<service name="MyApp.WCFServices.AccountService">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="MyBasicHttpBinding"
contract="MyApp.Contracts.ServiceContracts.IAccountService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Attaching diagnostics shows:
Construct Service: no errors/warnings
Open Service: warning - Configuration evaluation context not found - No matching tag was found. Default endpoints added.
Listen at 'http://dev.svc.someurl.com/CommonService.svc' : no
errors/warnings
Processing message 1 : no errors/warnings
Processing Action 'http://tempuri.org/ICommonService/DocumentInsert'.
: throws exception that I wrote at the very beginning.
Any help is appreciated.
I have came across with the same exception a few months ago. To send/receive large data to/from WCF service you have to set transferMode="Streamed". When use transfermode as Buffered, it actually puts the entire file in memory before uploading/downloading. Therefore a large buffer is required on both the web client and the WCF service host.Whereas Streamed transfers can improve the scalability of a service by eliminating the need for large memory buffers. For more information on transfermode, see the MSDN article on TransferMode Enumeration
All right, after a day of struggling I finally found an issue.
I just had to make sure that the name of the tag in WCF web.config matches the namespace and the name of the service:
<service name="ServicesImplementation.WcfServices.CommonService">
Unfortunately it was not something that you guys would see based on the information that I provided.
I am trying to build a WCF service that allows me to send large binary files from clients to the service.
However I am only able to successfully transfer files up to 3-4MB. (I fail when I try to transfer 4.91MB and, off course, anything beyond)
The Error I get if I try to send the 4.91MB file is:
Exception Message: An error occurred while receiving the HTTP response to http://localhost:56198/Service.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.
Inner Exception Message: The underlying connection was closed: An unexpected error occurred on a receive.
Inner Exception Message: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
Inner Exception Message: An existing connection was forcibly closed by the remote host
This error occurs at client side as soon as the byte[] file is sent as a method parameter to the exposed service method.
I have a breakpoint at the service method's first line, in case of successful file transfers (below 3MB) that break point is hit and the file gets transferred. However in this case as soon as the method is called, the error comes. The breakpoint in the service is not hit in case of this error.
I am going to paste my sections of my Service Web.config and Asp Page (Client) Web.config. If you also require the code that send the file and accepts the file, let me know, I'll send that as well.
Service Web.Config
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttpEndpointBinding" closeTimeout="01:01:00"
openTimeout="01:01:00" receiveTimeout="01:10:00" sendTimeout="01:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483646" maxBufferPoolSize="2147483646" maxReceivedMessageSize="2147483646"
messageEncoding="Mtom" textEncoding="utf-8" transferMode="StreamedRequest"
useDefaultWebProxy="true">
<readerQuotas maxDepth="2147483646" maxStringContentLength="2147483646" maxArrayLength="2147483646"
maxBytesPerRead="2147483646" maxNameTableCharCount="2147483646" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="DragDrop.Service.ServiceBehavior" name="DragDrop.Service.Service">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpEndpointBinding" contract="DragDrop.Service.IService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DragDrop.Service.ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Client (Asp.net page) Web.Config
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483646" maxBufferPoolSize="2147483646" maxReceivedMessageSize="2147483646"
messageEncoding="Mtom" textEncoding="utf-8" transferMode="StreamedResponse"
useDefaultWebProxy="true">
<readerQuotas maxDepth="2147483646" maxStringContentLength="2147483646" maxArrayLength="2147483646"
maxBytesPerRead="2147483646" maxNameTableCharCount="2147483646" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="">
<extendedProtectionPolicy policyEnforcement="Never" />
</transport>
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="debuggingBehaviour">
<dataContractSerializer maxItemsInObjectGraph="2147483646" />
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="http://localhost:56198/Service.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService" contract="ServiceReference.IService"
name="BasicHttpBinding_IService" behaviorConfiguration="debuggingBehaviour" />
</client>
</system.serviceModel>
(While I agree that streaming transfer would be preferrable, the below should make it work without any other changes)
You also need to increase the maximum message length in the Web.config:
<configuration>
<system.web>
<httpRuntime maxMessageLength="409600"
executionTimeoutInSeconds="300"/>
</system.web>
</configuration>
This will set the maximum message length to 400 MB (parameter is in kB). Check this MSDN page for more information.
As pointed out, try using Streaming Transfer, here's some example code showing both sending and receiving (possibly) large amounts of data using streamed transfer.
Use a binding like this, notice the MaxReceivedMessageSize and TranferMode settings.
<binding name="Streaming_Binding" maxReceivedMessageSize="67108864"
messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed">
</binding>
Add some service code:
[OperationContract]
public Stream GetLargeFile()
{
return new FileStream(path, FileMode.Open, FileAccess.Read);
}
[OperationContract]
public void SendLargeFile(Stream stream)
{
// Handle stream here - e.g. save to disk
ProcessTheStream(stream);
// Close the stream when done processing it
stream.Close();
}
And some client code:
public Stream GetLargeFile()
{
var client = /* create proxy here */;
try
{
var response = client.GetLargeFile();
// All communication is now handled by the stream,
// thus we can close the proxy at this point
client.Close();
return response;
}
catch (Exception)
{
client.Abort();
throw;
}
}
public void SendLargeFile(string path)
{
var client = /* create proxy here */;
client.SendLargeFile(new FileStream(path, FileMode.Open, FileAccess.Read));
}
Also, make sure you are not getting a timeout, a large file might take a while to transfer (the default receiveTimeout is 10 minutes though).
You can download Microsoft WCF/WF sample code here (top C# link is broken at the time of writing but other samples code seems ok).
Have you had a look at using Streaming Transfer?
Windows Communication Foundation (WCF)
can send messages using either
buffered or streamed transfers. In the
default buffered-transfer mode, a
message must be completely delivered
before a receiver can read it. In
streaming transfer mode, the receiver
can begin to process the message
before it is completely delivered. The
streaming mode is useful when the
information that is passed is lengthy
and can be processed serially.
Streaming mode is also useful when the
message is too large to be entirely
buffered.
http://msdn.microsoft.com/en-us/library/ms789010.aspx
I'll echo what others have said and say that using a Streaming Transfer is the way to go when using Windows Communication Foundation. Below is an excellent guide that explains all of the steps in order to stream files over WCF. It's quite comprehensive and very informative.
Here it is: Guide on Streaming Files over WCF.