Cannot upload a file through webservice that is over 1MB - vb.net

Could some take a look at my web.config and tell me what is wrong with it? I am just not able to upload a file through a remote webservice that is larger than 1MB. I am guessing it has something to do with the attribute settings, but so far I havent had any luck changing the values. Or is it the setting on the host server side that I can't override?
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="CategoryPath" value="QA/ProcessValidation"/>
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_Authentication" 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>
<binding name="BasicHttpBinding_DocumentManagement" 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>
<binding name="BasicHttpBinding_ContentService" 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="Mtom" 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>
</client>
</system.serviceModel>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>
EDIT: I have no control for the service on the server side, I am actually only using the WCF and I only have the links to them.

It's not entirely clear whether the config file you posted is the client config or the server config, but it I'm going to make a semi-educated guess and say it's the client config, and you're using your client to connect to a third-party service.
Without knowing the error message and/or behavior you're seeing, or how you're creating the client in code, there are a few things you can try:
Increase the size of the maxStringContentLength attribute in the <readerQuotas> element. Right now it is set to the default of 8,192 bytes.
If this is the service config, increase the maxReceivedMessageSize attribute in the <binding> element - right now it is also set to the default of 65536.
The maximum value for both of these attributes is Int32.MaxValue - roughly 2GB. In either case, unless you have an endpoint specified in the config file (which you don't appear to currently) which references the defined binding config (via the <endpoint> element's bindingConfiguration attribute), you will always get the default values for the endpoint's binding.
So you will need to either make the binding definition the default (by omitting the name attribute from the <binding> element, or you will need to assign the binding configuration you want to use by using the bindingConfiguration attribute on the endpoint, like this:
<endpoint address="" binding=basicHttpBinding"
bindingConfiguration="MyBinding" contract="MyService.IMyService" />
If the service is not under your control, then you will not be able to do much if they have low limits set, as the client cannot modify the service's configuration (and the service cannot modify the client's either). The configurations are separate, but many parts (binding, security, etc) have to match.
If the above doesn't help, please edit your question to add more info (what error message/behavior are you seeing, is it the client or service config, how are you creating the client, do you have the service config, etc).

Related

WCF service binding content type mismatch - text/xml and application/soap+xml

I have been at this for a few days trying to figure out why I am getting a content type mismatch error in my binding. There are countless other people that seem to be having this issue but all the resolutions don't apply or haven't worked.
I have looked everywhere trying to figure out why I am getting the following error:
Server Error in '/' Application.
The content type application/soap+xml; charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 823 bytes of the response were:
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><GetQuoteResponse xmlns="http://soap.service.GMO.com"><Quote_Response><errorMessage></errorMessage><return_List><item><errorMessage></errorMessage><monthlyPremiumAmount>6.0</monthlyPremiumAmount><webID>7P3W4Txst</webID><basePer1>1000.0</basePer1><basePer2>0.0</basePer2><baseRate1>0.05</baseRate1><baseRate2>0.0</baseRate2><benefitID>5365</benefitID><coverageAmount>100000</coverageAmount><grossPer1>1000.0</grossPer1><grossPer2>0.0</grossPer2><grossRate1>0.06</grossRate1><grossRate2>0.0</grossRate2></item></return_List></Quote_Response></GetQuoteResponse></soapenv:Body></soapenv:Envelope>.
The web service I am consuming is not hosted in IIS. The web service itself seems to be working properly because we use SoapUI and get all the proper results returned to us. As you can also see from the above error message, values are being returned from the web service.
I have also been using Fiddler and am able to confirm that the request header content type is text/xml and the response header content type is application/soap+xml.
We have a datalayer where the service reference resides. The app.config looks like this:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="IMSQuoteServiceBinding" 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://hostingServerName:81/cgi-bin/jsmdirect?IMSQuote"
binding="basicHttpBinding" bindingConfiguration="IMSQuoteServiceBinding"
contract="Quote.IMSQuoteServicePortType" name="IMSQuoteServicePort" />
</client>
</system.serviceModel>
The web site web.config looks like this:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="IMSQuoteServiceBinding" 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://hostingServerName:81/cgi-bin/jsmdirect?IMSQuote"
binding="basicHttpBinding" bindingConfiguration="IMSQuoteServiceBinding"
contract="Quote.IMSQuoteServicePortType" name="IMSQuoteServicePort" />
</client>
Any help would be very much appreciated. I am somewhat new to WCF and am open to any and all ideas.
Thank you all in advance for your help. If you need me to provide any more information, please let me know.
Just as an update.
I changed the service binding from basicHttpBinding to wsHttpBinding. Changing the binding to wsHttpBinding changed the SOAP service to send as a SOAP 1.2 call rather than a SOAP 1.1 call. Once I did this, the content types matched on the send and receive calls which resolved the binding mismatch error.

WCF binding not being read

I am using a basic http binding and have set maxReceivedMessageSize="2147483647" on both the client and the service. My service is throwing an error however, with this message:
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.
I know it's using my binding because that's the only one I've enabled and other method calls work fine. Is this just a generic message and my object is really bigger than 2147483647 not 65536?
The binding looks like this on both the client and server
<basicHttpBinding>
<binding name="basicHttpBinding" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="16384" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
You likely have a name mismatch in the config between the name attribute of the <service> element and the actual service name. The name must be the fully-qualified name of the service class.

Large string argument in WCF operation call

I am unable to pass a string as an argument to a WCF operation call. The string is quite large (about 12000 characters).
I have increased maxStringContentLength in web.config and played around with almost all the attributes but the problem still remains.
I have found a workaround - Split the string at client's end and concatenate at the server's end. It works this way.
Can anybody direct me towards the right way of solving this problem? Why WCF operation call is able to accept the same amount of data (split into 2 string parameters) but throws error when that data is passed in one string parameter? Where do we configure the size limit of WCF operation arguments?
---------------------------------CODE--------------------------------
TestService.Service1Client client = new TestService.Service1Client();
string str = "VERY LARGE STRING";
//DOES NOT WORK
client.TakeLargeStringParam(str);
//WORKS
client.TakeLargeStringParam2(str.Substring(0, 5000), str.Substring(5000));
-----------------------WEB.CONFIG--------------------------
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" 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="819200" 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:30701/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="TestService.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
You need to increase the maxStringContentLength at the server side, not at the client. The web.config only has a <client> section, and to configure a service you'd need to set a <service> section there. If there's no matching service configuration on the service, it will use a default one, which has the default quota values.

WCF + net.tcp Communication Timeout problem

I have some critical problem in my project. During transaction time with (wcf + netTCP)
I was getting the exception is.
The communication object,
System.ServiceModel.Channels.ClientFramingDuplexSessionChannel,
cannot be used for communication because it is in the Faulted state.
In WCF service app.config add binding tag with timeout specification. But my transaction has been ended within 10 min. what was the problem..
<bindings>
<basicHttpBinding>
<binding name="ServiceSoap" closeTimeout="0:01:00" openTimeout="0:01:00" receiveTimeout="10:00:00" sendTimeout="10:00: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>
<netTcpBinding>
<binding name="b1" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="infinite" sendTimeout="10:00:00"
transferMode="Buffered"
maxBufferPoolSize="524288"
maxBufferSize="65536"
maxConnections="10"
maxReceivedMessageSize="65536">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
Any one help me !!!..
I'm not sure why you think its a timeout issue? The error message doesn't suggest a timeout has ocured. Could the server be throwing an exception?
I would strongly recommend setting up WCF tracing. Its a bit involved but really worth doing as I've solved many obscure WCF issue with it.
This is not a complete answer but if you are using the client + server on the same machine you can use a named-pipe binding instead of netTcp
The binding section the configurations might look like this.
<netNamedPipeBinding>
<binding name="infiniteOpenBindingConfig" receiveTimeout="infinite" closeTimeout="infinite">
</binding>
</netNamedPipeBinding>
To keep the binding alive indefinitely the configuration above must be set both on server and client.
Try adding this to your netTcpBinding:
<reliableSession inactivityTimeout="infinite" enabled="true" />
And if that doesn't work, enable WCF tracing to find out what's killing it.

What is the WCF equivalent?

I am trying to port some code that is based on WSE3.0 to WCF. Basically, the old code has the following configuration:
<microsoft.web.services3>
<diagnostics>
<trace enabled="true" input="InputTrace.webinfo" output="OutputTrace.webinfo" />
</diagnostics>
<tokenIssuer>
<statefulSecurityContextToken enabled="false" />
</tokenIssuer>
</microsoft.web.services3>
When calling the same service through my "Service Reference" I get this error:
Request does not contain required Security header
My binding looks like this:
<basicHttpBinding>
<binding name="LegalUnitGetBinding" 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="Transport">
</security>
</binding>
</basicHttpBinding>
From what I have understood, the service I'm calling only requires an SSL connection, since it receives a username and password as part of a request parameter.
Any help or suggestions would be greatly appreciated.
You'll have to pass credentials on the client side and validate them on the server side, I guess you are using IIS to Host? Instead of rehashing - here is an MVP post that should get you pointed in the right direction.
Key change that will get you thinking in your config file:
<security mode="TransportWithMessageCredential">
...
</security>