(他人)的远程服务器返回了意外的响应:(400)错误的请求 - 温莎城堡,WCF [英] (Another) The remote server returned an unexpected response: (400) Bad Request - Castle Windsor, WCF

查看:155
本文介绍了(他人)的远程服务器返回了意外的响应:(400)错误的请求 - 温莎城堡,WCF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我问这是别人的众多独立问题的原因是,我使用温​​莎城堡3.0作为我的DI框架,从而通过CW的WCF设施配置我的端点。我无法找到与此设置的任何决议。

The reason I am asking this as a separate question to the multitude of others is that I am using Castle Windsor 3.0 as my DI framework and thus configuring my endpoints through the WCF Facility of CW. I am unable to find any resolution with this setup.

::更新::

感谢您的意见。

该项目是一个标准的WCF服务应用程序,哺养了一些连接到底层funcitonality(SQL服务器等)的标准类库。
存在于项目中的Web服务是标准的WCF服务(.SVC),将在IIS(默认VS调试服务器测试)主办将由ASP.NET MVC3 Web应用程序被消耗掉。

The project is a standard WCF Service Application, which feeds off a number of standard class libraries connecting to underlying funcitonality (SQl Server etc). The Web services that exist in the project are standard Wcf Services (.svc) and will be hosted in IIS (tested in the default VS debugging server) will be consumed by an ASP.NET MVC3 Web Application.

这些服务挂钩到温莎集装箱在这个客户端和服务方面。

The services are hooked into the Windsor Container at both client and service sides of this.

服务端:

<%@ ServiceHost 
Language="C#" 
Debug="true" 
Service="FileDownloadService" 
CodeBehind="FileDownloadService.svc.cs" 
Factory="Castle.Facilities.WcfIntegration.DefaultServiceHostFactory, 
    Castle.Facilities.WcfIntegration" %>

因此​​,温莎WCFacility负责所有依赖注入的分辨率在两个MVC3应用程序和WCF服务应用程序。

Thus, the Windsor WCFacility is responsible for all dependency injection resolution in both the MVC3 app, and the WCF Service Application.

我关注于在配置主要的原因(我知道用我所获得的形式教程/演练/ SO问题的值)是因为我不能确定,如果温莎100%捡这个配置了服务端 - 意见?

The main reason I am concerned over the configuration (which I know uses values which I have obtained form tutorials/walkthroughs/SO questions) is because I am unsure if Windsor is 100% picking this configuration up on the service side - opinions?

我也更新了code片段,显示当前implement执行。

I have also updated the code snippets to show the current impl.

[DataContract]
    public enum FileTypeEnum
    {
        [EnumMember]
        Generic = 1,

        [EnumMember]
        TXT = 2,

        [EnumMember]
        XLS = 3,

        [EnumMember]
        PDF = 4,

        [EnumMember]
        DOC = 5
    }


Web服务解决方案,这在有WCF Web服务,定义了以下合约:


The Web Service solution, which has the WCF web service in, defines the following contract:

[ServiceContract]
public interface IFileDownloadService
{
    [OperationContract]
     FileDownloadReturnMessage DownloadFile(FileDownloadMessage request);
}

返回类型的合同是:

The return type contract is:

[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;
}

在服务器上为温莎上的配置注入的服务是:

The configuration on the server for the Windsor injected service is:

.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"])
                            }));

据我所知,这些端点配置必须匹配,这是他们做的。但由于某些原因击球方式:

As far as I know these endpoint configurations have to match, which they do. But for some reason hitting the method:

var commandResult = _downloadService.DownloadFile(command);

业绩符合以下堆栈跟踪的异常:

results in an exception with the following stack trace:

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

没有任何人有任何线索,为什么发生这种情况?

Does anybody have any clue as to why this is happening?

在此先感谢!

推荐答案

我转载400错误,它是在code做了一些更改后走了:

I reproduced 400 error and it is gone after a few changes made in code:


  1. 使用 TransferMode = TransferMode.StreamedResponse,而不是。我申请,只有在客户端配置。服务器仍然有

  2. 默认(无参数)构造函数添加到 FileDownloadReturnMessage 。这是必要的 MessageContract 反序列化。 code - 公共FileDownloadReturnMessage(){}

  1. Use TransferMode = TransferMode.StreamedResponse, instead of Streamed. I applied that only to client configuration. Server still has Streamed.
  2. Add default (parameterless) constructor to FileDownloadReturnMessage. It is necessary for MessageContract deserialization. Code - public FileDownloadReturnMessage() { }

这是我现在无法重现错误回来,一切工作正常,即使 TransferMode.Streamed

Funny thing that now I cannot reproduce error back and everything works fine even with TransferMode.Streamed

让我知道这是否有帮助。

Let me know if that helped.

我可以发表我的code,如果你仍然无法解决问题。

I can publish my code if you still cannot fix the issue.

有趣的是,由WCF客户端产生的400错误。如果您在提琴手检查业务服务器总是返回200和正确的数据。

Interesting thing is that 400 error is generated by WCF in client. Server always returns 200 and correct data if you check traffic in fiddler.

这篇关于(他人)的远程服务器返回了意外的响应:(400)错误的请求 - 温莎城堡,WCF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆