WCF service raises System.IO.InvalidDataException - c#

I try to connect to the NetSuite OpenAir API from a .NET console application using a WCF client. I generated the proxy by adding a service connection and using the following WSDL: http://sandbox.openair.com/wsdl.pl?wsdl&style=document
Logging in and reading data works fine as long as the HTTP response does not exceed a specific size. When that happens a System.IO.InvalidDataException occurs. The exception message is "Block length does not match with its complement".
These are the exception details:
System.IO.InvalidDataException
HResult=0x80131501
Message=Block length does not match with its complement.
Source=mscorlib
StackTrace:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at TestService.OASandbox.OAirServiceHandler.read(readRequest1 request)
at TestService.OASandbox.OAirServiceHandlerClient.TestService.OASandbox.OAirServiceHandler.read(readRequest1 request) in TestService\Connected Services\OASandbox\Reference.cs:line 43089
at TestService.OASandbox.OAirServiceHandlerClient.read(SessionHeader SessionHeader, ReadRequest[] method) in TestService\Connected Services\OASandbox\Reference.cs:line 43096
at TestService.Program.Main() in TestService\Program.cs:line 105
I used Fiddler to find out what the turning point is. It appears that the exception is raised when the Content-Length of the HTTP response is larger than 10000 bytes. The response itself is completely intact: when I analyze it using Fiddler it can be deciphered (as it is a SSL connection) and the full XML which is sent back by OpenAir is revealed. So it has to be a problem with the .NET code.
The WCF bindings are defined in my app.config as follows:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="OAirServiceSoapBinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
<security mode="Transport" />
<readerQuotas maxDepth="200" maxStringContentLength="83886089" maxArrayLength="163841" maxBytesPerRead="2147483647" maxNameTableCharCount="16384"/>
</binding>
<binding name="OAirServiceSoapBinding1" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
<readerQuotas maxDepth="200" maxStringContentLength="83886089" maxArrayLength="163841" maxBytesPerRead="2147483647" maxNameTableCharCount="16384"/>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://sandbox.openair.com/soapdoc" binding="basicHttpBinding"
bindingConfiguration="OAirServiceSoapBinding" contract="OASandbox.OAirServiceHandler"
name="OAirService" />
</client>
</system.serviceModel>
Looking at the exception it appears that it has something to do with the DEFLATE decompression algorithm, which is internally being called by WCF. It seems like some buffer overflow occurs. I could define a custom binding and disable compression, but I would like to keep that as a last resort.
Any clues how to troubleshoot this issue? Any help is highly appreciated!

I am using the NetSuite SuiteTalk WSDL. I add this as a web reference and it is then added as a setting to "applicationSettings" in my config file:
I think the problem is that your binding to the SOAP service only allows for a certain size of data to be returned. If the WSDL is added as a web reference, this restriction should not apply. I added mine as follows:
1) Right click on "References" in your WCF service and select "Add Service Reference".
2) Select "Advanced":
3) Add web reference:
4) Paste your WSDL reference and click on the arrow next to the text field. Wait for the WSDL to appear in the text block and click "add reference".:
I hope this helps!

Related

Send fails if message has a certain size

I am trying to consume a web service from a third party. Whenever the message that I send to the server passes a certain size, I am getting the following exception:
Unhandled Exception: System.ServiceModel.CommunicationException: An error occurred while making the HTTP request to https://host/path. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server.
---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send.
---> System.IO.IOException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.
---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
I am pretty sure that the first message regarding HTTP.SYS is incorrect because it works if I decrease the message size.
This is the code of a successful call:
var request = new GreetingUploadRequest
{
msisdn = "12345678900",
personalGreetingVoiceData = File
.ReadAllBytes(#"d:\Temp\sample.wav")
.Take(48876)
.ToArray()
};
var response = service.GreetingUpload(request);
And this is the code of an unsuccessful call:
var request = new GreetingUploadRequest
{
msisdn = "12345678900",
personalGreetingVoiceData = File
.ReadAllBytes(#"d:\Temp\sample.wav")
.Take(48877)
.ToArray()
};
var response = service.GreetingUpload(request);
As you can see, the only difference is in the Take - it is sending one byte more.
I have increased every setting I could think of, but to no avail:
<system.web>
<httpRuntime maxRequestLength="2147483647" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpsBinding>
<binding name="VmsGreetingUploadWSSoapBinding" closeTimeout="10:01:00"
openTimeout="10:01:00" receiveTimeout="10:10:00" sendTimeout="10:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="5147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security>
<transport clientCredentialType="Basic" proxyCredentialType="None" realm="" />
</security>
</binding>
</basicHttpsBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="endPoint">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="https://host/path"
binding="basicHttpsBinding" bindingConfiguration="VmsGreetingUploadWSSoapBinding"
contract="ServiceReference1.VmsGreetingUploadWS" name="VmsGreetingUploadWS" />
</client>
</system.serviceModel>
Important: The server seems to be configured correctly, because I can send the full data from a SoapUI project!
What setting am I missing? How can I further troubleshoot this?
However, the message size can't be the only problem, because if I route the request through Fiddler 4 - and allow it to decrypt HTTPS traffic - it works even with big messages!

How to remove Soap Security header

I'm currently trying to consume a SOAP 1.2 web service using a WCF client. Problem is, whenever I make a request a MessageSecurityException with the following inner message is thrown:
SOAP header Security was not understood
From what I can tell, the WS does not understand the Security header, which is currently marked as MustUnderstand="true".
How can I change MustUnderstandto false / remove the Security header?
Below is the binding I'm using right now:
<customBinding>
<binding name="CteRecepcaoSoap12">
<textMessageEncoding messageVersion="Soap12" />
<security authenticationMode="CertificateOverTransport"/>
<httpsTransport requireClientCertificate="true"/>
</binding>
</customBinding>

WCF set keepAliveEnable="false" not working

In my service I need to set keepAliveEnable=false in order to work with my load balancer. Therefore I followed instruction in this article. I did same thing mentioned in article but I am getting this error.
<customBinding>
<binding name="HttpBinding" keepAliveEnabled="False"/>
</customBinding>
The Scheme cannot be computed for this binding because this CustomBinding lacks a TransportBindingElement. Every binding must have at least one binding element that derives from TransportBindingElement.
Then I found set keepAliveFalse like below
<customBinding>
<binding name="HttpBinding" >
<textMessageEncoding />
<httpTransport allowCookies="false" keepAliveEnabled="false"/>
</binding>
</customBinding>
In this method service is getting started normal and I can get the responses. But in request headers still shows connection as keep alive. (I checked using firebug)
What is the correct way of doing this?
What is the end I need to set keep alive false (client or service) ?
Am I checking keepAlive in wrong way?

WCF-The request channel timed out after 1 min, while sendTimeout="00:25:00" on both sides

I am getting the error of "The request channel timed out after 1 min" even sendTimeout="00:25:00" on both sides.
If request is less than 1 min in time, then there is no issue but issue arises on request taking processing of greater than 1 min. on WCF service.
On WCF service side I have following bindings in my web.config file
<bindings>
<basicHttpBinding>
<binding maxReceivedMessageSize="67108864" transferMode="Streamed" closeTimeout="00:25:00" openTimeout="00:25:00" sendTimeout="00:25:00" receiveTimeout="00:25:00" >
<security mode="None" ></security>
</binding>
</basicHttpBinding>
</bindings>
On Client side, I have following bindings in my app.config file
<bindings>
<basicHttpBinding>
<binding name="streambinding" maxReceivedMessageSize="67108864" closeTimeout="00:25:00" openTimeout="00:25:00" sendTimeout="00:25:00" receiveTimeout="00:25:00" transferMode="Streamed">
<security mode="None"></security>
</binding>
</basicHttpBinding>
</bindings>
Can you add trace and message logs (at client and service) and share the findings? refer this article for client and this for service
from your config file of service and client I could make out that, your service bindingconfiguration is default I mean it doesn't have any name given, but client side binding configuration has a binding name. Try to keep it same both at the service and client, either have a name for binding configuration in service or remove the name from the client. Since you are accessing with different bindingName WCF not able to recognize the exact configuration and it might be timing out.

Namespace is not supported with rpc\\literal SOAP. The wrapper element has to be unqualified

I'm currently working on an integration with a leasing service provider, which runs (I assume) a Java service.
When I add the service reference in Visual Studio 2012, the reference is created correctly and I can call the methods specified in the service.
The problem arises when I get a response from the service.
Let's say I call the service with wrong parameters getCalculation and I get the JSON response JSONException. The problem is, that Visual Studio throws an exception There was an error reflecting 'JSONException'. and as InnerException: {"Namespace='http://service.ecommerce.cetelem.hu/' is not supported with rpc\\literal SOAP. The wrapper element has to be unqualified."}
This is the web.config code:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="EcommerceServiceImplPortBinding">
<security mode="Transport" />
</binding>
<binding name="EcommerceServiceImplPortBinding1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://ecomdemo.cetelem.hu:443/ecommerce/EcommerceService"
binding="basicHttpBinding" bindingConfiguration="EcommerceServiceImplPortBinding"
contract="CetelemInstallmentsService.EcommerceService" name="EcommerceServiceImplPort" />
</client>
</system.serviceModel>
If this is of any help, I'm using WebAPI for the user "front-end".
Thank you for all the answers!
I figured this thing out eventually, but with the help of another post on SO: SOAP Requests in .net
All I needed to change in the service refence file was:
[System.ServiceModel.XmlSerializerFormatAttribute(Style = System.ServiceModel.OperationFormatStyle.Rpc, SupportFaults = true)]
To:
[System.ServiceModel.XmlSerializerFormatAttribute(Style = System.ServiceModel.OperationFormatStyle.Document, SupportFaults = true)]

Categories