WCF - 400 Bad request - 2 Days configuring - asp.net

I'm trying to solve my problem when I send class Product (including a binary[] Picture). If I send a Product containing a picture of around 14KB it works, but if I increase the size to 17KB I get the error message:
"The remote server returned an unexpected response: (400) Bad Request.
Because it works with smaller pictures I think it is something wrong with my configurations.
Client (winform) app.config:
http://www.copypastecode.com/157335/
Server web.config:
http://www.copypastecode.com/157339/
I've tried to increased every value (maxBufferSize, maxReceivedMessageSize..) to MAX without any progress?

If you are sending array you should check
maxArrayLength
setting as you most probably hit this limit. What is the length of your array when with 17kb file?
But in general, the best way to upload \ download files are stream upload \ download endpoints

You might consider adding the DataContractSerializer element in your serviceBehaviour element to define the maxItemsInObjectGraph as shown below
<serviceBehaviors>
<behavior name="">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
Also try to add Tracing on your service and see the trace log for the exact reason on why the request is failing.
If your total request length is exceeding 4MB then make sure you have the below:
<system.web>
<httpRuntime maxRequestLength="2147483647"/>
</system.web>

Related

Take only first certificate found

Having a behaviour for a endpoint, I specified a serviceCertificate to be used.
Everything works fine, but every year we get a new certificate on our servers while the old ones are being left undeleted.
This results in 2 valid certificates (overlapping few days in validity period), both with the same name. When having 2 certificates with the same name, using the service throws an error:
The exception message is: Found multiple X.509 certificates using the following search criteria: StoreName 'My', StoreLocation 'LocalMachine', FindType 'FindBySubjectName', FindValue 'CertName'. Provide a more specific find value
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehaviour">
<serviceCredentials>
<serviceCertificate findValue="CertName" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
I know how to solve this problem for now by deleting the old certificate, but I found no way to solve this for long term, i.e. taking always the first valid certificate.
Is there any way to specify to take one certificate, regardless of the number of available ones that match? I don't want to modify our config files everytime we get a certifcate renewed.

Redirect web.config IIS 8

I tried to make a redirect in web.config, but I get a 500 error. The version of IIS is 8.5, but before I was on version 6. What is wrong with this syntax ?
<location path="Test/test.aspx">
<system.webServer>
<httpRedirect enabled="true" destination="http://domain/Test/IT/test.aspx" httpResponseStatus="Permanent" />
</system.webServer>
</location>
I get an this error message : Internal error - 500. I deleted the lines in web.config and everything works again.
I tried URL Rewrite feature, but I get an error.
"Cannot read configuration file due to insufficient permissions"
I am trying to fix with these instructions below, but the system asked me for user/password. I am as administrator, but those credentials didn't work.
Cannot read configuration file due to insufficient permissions
The HttpRedirectionModule is installed in the server. Also, RewriteModule
Did you install the HttpRedirect module? It is optional under IIS7+.
If that isn't it would help if you could post the detailed error message you get from hitting this locally if you can -- that will help narrow down the cause.
Finally, you might want to look into URL rewriting here, it is a new feature for IIS7+ that can handle simple url redirects like the above and much more.

Deploy WCF Web Service in IIS 7 - Getting Error

I'm trying to add a service reference in VS 2010 to a WCF Web Service I have on a Server 2008/IIS7 server. I put the service into an existing/working ASP.NET site. When I type in the url of the service, it comes up with the standard service screen, but when I try to add the reference to a new website project I'm developing, I get the following error.
The document at the url https://www.nameofsite.net/service.svc?wsdl was not recognized as a known document type.
The error message from each known type may help you fix the problem:
- Report from 'XML Schema' is 'The document format is not recognized (the content type is 'text/html; charset=UTF-8').'.
- Report from 'https://www.nameofsite.net/service.svc?wsdl' is 'The document format is not recognized (the content type is 'text/html; charset=UTF-8').'.
- Report from 'DISCO Document' is 'Discovery document at the URL https://www.nameofsite.net/Service.svc?disco could not be found.'.
- The document format is not recognized.
- Report from 'WSDL Document' is 'The document format is not recognized (the content type is 'text/html; charset=UTF-8').'.
Metadata contains a reference that cannot be resolved: 'https://www.nameofsite.net/service.svc?wsdl'.
There was no endpoint listening at https://www.nameofsite.net/service.svc?wsdl that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
The remote server returned an error: (404) Not Found.
If the service is defined in the current solution, try building the solution and adding the service reference again.
I tried adding the mime type svc to IIS and that didn't work. I see that there's a lot of talk about soap 1.1 not communicating with soap 1.2 but I'm too new to this to even follow the instructions I've seen. Please help. Thanks.
Is the service publishing its metadata? Check the httpsGetEnabled flag in the web.config file for the service:
<behaviors>
<serviceBehaviors>
<behavior name="NewBehavior">
<serviceMetadata httpsGetEnabled="true"
httpsGetUrl="https://myComputerName/myEndpoint" />
</behavior>
</serviceBehaviors>
</behaviors>
For more info on these tags: ServiceMetaData
You may also need this endpoint configured in your web.config for the service:
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
Some more background:
Web.Config
WSDL vs MEX

Handling IIS Requests Current in a SignaR application?

I have a SignalR application running in production, where the enter code here Requests Current value exceeded 5000, rendering a 503 Service Unavailable error. So I updated the Aspnet.config with the following to increase the Requests Current value
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<system.web>
<applicationPool
maxConcurrentRequestsPerCPU="20000"
maxConcurrentThreadsPerCPU="20000"
requestQueueLimit="20000" />
</system.web>
<runtime>
<legacyUnhandledExceptionPolicy enabled="false" />
<legacyImpersonationPolicy enabled="true"/>
<alwaysFlowImpersonationPolicy enabled="false"/>
<SymbolReadingPolicy enabled="1" />
<shadowCopyVerifyByTimestamp enabled="true"/>
</runtime>
<startup useLegacyV2RuntimeActivationPolicy="true" />
</configuration>
However, now the Requests Current value is able to increase past 5000, and at just above 10,000, the service is unavailable. I am only seeing a small number of Requests Queued ( less than 100) at times.
What else needs to be configured to allow this to operate properly?
-- Update --
After using 0.5.2, the Requests Current seems to stabilize, which is a significant improvement. This test has run for a little over two hours, whereas within less than 30 minutes the req's current would just continue to build.
Still some increase in memory consumption, but possibly not due to the Req's Current:

Configuration Log4j: ConsoleAppender to System.err?

I saw that one of our tools uses a ConsoleAppender to System.err next to System.out in it's log4j configuration. Fragments of the configuration:
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<!-- Log to STDOUT. -->
<param name="Target" value="System.out"/>
....
<appender name="CONSOLE_ERR" class="org.apache.log4j.ConsoleAppender">
<!-- Log to STDERR. -->
<param name="Target" value="System.err"/>
In Eclipse this results in double messages to the console, so I believe that is of no use, right?
On the Linux server I see only one message to the PuTTY console, so where would that System.err message go to?
It can be of use depending on how the standard and error outputs are redirected. Often the standard output is muted (e.g. redirected to /dev/null) so the error output is the only way to actually display error messages.
I suspect that PuTTY actually does that - it would be very unusual to mute stderr but not stdout. I guess that your CONSOLE_ERR is set to ERROR or WARN level. In this case, you could check with PuTTY whether only error messages are displayed or all of them, to decide which appender's output you are actually seeing.

Resources