Silverlight out of browser mode - c#

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

Related

WCF client failed when receive bytes array over 350 MB

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.

Wcf TimeoutException

I create WCF application that used Azure Cloud Service.
Sometimes client catch TimeoutException About 3 times a day.
Now, Total of client amounts about 100 clients.So The 100 cleint access wcf server at the same time.
The setting is below.How do I optimize? or Do I mistake?
WorkerRols.cs
ServicePointManager.DefaultConnectionLimit = Int32.MaxValue;
var netTcpBinding = new NetTcpBinding();
netTcpBinding.Security.Mode = SecurityMode.Transport;
netTcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
netTcpBinding.MaxBufferPoolSize = 314572800;
netTcpBinding.MaxReceivedMessageSize = 20971520;
netTcpBinding.MaxBufferSize = 20971520;
netTcpBinding.ListenBacklog = 2147483647;
netTcpBinding.MaxConnections = 2147483647;
netTcpBinding.ReceiveTimeout = new TimeSpan(0, 1, 0);
//binding.SendTimeout = new TimeSpan(0, 3, 0);
//binding.CloseTimeout = new TimeSpan(0, 3, 0);
netTcpBinding.ReliableSession.Enabled = true;
netTcpBinding.ReliableSession.InactivityTimeout = new TimeSpan(0, 1, 0);
ServiceThrottlingBehavior throttle;
throttle = host.Description.Behaviors.Find<ServiceThrottlingBehavior>();
if (throttle == null)
{
LogWriter.PutInfo(CLASSNAME, "throttle == null");
throttle = new ServiceThrottlingBehavior();
throttle.MaxConcurrentCalls = Int32.MaxValue;
throttle.MaxConcurrentSessions = Int32.MaxValue;
throttle.MaxConcurrentInstances = Int32.MaxValue;
host.Description.Behaviors.Add(throttle);
}
app.config
<system.net>
<connectionManagement>
<add address="*" maxconnection="65535"/>
</connectionManagement>
</system.net>

Sharepoint 2010 GetListItems with Webservice - ListSoapClient with DefaultNetworkCredentials

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;
}

WCF client request returns bad request (400)

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.

WCF CustomBing exception - AddressingNone does not support adding WS-Addressing headers

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
};

Categories

Resources