When I receive bytes array over 350 MB, I am getting error as "The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error."
Client side config
var binding = new NetTcpBinding(SecurityMode.None)
{
PortSharingEnabled = true,
MaxBufferSize = Int32.MaxValue,
MaxReceivedMessageSize = Int32.MaxValue,
ReaderQuotas = new XmlDictionaryReaderQuotas
{
MaxArrayLength = Int32.MaxValue,
MaxBytesPerRead = Int32.MaxValue,
MaxDepth = Int32.MaxValue,
MaxNameTableCharCount = Int32.MaxValue,
MaxStringContentLength = Int32.MaxValue,
},
MaxBufferPoolSize = 0,
TransactionFlow = false,
TransactionProtocol = TransactionProtocol.Default,
TransferMode = TransferMode.Streamed,
OpenTimeout = new TimeSpan(0, 10, 0),
CloseTimeout = new TimeSpan(0, 10, 0),
SendTimeout = new TimeSpan(0, 10, 0),
ReceiveTimeout = new TimeSpan(0, 10, 0)
};
container.Register(Component.For<IFtpsServiceFacade>()
.AsWcfClient(
new DefaultClientModel(
WcfEndpoint.BoundTo(binding)
.At(string.Format("net.tcp://{0}/FileService.Ftps",
"localhost")))
));
Server side config.
var binding = new NetTcpBinding
{
PortSharingEnabled = true,
MaxBufferSize = Int32.MaxValue,
MaxReceivedMessageSize = Int32.MaxValue,
ReaderQuotas = new XmlDictionaryReaderQuotas
{
MaxArrayLength = Int32.MaxValue,
MaxBytesPerRead = Int32.MaxValue,
MaxDepth = Int32.MaxValue,
MaxNameTableCharCount = Int32.MaxValue,
MaxStringContentLength = Int32.MaxValue,
},
MaxBufferPoolSize = 0,
TransactionFlow = false,
TransactionProtocol = TransactionProtocol.Default,
TransferMode = TransferMode.Buffered,
OpenTimeout = new TimeSpan(0, 10, 0),
CloseTimeout = new TimeSpan(0, 10, 0),
SendTimeout = new TimeSpan(0, 10, 0),
ReceiveTimeout = new TimeSpan(0, 10, 0)
};
container.Register(Component.For<IFtpsServiceFacade>()
.ImplementedBy<FtpsServiceFacade>()
.AsWcfService(
new DefaultServiceModel()
.AddEndpoints(
WcfEndpoint.BoundTo(binding)
.At(string.Format("net.tcp://{0}/FileService.Ftps",
"localhost"))
)).LifestyleSingleton() );
The establishment of the communication channel between the server-side and the client-side requires that the server-side and the client-side have the same binding settings. Therefore, the above error occurred. In order to solve this problem, we should change the settings on the server-side instead of the client-side. The max size of the supported file above 2GB, finished by the below configuration.
NetTcpBinding binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.None;
binding.MaxBufferSize = Int32.MaxValue;
binding.MaxBufferPoolSize = Int32.MaxValue;
binding.MaxReceivedMessageSize = Int32.MaxValue;
Especially to the security mode, it should be fully consistent with the setting located on the client-side.
Feel free to let me know if the problem still exists.
Related
I want to get some ListItems of a SharePoint 2010 List with a Win8 App. Everything works fine when I set the Credentials manually like:
BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
basicHttpBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
EndpointAddress endpoint = new EndpointAddress("http://site1/site2/_vti_bin/Lists.asmx");
string listName = "{4e661b3b-d0a9-4440-b98f-3f3ef41a44a7}";
string viewName = "{f1ba8d46-ad36-40ef-b4bc-6f74ea87b5d7}";
string rowLimit = "25";
XElement ndQuery = new XElement("Query");
XElement ndViewFields = new XElement("ViewFields");
XElement ndQueryOptions = new XElement("QueryOptions");
MyService.ListsSoapClient client = new MyService.ListsSoapClient(basicHttpBinding, endpoint);
client.ClientCredentials.Windows.ClientCredential.UserName = "user";
client.ClientCredentials.Windows.ClientCredential.Password = "pw";
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
MyService.GetListItemsResponse response = await client.GetListItemsAsync(listName, viewName, ndQuery, ndViewFields, rowLimit, ndQueryOptions, null);
If I try to set the Credentials with the logged on Windows user i get the following Unauthorized error:
The HTTP request is unauthorized with client authentication scheme
'Negotiate'. The authentication header received from the server was
'Negotiate,NTLM'.
client.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
Can you help me?
try this (use default credentials instead of specific):
private ListsSoapClient CreateListsSoapClient(string siteUrl, string siteUserName, string sitePassword)
{
var basicHttpBinding = new BasicHttpBinding
{
CloseTimeout = new TimeSpan(00, 5, 00),
OpenTimeout = new TimeSpan(00, 5, 00),
ReceiveTimeout = new TimeSpan(00, 5, 00),
SendTimeout = new TimeSpan(00, 5, 00),
TextEncoding = Encoding.UTF8,
MaxReceivedMessageSize = int.MaxValue,
MaxBufferSize = int.MaxValue,
Security =
{
Mode = BasicHttpSecurityMode.TransportCredentialOnly
},
ReaderQuotas =
{
MaxArrayLength = int.MaxValue,
MaxBytesPerRead = int.MaxValue,
MaxStringContentLength = int.MaxValue
}
};
basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
var url = string.Format("{0}/_vti_bin/Lists.asmx", siteUrl);
var address = new EndpointAddress(url);
var listsSoapClient = new ListsSoapClient(basicHttpBinding, address);
listsSoapClient.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Delegation;
listsSoapClient.ChannelFactory.Credentials.Windows.ClientCredential = new NetworkCredential(siteUserName, sitePassword);
listsSoapClient.ChannelFactory.Credentials.Windows.AllowNtlm = true;
return listsSoapClient;
}
I have run into the dreaded
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.
error. No problem, I know you have to change the attributes on the web.config for the client and server to increase it up. I am creating my client in code however, and I am trying to manipulate these properties in kind.
Here I am creating the client, and assigning it to session. I will later call it through a class level _client field.
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
binding.CloseTimeout = new TimeSpan(00, 05, 00);
binding.OpenTimeout = new TimeSpan(00, 05, 00);
binding.ReceiveTimeout = new TimeSpan(00, 05, 00);
binding.SendTimeout = new TimeSpan(00, 05, 00);
binding.TextEncoding = System.Text.Encoding.UTF8;
binding.MaxReceivedMessageSize = int.MaxValue;
binding.MaxBufferSize = int.MaxValue;
binding.MaxBufferPoolSize = int.MaxValue;
binding.Name = "BasicHttpBinding_Test";
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
EndpointAddress endpointAddress = new EndpointAddress(wcfUrl);
HttpContext.Current.Session["Client"] = new TestClient(binding, endpointAddress);
I change the binding in code, and I could see in a watch these values are indeed taking effect. The _client in the below is the TestClient that was created before and stored in Session. However, the error persists. Is there another property I am missing?
Binding binding = _client.Endpoint.Binding;
binding.CloseTimeout = new TimeSpan(00, 05, 00);
binding.OpenTimeout = new TimeSpan(00, 05, 00);
binding.ReceiveTimeout = new TimeSpan(00, 05, 00);
binding.SendTimeout = new TimeSpan(00, 05, 00);
binding.GetType().GetProperty("ReaderQuotas").SetValue(binding, XmlDictionaryReaderQuotas.Max, null);
binding.GetType().GetProperty("TransferMode").SetValue(binding, TransferMode.Streamed, null);
binding.GetType().GetProperty("MaxBufferPoolSize").SetValue(binding, int.MaxValue, null);
binding.GetType().GetProperty("MaxBufferSize").SetValue(binding, int.MaxValue, null);
binding.GetType().GetProperty("MaxReceivedMessageSize").SetValue(binding, int.MaxValue, null);
both client and server binding would need
maxReceivedMessageSize
Setting your values to Max is a bad idea. You really want to try and limit that down to what you believe your usage is. Unless you really need 2gb file transfers and the server can handle that.
My client application use a WCF web service which is hosted in my local IIS. This web service use for upload an image. Once image size become bigger it gives bad request(400).
Client is configure to dynamically get the web service URL.
Client Code
string serviceUrl=GetUrl(); /* http://localhost:85/ImageUploaderService.svc */
TimeSpan timeOut = new TimeSpan(0, 30, 0);
EndpointAddress endPoint = new EndpointAddress(serviceUrl);
BasicHttpBinding binding = new BasicHttpBinding()
{
CloseTimeout = timeOut,
MaxReceivedMessageSize = 65536,
OpenTimeout = timeOut,
ReceiveTimeout = timeOut,
SendTimeout = timeOut,
MaxBufferSize = 65536,
MaxBufferPoolSize = 524288,
UseDefaultWebProxy = true,
};
binding.ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas()
{
MaxArrayLength = 64000000,
MaxStringContentLength = 8192,
MaxDepth = 32,
MaxNameTableCharCount = 16384,
MaxBytesPerRead = 4096
};
client = new ImageUploaderServiceClient(binding, endPoint);
Web Service side
<basicHttpBinding>
<binding maxBufferSize="64000000" maxReceivedMessageSize="64000000" maxBufferPoolSize="64000000">
<readerQuotas maxDepth="64000000" maxStringContentLength="64000000" maxArrayLength="64000000" maxBytesPerRead="64000000" />
<security mode="None"/>
</binding>
</basicHttpBinding>
What is the wrong I am doing. Please guide me through the correct way.
You should increase MaxReceivedMessageSize on client side as well probably:
BasicHttpBinding binding = new BasicHttpBinding()
{
MaxReceivedMessageSize = 64000000,
MaxBufferSize = 64000000,
MaxBufferPoolSize = 64000000,
// .....
};
binding.ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas()
{
MaxArrayLength = 64000000,
MaxStringContentLength = 64000000,
MaxDepth = 64000000,
MaxBytesPerRead = 64000000
};
I had the same problem once - the server and client binding configuration should be the same.
Does silverlight support SSL in oob mode? I have SSL turned on and it works fine in browser, but it doesnt connect oob mode. Is there something I am missing?
Thanks
EDIT:
_serviceHost = new ServiceHost(typeof(ApplicationService), new Uri(BaseAddress));
_serviceHost.Description.Behaviors.Add(new ServiceMetadataBehavior { HttpsGetEnabled = true });
var serviceBinding = new BasicHttpBinding(BasicHttpSecurityMode.Transport)
{
MessageEncoding = WSMessageEncoding.Text,
TextEncoding = Encoding.UTF8,
BypassProxyOnLocal = false,
UseDefaultWebProxy = true,
CloseTimeout = new TimeSpan(10, 0, 0),
OpenTimeout = new TimeSpan(10, 0, 0),
SendTimeout = new TimeSpan(10, 0, 0),
ReceiveTimeout = new TimeSpan(10, 0, 0),
HostNameComparisonMode = HostNameComparisonMode.StrongWildcard,
MaxBufferPoolSize = int.MaxValue,
MaxReceivedMessageSize = int.MaxValue,
AllowCookies = false,
TransferMode = TransferMode.StreamedResponse,
ReaderQuotas =
{
MaxDepth = 32,
MaxStringContentLength = int.MaxValue,
MaxArrayLength = 6553600,
MaxBytesPerRead = 4096,
MaxNameTableCharCount = 16384
}
};
var policyRetrieverBinding = new WebHttpBinding(WebHttpSecurityMode.Transport)
{
BypassProxyOnLocal = false,
UseDefaultWebProxy = true,
CloseTimeout = new TimeSpan(10, 0, 0),
OpenTimeout = new TimeSpan(10, 0, 0),
SendTimeout = new TimeSpan(10, 0, 0),
ReceiveTimeout = new TimeSpan(10, 0, 0),
HostNameComparisonMode = HostNameComparisonMode.StrongWildcard,
MaxBufferPoolSize = int.MaxValue,
MaxReceivedMessageSize = int.MaxValue,
AllowCookies = false,
TransferMode = TransferMode.StreamedResponse,
ReaderQuotas =
{
MaxDepth = 32,
MaxStringContentLength = int.MaxValue,
MaxArrayLength = 6553600,
MaxBytesPerRead = 4096,
MaxNameTableCharCount = 16384
}
};
//service endpoint
_serviceHost.AddServiceEndpoint(typeof(IApplicationService), serviceBinding, ServiceEndPoint);
//mex endpoint for metadata
_serviceHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpsBinding(), "mex");
//policy retriever endpoint
_serviceHost.AddServiceEndpoint(typeof(IPolicyRetriever), policyRetrieverBinding, string.Empty)
.Behaviors.Add(new WebHttpBehavior());
//so we get detailed exceptions
_serviceHost.Description.Behaviors.Find<ServiceDebugBehavior>()
.IncludeExceptionDetailInFaults = true;
_serviceHost.Open();
The service endpoint is configured to use :
"https://" + Environment.MachineName
I keep getting the following exception when I use my pragmatically created CustomBinding.
Addressing Version 'AddressingNone (http://schemas.microsoft.com/ws/2005/05/addressing/none)' does not support adding WS-Addressing headers.
Is there any way to resolve this issue?
private static CustomBinding CreateCustomBinding(bool useHttps)
{
BindingElement security;
BindingElement transport;
if (useHttps)
{
security = SecurityBindingElement.CreateSecureConversationBindingElement(
SecurityBindingElement.CreateUserNameOverTransportBindingElement());
transport = new HttpsTransportBindingElement
{
MaxBufferPoolSize = 2147483647,
MaxBufferSize = 2147483647,
MaxReceivedMessageSize = 2147483647,
};
}
else
{
security = SecurityBindingElement.CreateSecureConversationBindingElement(
SecurityBindingElement.CreateUserNameForSslBindingElement(true));
transport = new HttpTransportBindingElement
{
MaxBufferPoolSize = 2147483647,
MaxBufferSize = 2147483647,
MaxReceivedMessageSize = 2147483647,
};
}
var encoding = new MtomMessageEncodingBindingElement
{
MaxReadPoolSize = 64,
MaxWritePoolSize = 16,
MaxBufferSize = 2147483647,
MessageVersion = MessageVersion.Soap11,
WriteEncoding = System.Text.Encoding.UTF8
};
//var encoding = new TextMessageEncodingBindingElement();
var customBinding = new CustomBinding();
customBinding.Elements.Add(security);
customBinding.Elements.Add(encoding);
customBinding.Elements.Add(transport);
return customBinding;
}
Just in case anyone is interested, below is my solution. I added an if for dealing with the text encoding section and also updated the SecurityBindingElement under if (useHttps):
private static CustomBinding CreateCustomBinding(bool useHttps, bool textEncoding)
{
BindingElement security;
BindingElement encoding;
BindingElement transport;
if (useHttps)
{
var seq = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
seq.MessageSecurityVersion =
MessageSecurityVersion.
WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
seq.SecurityHeaderLayout = SecurityHeaderLayout.Lax;
seq.DefaultAlgorithmSuite = SecurityAlgorithmSuite.Default;
security = seq;
transport = new HttpsTransportBindingElement
{
MaxBufferPoolSize = 2147483647,
MaxBufferSize = 2147483647,
MaxReceivedMessageSize = 2147483647,
};
}
else
{
security = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
transport = new HttpTransportBindingElement
{
MaxBufferPoolSize = 2147483647,
MaxBufferSize = 2147483647,
MaxReceivedMessageSize = 2147483647,
};
}
if (textEncoding)
encoding = new TextMessageEncodingBindingElement
{
MaxReadPoolSize = 64,
MaxWritePoolSize = 16,
MessageVersion = MessageVersion.Soap11,
WriteEncoding = System.Text.Encoding.UTF8
};
else
encoding = new MtomMessageEncodingBindingElement
{
MaxReadPoolSize = 64,
MaxWritePoolSize = 16,
MaxBufferSize = 2147483647,
MessageVersion = MessageVersion.Soap11,
WriteEncoding = System.Text.Encoding.UTF8
};
var customBinding = new CustomBinding();
customBinding.Elements.Add(security);
customBinding.Elements.Add(encoding);
customBinding.Elements.Add(transport);
return customBinding;
}
It worked for me with small changes. Thanks Tawani. Just I set AuthenticationSheme to Basic for HTTPSTransportBinidingElement.
transport = new HttpsTransportBindingElement
{
MaxBufferPoolSize = 2147483647,
MaxBufferSize = 2147483647,
MaxReceivedMessageSize = 2147483647,
AuthenticationScheme = System.Net.AuthenticationSchemes.Basic
};