我之所以要求這是另一個問題,是因爲我使用Castle Windsor 3.0作爲我的DI框架,從而通過CW的WCF工具配置我的端點。我無法使用此設置找到任何解決方案。(Another)遠程服務器返回了一個意外的響應:(400)Bad Request - Castle Windsor,WCF
::更新::
感謝您的意見。
該項目是一個標準的WCF服務應用程序,它提供了許多連接到底層函數(SQl服務器等)的標準類庫。 項目中存在的Web服務是標準的Wcf服務(.svc),並將託管在IIS中(在默認的VS調試服務器中測試)將由ASP.NET MVC3 Web應用程序使用。
服務在客戶端和服務端均被連接到Windsor Container。
服務側:
<%@ ServiceHost
Language="C#"
Debug="true"
Service="FileDownloadService"
CodeBehind="FileDownloadService.svc.cs"
Factory="Castle.Facilities.WcfIntegration.DefaultServiceHostFactory,
Castle.Facilities.WcfIntegration" %>
因此,溫莎WCFacility負責所有依賴注入分辨率在兩個MVC3應用程序,和WCF服務應用程序。
我擔心配置的主要原因(我知道它使用了我從表單教程/演練/ SO問題獲得的值),因爲我不確定Windsor是否100%在服務端選擇了此配置 - 意見呢?
我也更新了代碼片段以顯示當前的impl。
[DataContract]
public enum FileTypeEnum
{
[EnumMember]
Generic = 1,
[EnumMember]
TXT = 2,
[EnumMember]
XLS = 3,
[EnumMember]
PDF = 4,
[EnumMember]
DOC = 5
}
Web服務的解決方案,這有WCF Web服務,定義了以下合約:
[ServiceContract]
public interface IFileDownloadService
{
[OperationContract]
FileDownloadReturnMessage DownloadFile(FileDownloadMessage request);
}
返回類型的合同是:
[MessageContract]
public class FileDownloadReturnMessage : IDisposable
{
public FileDownloadReturnMessage(FileMetaData metaData, Stream stream)
{
FileByteStream = stream;
}
[MessageBodyMember(Order = 1)]
public Stream FileByteStream;
[MessageHeader(MustUnderstand = true)]
public FileMetaData DownloadedFileMetadata;
public void Dispose()
{
if (FileByteStream != null)
{
FileByteStream.Close();
FileByteStream = null;
}
}
和請求合同是:
[MessageContract]
public class FileDownloadMessage
{
[MessageHeader(MustUnderstand = true)]
public FileMetaData FileMetaData;
}
和:
[DataContract(Namespace = "http://schemas.acme.it/2009/04")]
public class FileMetaData
{
public FileMetaData(string fileName, string remoteFilePath)
{
FileName = fileName;
RemoteServerFilePath = remoteFilePath;
FileType = FileTypeEnum.Generic;
}
public FileMetaData(string fileName, string remoteFilePath, FileTypeEnum? fileType)
{
FileName = fileName;
RemoteServerFilePath = remoteFilePath;
FileType = fileType;
}
[DataMember(Name = "FileType", Order = 0, IsRequired = true)]
public FileTypeEnum? FileType;
[DataMember(Name = "FileName", Order = 1, IsRequired = true)]
public string FileName;
[DataMember(Name = "RemoteFilePath", Order = 2, IsRequired = true)]
public string RemoteServerFilePath;
}
服務器的溫莎上的配置注入的服務是:
.Register(Component.For<IFileDownloadService>()
.ImplementedBy<FileDownloadService>()
.Named("FileDownloadService")
.AsWcfService(new DefaultServiceModel()
.AddEndpoints(WcfEndpoint
.BoundTo(new BasicHttpBinding
{
MaxReceivedMessageSize = 2147483647,
MaxBufferSize = 2147483647,
MaxBufferPoolSize = 2147483647,
TransferMode = TransferMode.Streamed,
MessageEncoding = WSMessageEncoding.Mtom,
ReaderQuotas = new XmlDictionaryReaderQuotas
{
MaxDepth = 2147483647,
MaxArrayLength = 2147483647,
MaxStringContentLength = 2147483647,
MaxNameTableCharCount = 2147483647,
MaxBytesPerRead = 2147483647
}
}))
.Hosted()
.PublishMetadata())
.LifeStyle.PerWcfOperation())
和端點的客戶端配置爲:
_container.Register(Component.For<IFileDownloadService>()
.AsWcfClient(new DefaultClientModel
{
Endpoint = WcfEndpoint
.BoundTo(new BasicHttpBinding
{
MaxReceivedMessageSize = 2147483647,
MaxBufferSize = 2147483647,
MaxBufferPoolSize = 2147483647,
TransferMode = TransferMode.Streamed,
MessageEncoding = WSMessageEncoding.Mtom,
ReaderQuotas = new XmlDictionaryReaderQuotas
{
MaxDepth = 2147483647,
MaxArrayLength = 2147483647,
MaxStringContentLength = 2147483647,
MaxNameTableCharCount = 2147483647,
MaxBytesPerRead = 2147483647
}
})
.At(ConfigurationManager.AppSettings["FileDownloadAddress"])
}));
據因爲我知道這些端點配置必須匹配,他們會這樣做。但由於某些原因擊中方法:
var commandResult = _downloadService.DownloadFile(command);
結果與以下堆棧跟蹤的異常:
Ex Message: The remote server returned an unexpected response: (400) Bad Request.
Source: Castle.Facilities.WcfIntegration
Target Site: Castle.Facilities.WcfIntegration.Proxy.WcfRemotingInterceptor+<>c__DisplayClass1 -> Void <PerformInvocation>b__0(Castle.Facilities.WcfIntegration.WcfInvocation)
Stack Trace: at Castle.Facilities.WcfIntegration.Proxy.WcfRemotingInterceptor.<>c__DisplayClass1.<PerformInvocation>b__0(WcfInvocation wcfInvocation)
at Castle.Facilities.WcfIntegration.Proxy.WcfRemotingInterceptor.ApplyChannelPipeline(Int32 policyIndex, WcfInvocation wcfInvocation, Action`1 action)
at Castle.Facilities.WcfIntegration.Proxy.WcfRemotingInterceptor.<>c__DisplayClass4.<ApplyChannelPipeline>b__3()
at Castle.Facilities.WcfIntegration.WcfInvocation.Proceed()
at Castle.Facilities.WcfIntegration.RepairChannelPolicy.Apply(WcfInvocation wcfInvocation)
at Castle.Facilities.WcfIntegration.Proxy.WcfRemotingInterceptor.ApplyChannelPipeline(Int32 policyIndex, WcfInvocation wcfInvocation, Action`1 action)
at Castle.Facilities.WcfIntegration.Proxy.WcfRemotingInterceptor.PerformInvocation(IInvocation invocation, IWcfChannelHolder channelHolder, Action`1 action)
at Castle.Facilities.WcfIntegration.Proxy.WcfRemotingInterceptor.PerformInvocation(IInvocation invocation, IWcfChannelHolder channelHolder)
at Castle.Facilities.WcfIntegration.Async.WcfRemotingAsyncInterceptor.PerformInvocation(IInvocation invocation, IWcfChannelHolder channelHolder)
at Castle.Facilities.WcfIntegration.Proxy.WcfRemotingInterceptor.Intercept(IInvocation invocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.IWcfChannelHolderProxy_2.FakeDownloadTest(FakeDownloadTestRequest request)
at cpfe.DAL.Repositories.FileDownloadRepository.DownloadFile(IEnumerable`1 fileIds, TenantDTO tenant, String zipPackageName, UserDTO user) \..\..\..\FileDownloadRepository.cs:line 44
沒有任何人有任何線索,爲什麼發生這種情況?
在此先感謝!
瞭解一些關於您如何託管服務可能會有所幫助 - 我看到您將問題標記爲asp .net mvc,但您在描述中提到了一個Web服務項目 - 它是什麼類型的項目以及將要執行什麼操作在那裏關於配置容器,路線等?我只是使用幾個控制檯應用程序來嘗試@Hyralex答案,它運行良好,因此可以將其縮小到我認爲的服務主機。 – kmp
@kmp - 更新了問題,歡呼聲。 – M05Pr1mty
我們可以看到FileTypeEnum的合約嗎? – Hyralex