Aumento del tamaño máximo del mensaje
Última modificación: jueves, 01 de septiembre de 2011
Hace referencia a: SharePoint Foundation 2010
Disponible en SharePoint Online
Cuando se realiza una solicitud de gran tamaño mediante el modelo de objetos de cliente, se puede recibir un error de solicitud incorrecta. Si es así, puede usar el modelo de objetos de servidor para aumentar el tamaño máximo para mensajes permitido por el servicio de Windows Communication Foundation (WCF), Client.svc, que es compatible con el modelo de objetos de cliente de SharePoint Foundation. Otra opción es usar el Sistema distribuido de creación y control de versiones (DAV) para realizar una solicitud PUT.
El modelo de objetos de servidor proporciona dos propiedades para aumentar el tamaño máximo de los mensajes. Puede establecer la propiedad MaxReceivedMessageSize en la clase SPWcfServiceSettings, o la propiedad MaxReceivedMessageSize en la clase SPClientRequestServiceSettings. Puede tener acceso a estas propiedades mediante el objeto SPWebService de una de las formas siguientes: SPWebService.ContentService.ClientRequestServiceSettings o SPWebService.ContentService.WcfServiceSettings["Client.svc"]. Según el valor de la propiedad del objeto SPClientRequestServiceSettings, SharePoint Foundation usa, o no usa, la propiedad del objeto SPWcfServiceSettings como se muestra a continuación:
Si SPWebService.ContentService.ClientRequestServiceSettings.MaxReceivedMessageSize es mayor que cero, SharePoint Foundation usa este valor como configuración de la propiedad.
Si SPWebService.ContentService.ClientRequestServiceSettings.MaxReceivedMessageSize es igual a cero, SharePoint Foundation usa el valor predeterminado como configuración.
Si SPWebService.ContentService.ClientRequestServiceSettings.MaxReceivedMessageSize es igual a -1, SharePoint Foundation usa el valor SPWcfServiceSettings como configuración si se ha definido; en caso contrario, SharePoint Foundation usa 64 KB como configuración.
Aumento de MaxReceivedMessageSize de WCF
El fragmento de código siguiente muestra cómo usar la propiedad MaxReceivedMessageSize del objeto SPClientRequestServiceSettings para modificar la configuración del tamaño de mensaje.
Public Shared Sub IncreaseMaxReceivedMessageSize()
Dim contentService As SPWebService = SPWebService.ContentService
contentService.ClientRequestServiceSettings.MaxReceivedMessageSize = 10485760 ' 10MB
contentService.Update()
End Sub
public static void IncreaseMaxReceivedMessageSize()
{
SPWebService contentService = SPWebService.ContentService;
contentService.ClientRequestServiceSettings.MaxReceivedMessageSize = 10485760; // 10MB
contentService.Update();
}
El fragmento de código siguiente muestra cómo usar la propiedad MaxReceivedMessageSize del objeto SPWcfServiceSettings para modificar la configuración. En el ejemplo, en primer lugar se debe establecer la propiedad en SPClientRequestServiceSettings en -1.
Public Shared Sub IncreaseMaxReceivedMessageSize()
Dim contentService As SPWebService = SPWebService.ContentService
' Must set this to -1, else, the MaxReceivedMessageSize value for
' SPWebService.ContentService.WcfServiceSettings["client.svc"] will not be used.
contentService.ClientRequestServiceSettings.MaxReceivedMessageSize = -1
' SPWcfServiceSettings has other Properties that you can set.
Dim csomWcfSettings As New SPWcfServiceSettings()
csomWcfSettings.MaxReceivedMessageSize = 10485760 ' 10MB
contentService.WcfServiceSettings("client.svc") = csomWcfSettings
contentService.Update()
End Sub
public static void IncreaseMaxReceivedMessageSize ()
{
SPWebService contentService = SPWebService.ContentService;
/* Must set this to -1, else, the MaxReceivedMessageSize value for
SPWebService.ContentService.WcfServiceSettings["client.svc"] will not be used.*/
contentService.ClientRequestServiceSettings.MaxReceivedMessageSize = -1;
// SPWcfServiceSettings has other Properties that you can set.
SPWcfServiceSettings csomWcfSettings = new SPWcfServiceSettings();
csomWcfSettings.MaxReceivedMessageSize = 10485760; // 10MB
contentService.WcfServiceSettings["client.svc"] = csomWcfSettings;
contentService.Update();
}
Uso de DAV para realizar la solicitud
En el ejemplo siguiente se muestra cómo se usa DAV para realizar la solicitud.
WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp)
Dim request As HttpWebRequest = DirectCast(WebRequestCreator.ClientHttp.Create(New Uri("https://Server/MyFile.txt")), HttpWebRequest)
request.Method = "PUT"
' Make an asynchronous call for the request stream. The callback method will be called on a background thread.
Dim asyncResult As IAsyncResult = request.BeginGetRequestStream(New AsyncCallback(RequestStreamCallback), request)
Private Sub RequestStreamCallback(ByVal ar As IAsyncResult)
Dim request As HttpWebRequest = TryCast(ar.AsyncState, HttpWebRequest)
Dim requestStream As Stream = request.EndGetRequestStream(ar)
Dim streamWriter As New StreamWriter(requestStream)
' Write your file here.
streamWriter.Write("Hello World!")
' Close the stream.
streamWriter.Close()
' Make an asynchronous call for the response. The callback method will be called on a background thread.
request.BeginGetResponse(New AsyncCallback(ResponseCallback), request)
End Sub
Private Sub ResponseCallback(ByVal ar As IAsyncResult)
Dim request As HttpWebRequest = TryCast(ar.AsyncState, HttpWebRequest)
Dim response As WebResponse = Nothing
Try
response = request.EndGetResponse(ar)
Catch generatedExceptionName As WebException
Catch generatedExceptionName As SecurityException
' You may need to analyze the response to see if it succeeded.
End Try
End Sub
WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);
HttpWebRequest request = (HttpWebRequest)WebRequestCreator.ClientHttp.Create(new Uri("https://Server/MyFile.txt"));
request.Method = "PUT";
/* Make an asynchronous call for the request stream. The callback method will be called on a background thread. */
IAsyncResult asyncResult = request.BeginGetRequestStream(new AsyncCallback(RequestStreamCallback), request);
private void RequestStreamCallback(IAsyncResult ar)
{
HttpWebRequest request = ar.AsyncState as HttpWebRequest;
Stream requestStream = request.EndGetRequestStream(ar);
StreamWriter streamWriter = new StreamWriter(requestStream);
// Write your file here.
streamWriter.Write("Hello World!");
// Close the stream.
streamWriter.Close();
/* Make an asynchronous call for the response. The callback method will be called on a background thread. */
request.BeginGetResponse(new AsyncCallback(ResponseCallback), request);
}
private void ResponseCallback(IAsyncResult ar)
{
HttpWebRequest request = ar.AsyncState as HttpWebRequest;
WebResponse response = null;
try
{
response = request.EndGetResponse(ar);
}
catch (WebException)
{}
catch (SecurityException)
{}
// You may need to analyze the response to see if it succeeded.
}
En una aplicación de Silverlight también es posible que necesite establecer el archivo XML de directivas de acceso de cliente, tal como se muestra en el ejemplo siguiente. Puede colocar este archivo en % inetpub%\wwwroot\wss\VirtualDirectories\80.
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<!--Enables Silverlight 3 all methods functionality-->
<policy>
<allow-from http-methods="*">"
<domain uri="*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
<!--Enables Silverlight 2 clients to continue to work normally -->
<policy>
<allow-from >
<domain uri="*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
Para obtener más información acerca de la comunicación de Silverlight y HTTP, vea HTTP Communication and Security with Silverlight.
Vea también
Conceptos
Introducción a la recuperación de datos
Instrucciones del modelo de objetos cliente
Tareas comunes de programación
Otros recursos
Uso del modelo de objetos de cliente administrado de SharePoint Foundation 2010