1

我正在尝试通过 iis 8 中托管的 wcf 服务上传文件我正在使用 Visual Studio 2010。我遇到以下错误我如何提供将在服务器上写入文件的流

远程服务器返回意外响应:(400) 错误请求。

网络配置

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="false" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <bindings>
  <basicHttpBinding>
    <binding  name="BasicHttpBinding_IService"
              transferMode="Streamed"
              messageEncoding="Mtom"
              maxReceivedMessageSize="10067108864"
             />
    </basicHttpBinding>
    </bindings>
    <behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

应用配置

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IService"
                     maxReceivedMessageSize="10067108864"
                     transferMode="Streamed"/>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost/FileService/Service.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
            contract="ServiceReference1.IService" name="BasicHttpBinding_IService" />
    </client>
</system.serviceModel>
</configuration>

代码

[ServiceContract]
public interface IService
{
[OperationContract]
void UploadFile(System.IO.Stream fstream);
}
4

1 回答 1

0

我在我的配置文件中遇到了问题

我需要如下更改我的网络配置

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding maxReceivedMessageSize="999999999" transferMode="Streamed" messageEncoding="Mtom"/>
  </basicHttpBinding>  
</bindings>

和应用程序配置如下

 <system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IFileService" maxReceivedMessageSize="10485760"  transferMode="Streamed" messageEncoding="Mtom"/>
        </basicHttpBinding>
    </bindings>
    <client>
于 2013-10-15T15:38:10.480 回答