I cannot get to work a wsDualHttpBinding endpoint on my WCF service.
I'm facing this problem on the client.
I get an exception that suggests to increment MaxArrayLength from 16384 to allow to read the whole xml data.
I tried the following configuration:
<system.serviceModel>
<bindings>
<wsDualHttpBinding>
<binding name="MyBinding" maxReceivedMessageSize="2147483647" />
</wsDualHttpBinding>
</bindings>
<client>
<endpoint name="WSDualHttpBinding_IDataService" binding="wsDualHttpBinding" bindingConfiguration="MyBinding"
address="http://localhost:8733/DataProvider/" contract="DataStorageService.IDataService" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
But the above configuration seems to be ignored.
I instantiate my client like this:
var instanceContext = new InstanceContext( new CallbackHandler() );
_clientService = new DataServiceClient( instanceContext );
and i read somewhere that these line of codes override the configuration in app.config; if that't the problem, how can i increment quotas?
Any help appreciated.
You have to configure more than just maxReceivedMessageSize.
As Jonathan Coffey said, there is BytePerRead, TableCharCount, StringContentLenght, etc.
You also have to configure the readerQuotas : https://msdn.microsoft.com/en-us/library/ms731325(v=vs.110).aspx
Note that you have to configure the server the exact same way you configured your client, and you can't set a maxbytearraylengh't greater than your maxreceivedmessagesize, obviously.
If the server doesn't have the same MaxReceivedMessageSize or whatever, it won't work as you expected, for example.
GL.
You do exactly what the error tells you :)
For this it might be best to see visually how to do it rather than copy and paste code.
In your project, Right click your service "app.config" and choose "Edit WCF Configuration" from there click on "Bindings" and you should see your custom binding. If not just right click and create a new binding. From here you can change the "ReaderQuotas Properties" what I use is
MaxArrayLength = 2147483647
MaxBytesPerRead = 4096
MaxDepth = 32
MaxNameTableCharCount = 2147483647
MaxStringContentLength = 2147483647
Once that is done, go ahead and press "File" and then "Save"
Now go view your app.config code and it should have updated.
Run your service and then right click your service references and "Update Service Reference"
Now if you look at your client app.config file it should match what your service app.config attributes looked like. If this is not the case then right click your clients app.config and "Edit WCF Configuration" again, go to bindings and then choose your service endpoint and change the values to the same as the service.
Be aware though settings the values that high will leave you vulnerable to ddos attacks etc. so find out what you need and change it after testing.
Hope this helps :)
Make sure your service is running as administrator also
I called an WCF service and tried fetching data from database in windows 7.
I got this error.
Error in deserializing body of reply message for operation
'GetProductXml'. The maximum string content length quota (8192) has
been exceeded while reading XML data. This quota may be increased by
changing the MaxStringContentLength property on the
XmlDictionaryReaderQuotas object used when creating the XML reader.
Line 13, position 197.
I tried changing the MaxStringContentLength property to 2147483647 in web config of WCF service but i get the same above error....
You need to change it in the client.config file that was created when you added a service reference in your windows 7 application.
You can get around the error by adding the below settings in your WCF Service web.config and also on your client side web.config:
<basichttpBinding>
<binding>
<readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="64" maxNameTableCharCount="2147483647" />
</binding>
</basichttpBinding>
NOTE: Assuming you are using BasicHttpBinding. If using a different binding make sure to add the readerQuotas for that binding.
If you are hosting your WCF service via code and then you want to add reader quotas via code see below:
var binding = new BasicHttpBinding();
var myReaderQuotas = new XmlDictionaryReaderQuotas();
myReaderQuotas.MaxStringContentLength = 5242880;
binding.GetType().GetProperty("ReaderQuotas").SetValue(binding, myReaderQuotas, null);
I'm calling a BizTalk service using WCF. The service requires the wsa:replyto address to be set in the SOAP header to able to make a 'callback' when the process is done.
We are using a contract-first approch with auto-generated code from svcutil (we cannot 'just' change the contract)...
And it's not possible to do in the config file...
I have seen someone 'overriding' some methods to make their own custom header - but this is not a custom header it's a standard in the SOAP protocol.
How can I add the wsa:replyto in the (SOAP) header?
In order to invoke a service that requires WS-Addressing from WCF you'll have to configure the client endpoint to use a binding that supports it, such as the WSHttpBinding.
You can then set the wsa:ReplyTo header to a specific URL in your client code through the OperationContext.OutgoingMessageHeaders property:
using (new OperationContextScope((IContextChannel)channel))
{
OperationContext.Current.OutgoingMessageHeaders.ReplyTo =
new EndpointAddress("http://client/callback");
channel.DoSomething();
}
In this example we are setting the wsa:ReplyTo header to a known URL where the client channel listens for incoming callback messages from the service.
Alternatively, if the service supports it, you could use the WSDualHttpBinding, which has built in support for duplex communication through WS-Addressing. In this case you would set the callback address through the WSDualHttpBinding.ClientBaseAddress property:
<system.serviceModel>
<bindings>
<wsDualHttpBinding>
<binding clientBaseAddress="http://client/callback" />
</wsDualHttpBinding>
</bindings>
<client>
<endpoint address="http://server/service"
binding="wsDualHttpBinding"
contract="Namespace.Service" />
</client>
</system.serviceModel>
I have a problem with a WCF service.
I have a console application and I need to consume the service without using app.config, so I had to set the endpoint, etc. by code.
I do have a service reference to the svc, but I can't use the app.config.
Here's my code:
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress("http://localhost:8731/WcfServicio/MiServicio");
MiServicioClient svc = new MiServicioClient(binding, address);
object ob = svc.PaisesObtener();
At the last line when I do svc.PaisesObtener() I get the error:
Content Type text/xml; charset=utf-8 was not supported by service
http://localhost:8731/WcfServicio/MiServicio. The client and service bindings may be mismatched.
First Google hit says:
this is usually a mismatch in the client/server bindings, where the message version in the service uses SOAP 1.2 (which expects application/soap+xml) and the version in the client uses SOAP 1.1 (which sends text/xml). WSHttpBinding uses SOAP 1.2, BasicHttpBinding uses SOAP 1.1.
It usually seems to be a wsHttpBinding on one side and a basicHttpBinding on the other.
Do not forget check the bindings-related code too.
So if you wrote:
BasicHttpBinding binding = new BasicHttpBinding();
Be sure that all your app.config files contains
<endpoint address="..."
binding="basicHttpBinding" ...
not the
<endpoint address="..."
binding="wsHttpBinding" ...
or so.
I've seen this behavior today when the
<service name="A.B.C.D" behaviorConfiguration="returnFaults">
<endpoint contract="A.B.C.ID" binding="basicHttpBinding" address=""/>
</service>
was missing from the web.config. The service.svc file was there and got served. It took a while to realize that the problem was not in the binding configuration it self...
I saw this problem today when trying to create a WCF service proxy, both using VS2010 and svcutil.
Everything I'm doing is with basicHttpBinding (so no issue with wsHttpBinding).
For the first time in my recollection MSDN actually provided me with the solution, at the following link How to: Publish Metadata for a Service Using a Configuration File. The line I needed to change was inside the behavior element inside the MEX service behavior element inside my service app.config file. I changed it from
<serviceMetadata httpGetEnabled="true"/>
to
<serviceMetadata httpGetEnabled="true" policyVersion="Policy15"/>
and like magic the error went away and I was able to create the service proxy. Note that there is a corresponding MSDN entry for using code instead of a config file: How to: Publish Metadata for a Service Using Code.
(Of course, Policy15 - how could I possibly have overlooked that???)
One more "gotcha": my service needs to expose 3 different endpoints, each supporting a different contract. For each proxy that I needed to build, I had to comment out the other 2 endpoints, otherwise svcutil would complain that it could not resolve the base URL address.
I was facing the similar issue when using the Channel Factory. it was actually due to wrong Contract specified in the endpoint.
For anyone who lands here by searching:
content type 'application/json; charset=utf-8' was not the expected type 'text/xml; charset=utf-8
or some subset of that error:
A similar error was caused in my case by building and running a service without proper attributes. I got this error message when I tried to update the service reference in my client application. It was resolved when I correctly applied [DataContract] and [DataMember] attributes to my custom classes.
This would most likely be applicable if your service was set up and working and then it broke after you edited it.
I was also facing the same problem recently. after struggling a couple of hours,finally a solution came out by addition to
Factory="System.ServiceModel.Activation.WebServiceHostFactory"
to your SVC markup file. e.g.
ServiceHost Language="C#" Debug="true" Service="QuiznetOnline.Web.UI.WebServices.LogService"
Factory="System.ServiceModel.Activation.WebServiceHostFactory"
and now you can compile & run your application successfully.
Again, I stress that namespace, svc name and contract must be correctly specified in web.config file:
<service name="NAMESPACE.SvcFileName">
<endpoint contract="NAMESPACE.IContractName" />
</service>
Example:
<service name="MyNameSpace.FileService">
<endpoint contract="MyNameSpace.IFileService" />
</service>
(Unrelevant tags ommited in these samples)
In my case, I had to specify messageEncoding to Mtom in app.config of the client application like that:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="IntegrationServiceSoap" messageEncoding="Mtom"/>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:29495/IntegrationService.asmx"
binding="basicHttpBinding" bindingConfiguration="IntegrationServiceSoap"
contract="IntegrationService.IntegrationServiceSoap" name="IntegrationServiceSoap" />
</client>
</system.serviceModel>
</configuration>
Both my client and server use basicHttpBinding.
I hope this helps the others :)
I had this error and all the configurations mentioned above were correct however I was still getting "The client and service bindings may be mismatched" error.
What resolved my error, was matching the messageEncoding attribute values in the following node of service and client config files. They were different in mine, service was Text and client Mtom. Changing service to Mtom to match client's, resolved the issue.
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IMySevice" ... messageEncoding="Mtom">
...
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
</configuration>
I had this problem in .net 6.0
The problem was the Soap Version, the BasicHttpBinding targets Soap 1.1 by default, but the service uses Soap 1.2.
The solution was to create a custom binding that targets Soap 1.2:
private Binding GetBindingConfiguration()
{
var textBindingElement = new TextMessageEncodingBindingElement()
{
MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None)
};
var httpsBindingElement = new HttpsTransportBindingElement()
{
MaxReceivedMessageSize = int.MaxValue,
RequireClientCertificate = true //my service require certificate
};
return new CustomBinding(textBindingElement, httpsBindingElement);
}
var binding = GetBindingConfiguration();
var address = new EndpointAddress("https://nfe.sefa.pr.gov.br/nfe/NFeAutorizacao4"); //Brazil NF-e endpoint that I had to consume.
var svc = new MyService(binding, address);
//my service requires certificate
svc.ClientCredentials.ClientCertificate.Certificate = certificado;
object ob = svc.PaisesObtener(); //call the method
I'm publishing a service with a MEX endpoint for metadata exchange and I'm using the code below to discover it and get the metadata information
DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
FindCriteria findCriteria = FindCriteria.CreateMetadataExchangeEndpointCriteria(ContractType);
findCriteria.Duration = TimeSpan.FromSeconds(15);
findCriteria.MaxResults = 1;// MaxResults;
FindResponse result = discoveryClient.Find(findCriteria);
discoveryClient.Close();
ServiceEndpointCollection eps = MetadataResolver.Resolve(ContractType, result.Endpoints[0].Address);
return eps[0].Binding;
When I get the metadata information in my client the binding information (OpenTimeout,
ReceiveTimeout and SendTimeout) is back to its default values.
Here is the binding information in the host
<binding name="MyServiceBinding" closeTimeout="00:05:00" openTimeout="00:05:00"
receiveTimeout="23:50:00" sendTimeout="00:05:00" maxReceivedMessageSize="50000000">
<readerQuotas maxStringContentLength="50000000" maxArrayLength="50000000" />
<reliableSession ordered="true" inactivityTimeout="00:01:00" enabled="false" />
<security mode="None" />
</binding>
here is another question i've found that is almost the same as mine.
WCF Service Binding taking default values instead of custom values
I would like to know if I'm doing something wrong or if I misunderstood the concept of metadata exchange.
What I'm trying to do is send all the info necessary to my clients so they can auto config them self and do not have any hard code configuration.
I don't think you're doing anything wrong - you're just expecting too much from the metadata exchange.
The purpose of MEX is to be able to discover new services programmatically, and create client-side proxies for those services. For this, there's the WSDL - basically anything contained in the WSDL is part of the metadata exchange:
service contract / service methods
parameters needed for those service methods
data type declarations in XML schema for the data types used
additional service related information like bindings used etc.
But MEX does not contain all WCF specific configuration settings - which is what you've discovered. MEX will create a functioning client-side proxy - but it never had the intention of transporting all configuration settings from the server to the client. You'll need to hand-code this yourself, on the client side.