XmlSerialization for custom type in WCF service - wcf

I'm newbie in WCF. I developed a WCF service and client for it. The service methods will retrieve custom data which uses custom XML serializer. I've read, in this case, contract methods should be marked with [XmlSerializerFormat]:
[ServiceContract]
[XmlSerializerFormat]
public interface ITSService
{
[OperationContract]
[XmlSerializerFormat]
ProtocolDocument GetReferenceData(string referenceType, SerializableDictionary<string, string> args);
ProtocolDocument implements IXmlSerializable:
[XmlRoot("protocol", Namespace = Protocol30Namespace)]
[Type(Name = "protocol", Namespace = Protocol30Namespace)]
public class ProtocolDocument : ProtocolElement, ICloneable, IXmlSerializable
VS 2010 chooses wsHttpBinding by default. I don't need in security, so I turned it off.
Here is the service configuration:
<services>
<service name="MyNamespace.TSService"
behaviorConfiguration="MyNamespace.TSServiceBehavior">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:51944/TSService.svc" />
</baseAddresses>
</host>
<endpoint
address=""
binding="wsHttpBinding"
bindingConfiguration="nonSecurityWSHttpBinding"
contract="MyNamespace.ITSService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyNamespace.TSServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="nonSecurityWSHttpBinding">
<security mode="None">
<transport clientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
Then I generated the client for this service, but the result could not be deserialized. Fiddler says SOAP wrapped serialized data into GetReferenceDataResult and GetReferenceDataResponse:
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">http://tempuri.org/ITourSystemService/GetReferenceDataResponse</a:Action>
<a:RelatesTo>urn:uuid:3d7f6dc0-4961-4bc5-b1fc-c9997af9fbd4</a:RelatesTo>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<GetReferenceDataResponse xmlns="http://tempuri.org/">
<GetReferenceDataResult>
<header version="3.0" language="Russian"/>
<references/>
</GetReferenceDataResult>
</GetReferenceDataResponse>
</s:Body>
</s:Envelope>
But the root element is missing! What should I do?
PS Serialization impl:
void IXmlSerializable.ReadXml(XmlReader reader)
{
var serializer = new ProtocolDocumentXmlSerializer();
serializer.Deserialize(this, reader);
}
void IXmlSerializable.WriteXml(XmlWriter writer)
{
//
// Serialize everything except the root element, because it was already written by .NET XML-serialization mechanism
var xmlSerializationFlags = XmlSerializationFlags.All & ~XmlSerializationFlags.IncludeRootElement;
var serializer = new ProtocolDocumentXmlSerializer();
serializer.Serialize(this, writer, xmlSerializationFlags);
}
Xml-serialization works well. It is already in use. I suppose smth wrong with my WCF-configuration.

You appear to have explicitly told it to ignore your root element in your WriteXml method - that's would be why there is no root element
var xmlSerializationFlags = XmlSerializationFlags.All & ~XmlSerializationFlags.IncludeRootElement;
If you cannot get deserialization to work you can always work at the XML level by using Message as the return type in your client's contract and then call GetReaderAtBody on the message, load the data into XElement and use LINQ to XML to transform the XML into objects to work with at the client side

Related

WCF: One-way callbacks timeouts after hibernation

My application has to components, one service (running as system) and one client (running in user space). Both are communicating by using WFC (localhost) and the communication works just fine, until I hibernate and resume the machine.
Since that moment, the method that I use as heartbeat is throwing a timeout exception with the following content
The message could not be transferred within the allotted timeout of 00:01:00. There was no space available in the reliable channel's transfer window. The time allotted to this operation may have been a portion of a longer timeout.
I am checking the connection status and is not faulted. Luckily, after 10 minutes of "inactivity" in the connection, another timeout expires (10 minutes) changing the connection status to Faulted. In that moment my client detects the new status and is able to restart the connection.
My server has the following config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<system.serviceModel>
<bindings>
<wsDualHttpBinding>
<binding openTimeout="00:00:05"
closeTimeout="00:00:05"
sendTimeout="00:00:03"
receiveTimeout="00:01:00">
<security mode="Message" >
<message clientCredentialType="Windows"/>
</security>
</binding>
</wsDualHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="EEAS.Kiosk.WcfService">
<endpoint address="" binding="wsDualHttpBinding" contract="EEAS.Kiosk.IWcfService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/KioskService/WcfService/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
And my client has the following config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<system.serviceModel>
<bindings>
<wsDualHttpBinding>
<binding name="WSDualHttpBinding_IWcfService" />
</wsDualHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8733/KioskService/WcfService/"
binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IWcfService"
contract="KioskWcf.IWcfService" name="WSDualHttpBinding_IWcfService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
my service interface
[ServiceContract(CallbackContract = typeof(IWcfServiceCallback))]
public interface IWcfService
{
[OperationContract]
void OpenSession();
[OperationContract]
CompositeType OpenSessionWithMessage();
[OperationContract]
bool isAlive();
[OperationContract]
void TemporarySuspension();
}
and the callback interface
public interface IWcfServiceCallback
{
[OperationContract]
bool IsAlive();
[OperationContract]
void SuspensionFinished();
[OperationContract]
bool UIMessageOnCallback(CompositeType UIMessage);
}
Any idea? my only solution is try to reduce that 10 minutes timeout to the minimum so the faulted connection is quickly detected and restarted. far from perfect :/
It does not appear that the current scenario requires duplex binding. If using duplex mode communication, please apply one-way communication to ensure that the client or server will not time out.
[ServiceContract(Namespace = "sv1", ConfigurationName = "isv", CallbackContract = typeof(ICallBack))]
public interface IService1
{
[OperationContract(Action = "post_num", IsOneWay = true)]
void PostNumber(int n);
}
[ServiceContract(Namespace = "callback")]
public interface ICallBack
{
[OperationContract(Action = "report", IsOneWay = true)]
void Report(double progress);
}
Besides, if the server and the client are not the same machines, please supply windows credentials on the client-side while calling the service.
Feel free to let me know if the problem still exists.

Error In consuming WCF services at client side end-point not found

I am working on ASP.NET WCF simple HelloWorld Example. I have successfully completed server side but I am getting issue while working on client side. I have used SVCUTIL.exe to generate proxy classes for me.
On debug I am getting following error;
An exception of type 'System.InvalidOperationException' occurred in System.ServiceModel.dll but was not handled in user code
Additional information: Could not find endpoint element with name 'WSHttpBinding_IHelloWorldService' and contract 'IHelloWorldService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element.
another thing, can I use Channel Factory if I don't access to dll file from server, say If I got access to WSDL url link
On Client Side app.config
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IHelloWorldService" />
<binding name="WSHttpBinding_IHelloWorldServiceAsyn" />
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8087/CreditUnionServices/HelloWorldServices/HelloWorldService"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IHelloWorldService"
contract="IHelloWorldService" name="WSHttpBinding_IHelloWorldService">
<identity>
<userPrincipalName value="DESKTOP-G6LE8I4\Khurram Zahid" />
</identity>
</endpoint>
<endpoint address="http://localhost:8087/CreditUnionServices/HelloWorldServices/HelloWorldServiceAsyn"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IHelloWorldServiceAsyn"
contract="IHelloWorldServiceAsyn" name="WSHttpBinding_IHelloWorldServiceAsyn">
<identity>
<userPrincipalName value="xyz\abc" />
</identity>
</endpoint>
</client>
</system.serviceModel>
Client Proxy Channel Factory
public class HelloWorldClient
{
public string SendTestMessage(string name)
{
ChannelFactory<IHelloWorldService> _HelloWorldClientService = new ChannelFactory<IHelloWorldService>("WSHttpBinding_IHelloWorldService");
IHelloWorldService _HelloWorldChannelService = _HelloWorldClientService.CreateChannel();
var _returnMessage = _HelloWorldChannelService.GetMessage(name);
((IClientChannel)_HelloWorldChannelService).Close();
return _returnMessage;
}
}
Server side config file
<system.serviceModel>
<services>
<service name="App.Services.Managers.HelloWorldManager" behaviorConfiguration="DefaultServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8087/CreditUnionServices/HelloWorldServices"/>
</baseAddresses>
</host>
<endpoint address="HelloWorldService" binding="wsHttpBinding" contract="App.Services.Contracts.IHelloWorldService"></endpoint>
<endpoint address="HelloWorldServiceAsyn" binding="wsHttpBinding" contract="App.Services.Contracts.IHelloWorldServiceAsyn"></endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DefaultServiceBehavior">
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
Update Code
public static class HelloWorldClient
{
public static string SendTestMessage(string name)
{
HelloWorldServiceClient _helloWorldService = new HelloWorldServiceClient("WSHttpBinding_IHelloWorldService");
var _returnMessage = _helloWorldService.GetMessage("mr kz ....");
return _returnMessage;
}
}

WCF Silverlight enabled service "Not Found" error

I'm struggling with the following scenario (here is the big picture):
I have a WCF Silverlight-enabled service (based on the DomainService class) into my Web project. The service is designed to be called by the Silverlight 5 clients and also by non-Silverlight consumers.
The service displays the WSDL info at the address
"http://localhost/mywebapproot/Services/MailService.svc" and therefore it can
be discovered and implemented by any client within the Web
project (which is fine).
Here are the symptoms:
The service can't be called by any
Silverlight client (here is the problem!) The error returned is "The remote server returned an exception: Not Found". If I change the name of the
service in Web.Config (let's say I change
MyCompany.Web.Services.MailService into MailService), the service can
now be called by any Silverlight client but at that time the service
is no longer discoverable.
I put includeExceptionDetailInFaults at True and tried to inspect the service with Fiddler/HTTPDebuggerPro but they didn't give me any detailed information about the exception. It looks to me that the Silverlight clients, in this configuration and for some reason, aren't able to create the .SVC file on the fly.
Here is the implementation:
MailService.svc implementation
<%# ServiceHost Language="C#" Debug="true" Service="MyCompany.Web.Services.MailService" CodeBehind="MailService.svc.cs" %>
MailService.svc.cs implementation
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public sealed partial class MailService : DomainService, IMailService
{
}
IMailService interface
[ServiceContract(ConfigurationName = "MyCompany.Web.Services.IMailService")]
public interface IMailService
{
//Some public methods flagged as [OperationContract] go here
}
Web.Config implementation
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="Secure_Behavior_Configuration">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="Public_MailService_BasicHttpBinding" transferMode="Streamed"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647"
maxBufferPoolSize="2147483647">
<readerQuotas maxArrayLength="21400000" maxStringContentLength="21400000" maxBytesPerRead="21400000"/>
<security mode="None"/>
</binding>
</basicHttpBinding>
<services>
<service name="MyCompany.Web.Services.MailService" behaviorConfiguration="Secure_Behavior_Configuration">
<endpoint
address=""
binding="basicHttpBinding"
bindingConfiguration="Public_MailService_BasicHttpBinding"
contract="MyCompany.Web.Services.IMailService" />
<endpoint
address=""
binding="basicHttpBinding"
bindingConfiguration="Secure_MailService_BasicHttpBinding"
contract="MyCompany.Web.Services.IMailService" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Thanks a lot for any help!
Chris.

Two endpoint (soap ,json) and one service method

I have that service
[OperationContract]
[WebGet(UriTemplate = "/GetData")]
List<FieldInfo> GetSerializedData();
and web.config
<system.web>
<webServices>
<protocols>
<add name="HttpGet" />
<add name="HttpPost" />
</protocols>
</webServices>
<httpRuntime executionTimeout="90" maxRequestLength="1048576" useFullyQualifiedRedirectUrl="false" minFreeThreads="8" minLocalRequestFreeThreads="4" appRequestQueueLimit="100"/>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingSettings" maxBufferPoolSize="524288" maxReceivedMessageSize="654321" sendTimeout="00:10:00" closeTimeout="00:01:00" openTimeout="00:10:00" receiveTimeout="00:10:00">
<security mode="None">
<transport clientCredentialType="None" />
</security>
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</webHttpBinding>
<wsHttpBinding>
<binding name="wsHttpBindingSettings" maxBufferPoolSize="524288" maxReceivedMessageSize="654321" sendTimeout="00:10:00" closeTimeout="00:01:00" openTimeout="00:10:00" receiveTimeout="00:10:00">
<security mode="None">
<transport clientCredentialType="None" />
</security>
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="MetadataBehavior" name="ServiceModel.Service">
<endpoint name="soap" address="soap" behaviorConfiguration="Default" binding="wsHttpBinding"
bindingConfiguration="wsHttpBindingSettings" contract="ServiceModel.IService" />
<endpoint name="Json" address="json" behaviorConfiguration="JSON" binding="webHttpBinding"
bindingConfiguration="webHttpBindingSettings" contract="ServiceModel.IService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://service.com/Service.svc/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MetadataBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="JSON">
<webHttp automaticFormatSelectionEnabled="true"/>
<dataContractSerializer maxItemsInObjectGraph="10000000"/>
</behavior>
<behavior name="Default">
<dataContractSerializer maxItemsInObjectGraph="10000000"/>
</behavior>
</endpointBehaviors>
</behaviors>
Why on the client side only one endpoint is generated ?
<client>
<endpoint address="http://service.renault.com/Service.svc/soap"
binding="wsHttpBinding" bindingConfiguration="soap" contract="ServiceReference1.IService"
name="soap" />
</client>
My point is to execute service method from asp.net page codebehind and wcf return data in soap or json depends on ContentType. But how to set in asp.net page content type to application/json when it have text/html content. I have problem with understand it.
Why on the client side only one endpoint is generated?
Because WCF does not emit metadata for non-SOAP endpoints. Unlike WSDL and MEX for SOAP, there's no widely used metadata format for "REST" endpoints (WADL is one of them, but it's not much used and not implemented by WCF), so on the Add Service Reference (or svcutil) will only see one endpoint in the metadata and only that one will be created.
I want to use WCF feature which select proper serialization type depends on ContentType of request
JSON vs XML is a serialization type decision; JSON vs SOAP is not (SOAP is a well-defined protocol, with rules for what the request should look like) - see more information on WCF Dynamic Response Format. Your webHttBinding-endpoint will do that (return JSON or XML based on the incoming request), since you enabled auto format selection, but the way you'd consume this service doesn't need to be with a WCF client - using WebClient, HttpWebRequest should work out just fine.
If possible, try to design you Visual Studio like this :
Solution
project with contracts (only the IXXXXService)
web project with the implementation and all the endpoints (reference the contract project)
clients project not using the VS generated proxy, but a factory that can select the correct endpoint and so protocol. (reference the contract project)
Here is a sample class I use in a scenario similar to yours :
public class ServiceHelper
{
/// <summary>
/// WCF proxys do not clean up properly if they throw an exception. This method ensures that the service
/// proxy is handeled correctly. Do not call TService.Close() or TService.Abort() within the action lambda.
/// </summary>
/// <typeparam name="TService">The type of the service to use</typeparam>
/// <param name="action">Lambda of the action to performwith the service</param>
[System.Diagnostics.DebuggerStepThrough]
public static void UsingProxy<TService>(Action<TService> action)
where TService : ICommunicationObject, IDisposable, new()
{
var service = new TService();
bool success = false;
try
{
action(service);
if (service.State != CommunicationState.Faulted)
{
service.Close();
success = true;
}
}
finally
{
if (!success)
{
service.Abort();
}
}
}
/// <summary>
/// WCF proxys do not clean up properly if they throw an exception. This method ensures that the service
/// proxy is handeled correctly. Do not call TService.Close() or TService.Abort() within the action lambda.
/// </summary>
/// <typeparam name="TIServiceContract">The type of the service contract to use</typeparam>
/// <param name="action">Action to perform with the client instance.</param>
/// <remarks>In the configuration, an endpoint with names that maches the <typeparamref name="TIServiceContract"/> name
/// must exists. Otherwise, use <see cref="UsingContract<TIServiceContract>(string endpointName, Action<TIServiceContract> action)"/>. </remarks>
[System.Diagnostics.DebuggerStepThrough]
public static void UsingContract<TIServiceContract>(Action<TIServiceContract> action)
{
UsingContract<TIServiceContract>(
typeof(TIServiceContract).Name,
action
);
}
/// <summary>
/// WCF proxys do not clean up properly if they throw an exception. This method ensures that the service
/// proxy is handeled correctly. Do not call TService.Close() or TService.Abort() within the action lambda.
/// </summary>
/// <typeparam name="TIServiceContract">The type of the service contract to use</typeparam>
/// <param name="action">Action to perform with the client instance.</param>
/// <param name="endpointName">Name of the endpoint to use</param>
[System.Diagnostics.DebuggerStepThrough]
public static void UsingContract<TIServiceContract>(
string endpointName,
Action<TIServiceContract> action)
{
var cf = new ChannelFactory<TIServiceContract>(endpointName);
var channel = cf.CreateChannel();
var clientChannel = (IClientChannel)channel;
bool success = false;
try
{
action(channel);
if (clientChannel.State != CommunicationState.Faulted)
{
clientChannel.Close();
success = true;
}
}
finally
{
if (!success) clientChannel.Abort();
}
}
}
In the client config, I set up manually my references :
<system.serviceModel>
<client>
<endpoint address="http://localhost/myapp/myservice.svc/soap"
binding="wsHttpBinding"
contract="MyProject.Contracts.IMyService"
name="IMyServiceSoap"/>
<endpoint address="http://localhost/myapp/myservice.svc/rest"
binding="webHttpBinding"
contract="MyProject.Contracts.IMyService"
name="IMyServiceRest"/>
</client>
</system.serviceModel>
Then, in your code you can simply call :
ServiceHelper.UsingContract<"IMyServiceSoap", MyProject.Contracts.IMyService>(
svc => svc.DoTheJob()
);
or
ServiceHelper.UsingContract<"IMyServiceRest", MyProject.Contracts.IMyService>(
svc => svc.DoTheJob()
);
[edit] The server config is similar to this one :
<services>
<service name="MyService">
<endpoint address="soap"
binding="wsHttpBinding"
contract="MyContracts.IMyService"/>
<endpoint address="rest"
binding="webHttpBinding"
contract="MyContracts.IMyService"/>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>

Fail to send image ( byte[] ) as parameter of WCF service

I wrote some service that have method that get image ( byte[] ) as parameter ( return void ).
I also wrote some client (client & server run on same machien - different sulotion - using IIS )that send the bitmap ( as byte[] ) to the service - and each time i try to send i get the exception:
An error occurred while receiving the HTTP response to http://localhost/WebService/Service.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down)
I added one more method that get void and return int - and i can call this method with no problem.
What can be wrong ? Do i need to define something speciel in the client service reference ?
The service method
[ServiceContract]
**public interface IService**
{
[OperationContract]
void GetPic( byte[] pic );
}
**public class Service : IService**
{
public void GetPic( byte[] pic )
{
...
}
}
Web.config file:
<system.serviceModel>
<services>
<service behaviorConfiguration="ServiceBehavior" name="ServiceProxy.Service">
<endpoint
name="basicHttp"
address=""
binding="basicHttpBinding"
bindingConfiguration=""
contract="Contracts.IService">
</endpoint>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" >
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8731/ServiceProxy/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
You must configure your binding on server to accept large messages. By default it accepts only messages up to 65KB and arrays with 16k elements = in your case bitmap which has size less then 16KB.
Use this in your web.config (server side):
<bindings>
<basicHttpBinding>
<binding name="myBinding" maxReceivedMessageSize="1000000">
<readerQuotas maxArrayLength="1000000" />
</binding>
</basicHttpBinding>
</bindings>
In your endpoint configuration reference this binding in bindingConfiguration attribute by setting it to myBinding.