J'ai un service WCF hébergé dans une application ASP.NET et essaie de télécharger un fichier à partir d'une autre application ASP.NET client en utilisant le mode de diffusion en continu. Je continue à obtenir l'erreur suivante:WCF question en streaming avec ASP.NET
The remote server returned an unexpected response: (400) Bad Request.
J'ai parcouru le net pour obtenir de l'aide, mais en vain.
Host Configuration:
<bindings>
<basicHttpBinding>
<binding name="FileTransferServicesBinding"
transferMode="Streamed"
messageEncoding="Mtom"
sendTimeout="01:05:00"
maxReceivedMessageSize="10067108864">
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="FileTransferServiceBehavior" name="WebServiceHost.TransferService">
<clear />
<endpoint address="" binding="basicHttpBinding"
bindingConfiguration="FileTransferServicesBinding" contract="WebServiceHost.ITransferService">
<identity>
<dns value="localhost"/>
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:11291/TransferService.svc" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="FileTransferServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Code des marchés:
[ServiceContract]
public interface ITransferService
{
[OperationContract]
RemoteFileInfo DownloadFile(DownloadRequest request);
[OperationContract]
void UploadFile(RemoteFileInfo request);
[OperationContract]
string TestMethod();
}
[MessageContract]
public class DownloadRequest
{
[MessageBodyMember]
public string FileName;
}
[MessageContract]
public class RemoteFileInfo : IDisposable
{
[MessageHeader(MustUnderstand = true)]
public string FileName;
[MessageHeader(MustUnderstand = true)]
public long Length;
[MessageBodyMember(Order = 1)]
public System.IO.Stream FileByteStream;
public void Dispose()
{
if (FileByteStream != null)
{
FileByteStream.Close();
FileByteStream = null;
}
}
}
Configuration du client:
<bindings>
<basicHttpBinding>
<binding name="FileTransferServicesBinding" sendTimeout="01:05:00"
maxReceivedMessageSize="10067108864" messageEncoding="Mtom"
transferMode="Streamed" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:11291/TransferService.svc/"
binding="basicHttpBinding" bindingConfiguration="FileTransferServicesBinding"
contract="TransferServiceReference.ITransferService" name="FileTransferService"
kind="">
<identity>
<dns value="localhost" />
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
</client>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
Code client:
ITransferService clientUpload = new TransferServiceClient();
string datetime = clientUpload.TestMethod();
var uploadRequestInfo = new RemoteFileInfo();
uploadRequestInfo.FileName = FileUpload1.FileName;
uploadRequestInfo.Length = FileUpload1.PostedFile.ContentLength;
uploadRequestInfo.FileByteStream = FileUpload1.PostedFile.InputStream;
clientUpload.UploadFile(uploadRequestInfo);
L'appel échoue à la fois clientUpload.TestMethod() et clientUpload.UploadFile (uploadRequestInfo). Avec le mode buffered clientUpload.TestMethod() est invoqué, le problème est lié à la configuration en mode streaming.
Je serais reconnaissant de trouver une aide à ce sujet. Merci.
Je ne vois rien de mal avec évidemment la config. Vous devrez peut-être [Activer le suivi] (http://msdn.microsoft.com/en-us/library/ms733025.aspx) sur le service pour creuser un peu plus loin – Smudge202