WCF Service Reference Support Files Not Updating - wcf

I have a VS 2010 solution containing a WCF service project and a unit test project. The unit test project has a service reference to the WCF service.
Web.config for the WCF service project sets a number of binding attributes to other-than-default values:
web.config: (Specifically note maxBufferSize="20000000")
<basicHttpBinding>
<binding name="basicHttpBindingConfig" maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000">
<readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000"/>
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm"/>
</security>
</binding>
</basicHttpBinding>
While examining this issue, I came to realize that the unit test project's service reference support files do not contain the values I would expect (i.e. the values configured in the WCF service's web.config):
configuration.svcinfo:
(Specifically note maxBufferSize="65536")
<binding hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" messageEncoding="Text" name="BasicHttpBinding_IBishopService" textEncoding="utf-8" transferMode="Buffered">
<readerQuotas maxArrayLength="16384" maxBytesPerRead="4096" maxDepth="32" maxNameTableCharCount="16384" maxStringContentLength="8192" />
<security mode="None">
<message algorithmSuite="Default" clientCredentialType="UserName" />
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
</security>
</binding>
Deleting and re-creating the service reference or updating the service reference re-creates the files, but I still end up with the same values.
Why?
Update
Here's the app.config of the client
<binding name="BasicHttpBinding_IMyService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="200000000" maxBufferPoolSize="200000000" maxReceivedMessageSize="200000000"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="200000000" maxArrayLength="200000000"
maxBytesPerRead="200000000" maxNameTableCharCount="200000000" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>

Same issue here and no solution after half a day messing about with config files... Changing automatically generated files is usually frowned upon, so my feeling says that "there has got to be a better way, Dennis".
UPDATE: I got my problem fixed by removing the name attribute in the binding configuration.
So your current web.config is looking like this
<basicHttpBinding>
<binding name="basicHttpBindingConfig" maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000">
<readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000"/>
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm"/>
</security>
</binding>
</basicHttpBinding>
would become
<basicHttpBinding>
<binding maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000">
<readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000"/>
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm"/>
</security>
</binding>
</basicHttpBinding>
I think you only need to this at the client-side. By removing the name attribute, you essentially change the default basicHttpBinding configuration for your app, as far as I understand it. Credits for this solution here.
Another update: if you name your service configuration correctly (including the namespace) it will pick up the binding configuration. So instead of
<service name="ServiceName">
you need
<service name="My.Namespace.ServiceName">

That is correct behavior. Some information included in binding are specific to only one side of the configuration and both client and server can use completely different values. Also these values are defence against Denial of Service attach so service doesn't want to show them publicly.
Those values affects only processing of incoming messages so service configures how it will handle incoming requests and client configures how it will handle incoming responses. Requests and responses can have different characteristics and different configuration. There is no need for service to be configured to accept 1MB requests if it always receives only few KB requests and returns 1MB responses.
Btw. this is WCF specific feature not related to general web services and because of that there is no standardized way to describe this in WSDL.

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 Transport/Windows Binding Security Not Being Enforced

I'm in the process of adding SSL security with Windows authentication to a formerly unsecured IIS hosted WCF service application. To my surprise, I found that two of the service endpoints were already using a Binding with Transport and Windows security. This is confusing because the client applications consuming this service are not configured to use Transport security or Windows credentials. Here is the service config:
<binding name="LargeBuffer" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="Transport">
<transport clientCredentialType="Windows" />
</security>
</binding>
...
<service behaviorConfiguration="WebServices.GCServiceBehavior"
name="WebServices.GCService">
<endpoint address="" binding="basicHttpBinding" name="GCSecuredEndpoint"
bindingName="largeBuffer" contract="WebServices.IGCService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
When I use Visual Studio to generate the client proxy and configuration, it creates this:
<binding name="GCSecuredEndpoint" 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>
...
<endpoint address="http://devservices.mysite.com/GCService/GCService.svc"
binding="basicHttpBinding" bindingConfiguration="GCSecuredEndpoint"
contract="GCSvc.IGCService" name="GCSecuredEndpoint" />
Notice it's security mode="None" and Transport ClientCredentialType is None instead of Windows. When I call a method on the GCService it succeeds. I would expect it to first complain that I'm trying to access over http instead of https, but it doesn't. Next I would expect it to not authenticate or complain that the client endpoint doesn't match the service in terms of authentication, but it doesn't.
I have another service in the same application that I had just setup with Transport/Windows security just without all the buffer/readquota stuff. For starters, when I generate the client proxy/config in VS for this service, it automatically uses the https address, transport security, and windows authentication. If I manually change it to use None for both, as above, a call to one of the service methods does not succeed, as expected. Why is the GCService above working?
The server config has
bindingName="largeBuffer"
instead of
bindingConfiguration="LargeBuffer"
The LargeBuffer binding configuration was never being used.

Sending larger object to WCF results in 400 Bad Request

I have a unit test that sends a moderately large object to a WCF service. If I pass null for that parameter, everything works fine. When I send a populated object, I get an HTTP 400 response.
WCF tracing shows this error:
The maximum message size quota for incoming messages (65536) has been
exceeded.
However, I have cranked up the size configuration parameters in app.config for the unit test project as follows:
<basicHttpBinding>
<binding name="BasicHttpBinding_IMyAppService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="200000000" maxBufferPoolSize="200000000" maxReceivedMessageSize="200000000"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000"/>
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
What am I missing in my configuration to raise the allowed message size above the 65536 seen in the error message?
UPDATE:
The web.config file for the web service host also sets the maxReceivedMessageSize to a large value (I think):
<binding name="basicHttpBindingConfig" maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000">
<readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000"/>
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm"/>
</security>
</binding>
If I understand your question correctly, you increased the size for 'maxReceivedMessageSize' in the unit test's app.config. Actually you should make this change in the app.config/web.config of the web service which you are calling from your unit test code. If you host your web service in IIS, then it will be web.config. If you host it in windows service, then you need to make the change in the app.config (which gets moved to your .exe.config file in your bin folder.

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.

BizTalk WCF Send Port error - The header 'CoordinationContext' was not understood

I have a WCF-WSHttp Send Port set up with Enable Transactions checked, and I'm getting the following error when a message is sent:
The header 'CoordinationContext' from the namespace 'http://schemas.xmlsoap.org/ws/2004/10/wscoor' was not understood by the recipient of this message, causing the message to not be processed. This error typically indicates that the sender of this message has enabled a communication protocol that the receiver cannot process. Please ensure that the configuration of the client's binding is consistent with the service's binding.
If I uncheck the Enable Transactions box, the message is processed successfully. Can anyone help me get this working with transaction support?
Here's the binding info from the service's web.config (transactionFlow is set to true):
<bindings>
<wsHttpBinding>
<binding name="serviceBinding" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="true" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Ntlm" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
Thanks in advance!
It could be a problem with the setup of MSDTC, see http://msdn.microsoft.com/en-us/library/ms752261.aspx
Also check the event log for MSDTC related errors.
Turns out the problem was with the service itself. Although the bindings were configured properly with transactionFlow="true", the service contract was missing the following attribute to explicitly allow transactions:
[System.ServiceModel.TransactionFlowAttribute(System.ServiceModel.TransactionFlowOption.Allowed)]