On a website i am maintaining dependant on customer needs, SSL is either turned on, or off.
I have the following binding set up in the applications Web.Config
<bindings>
<basicHttpBinding>
<binding name="TransferService" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" transferMode="Streamed">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
I would like to extract the binding's information and use it inside the websites application start event, but more specifically i would like to find out the security mode that is currently being used.
With this, i will be able to redirect the website to use HTTPS is the security mode="Transport" and not redirect if the website uses security mode="None"
So, how would i go about getting this binding into a controller?
I have tried the standard
IDictionary sampleTable = ictionary)ConfigurationManager.GetSection("bindings");
as well as something along the lines of
string securitsetting = ConfigurationManager.AppSettings[security]
but as i can obviously see, it is not the correct way to go about it!
Related
Hello I have one question about the wcf timeout.
I set the default timeout value 00:10:00 minutes.
but some service need more than 10:00 minutes. so I need to change timeout in server side programmatically.
I tried to change it but I can not find the way. Is there have any solution for this?
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="TCPBinding" portSharingEnabled="true" receiveTimeout="00:10:00" openTimeout="00:10:00" sendTimeout="00:10:00" closeTimeout="00:10:00" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="None"/>
<reliableSession enabled="true" inactivityTimeout="00:10:00"/>
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
Ver2
I tried to check timeout with below code but still doesn't change.
OperationContext.Current.Channel.OperationTimeout
I need to add this block to my binding in my web.config when there is a release compilation :
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
Here is the snippet of my web.config :
<bindings>
<basicHttpBinding>
<binding name="BasicBinding" closeTimeout="24.20:31:23.6470000" openTimeout="24.20:31:23.6470000" receiveTimeout="24.20:31:23.6470000" sendTimeout="24.20:31:23.6470000" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
And here is my transformation method web.release.config following this documentation :
<bindings>
<basicHttpBinding>
<binding>
<security mode="Transport" xdt:Transform="InsertAfter(/configuration/system.serviceModel/bindings/basicHttpBinding/binding)">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
I face the following erreur on compilation on VSTS :
[error]Sources\Foo.Interface\Web.Release.config(16,6): Error : No element in the source document matches '/configuration/bindings/basicHttpBinding'
Of course I tried with other similar values but facing all time the same issue.
Not clear about the error. But if you want to insert security node into your web.config's binding node, you could write the following code in your web.release.config
using xdt:Transform="Insert"
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicBinding" >
<security mode="Transport" xdt:Transform="Insert" >
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
I am facing 413 error in WCF service even if maxReceivedMessageSize is set to max i.e. 2147483647 and actual message size is less than 50kb.
This issue appears only when there is some ideal time between two request.
The exact scenario is as below:
1. Send 1000 messages each of them is around 38 kb. STATUS: PASS
2. Wait for sometime(Minimum 3 mins)
3. Send 1 message. STATUS: FAIL. (413 error)
I am using ws2007FederationHttpBinding. Web.config tag is as below:
<ws2007FederationHttpBinding>
<binding name="federationHttpBinding" openTimeout="00:04:00" closeTimeout="00:04:00" receiveTimeout="00:04:00" sendTimeout="00:40:00" maxReceivedMessageSize="2147483647">
<!-- <readerQuotas maxArrayLength="2147483647" maxDepth="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647" /> -->
<security mode="TransportWithMessageCredential">
<message establishSecurityContext="false">
</message>
</security>
</binding>
</ws2007FederationHttpBinding>
Client side binding tag is as below:
<ws2007FederationHttpBinding>
<binding name="AuthorizationBinding" openTimeout="00:04:00" closeTimeout="00:04:00" receiveTimeout="00:04:00" sendTimeout="00:40:00" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
<readerQuotas maxArrayLength="2147483647" maxDepth="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/>
<security mode="TransportWithMessageCredential">
<message establishSecurityContext="false"/>
</security>
</binding>
</ws2007FederationHttpBinding>
I think you could solve this problem by removing the name attribute from the binding tag, A similar problem could be found here
WCF service maxReceivedMessageSize basicHttpBinding issue
You also have to set maxBufferSize
<binding name="federationHttpBinding"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647"
maxBufferPoolSize="2147483647">
I have two environments running the same WCF web service but one of them seems to have a 3-5 minute delay returning the XML data. The slow down seems to occur in relation to the size of the data being returned. The web service just retrieves an XML string from a database so the processing time is constant.
The endpoint bindings are the same for both but I'm wondering what else would cause a delay.
I ran a trace and it shows that the TransportReceive happens at the same time on both environments, but on the delayed environment the ServiceLevelReceiveReply occurs after 3-5 minutes.
Any idea what could cause this? I'm happy to provide as much data as possible.
Here are the two bindings that are used. MyPolicySoap is used for getting the XML.
<basicHttpBinding>
<binding name="MyPolicySoap" closeTimeout="00:11:00" openTimeout="00:11:00" receiveTimeout="00:10:00" sendTimeout="00:11:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="5000000" maxBufferPoolSize="524288" maxReceivedMessageSize="5000000" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="5000000" maxArrayLength="16384" maxBytesPerRead="5000000" maxNameTableCharCount="16384"/>
<security mode="None">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="MyConfig" maxReceivedMessageSize="2147483647">
<readerQuotas maxStringContentLength="2147483647"/>
<security mode="None">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm=""><!--<extendedProtectionPolicy policyEnforcement="Never" />--></transport>
<message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="true"/>
</security>
</binding>
</wshttpbinding>
I'm trying to send a long string by WCF, around 64k chars long. When sending a long string, the I get the HTTP error 400. But when I send shorter string, everything works fine.
Here is the WCF interface and app.config that I use.
My message contract:
[MessageContract]
public class MessageClass
{
[MessageHeader(MustUnderstand = true)]
public string id;
[MessageBodyMember(Order=1)]
public string realMessage; // Long string
}
I have tried to change the app.config settings by rising the values:
<bindings>
<basicHttpBinding>
<binding
name="ws"
transferMode="Streamed"
messageEncoding="Mtom"
maxReceivedMessageSize="10067108864">
<readerQuotas
maxDepth="32"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
Is there any other value that I should change?
You also need to set the "maxBufferSize" and "maxBufferPoolSize" on your binding:
<bindings>
<basicHttpBinding>
<binding
name="ws"
transferMode="Streamed"
messageEncoding="Mtom"
maxReceivedMessageSize="10067108864"
maxBufferSize="500000" maxBufferPoolSize="500000">
<readerQuotas
maxDepth="32"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
Those also default to 64K in WCF's standard bindings. However, since you're using the "transferMode=Streamed", this really shouldn't be an issue - maybe there's something else going on. How about also increasing the sendTimeout setting? Maybe your service is just taking a tad too long to respond.
Marc
See the maxReceivedMessageSize attribute of the basicHttpBinding # http://msdn.microsoft.com/en-us/library/ms731361.aspx. Coindicentally, the default is 65,536 KB.