调用传递字节数组的WCF服务的错误请求



我是StackOverflow的新手,所以如果我弄错了,请原谅我。我在调用wcf服务时遇到了一个错误的请求。该方法将Byte数组作为参数。它适用于小文件,但不适用于长度为80000字节的文件。我已经在下面发布了网络配置文件。

这在我的网络配置文件中

    <system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IFileService" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
      maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
      useDefaultWebProxy="true">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
        maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost:4199/FileService.svc" binding="basicHttpBinding"
    bindingConfiguration="BasicHttpBinding_IFileService" contract="ConStringServices.IFileService"
    name="BasicHttpBinding_IFileService" />
</client>

这是在我的服务web配置文件中

    <system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="basicBinding" maxReceivedMessageSize="2147483647">
                <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/>
            </binding>              
        </basicHttpBinding>         
    </bindings>
    <services>
        <service behaviorConfiguration="MyServiceBehavior" name="MyService">
            <endpoint  bindingConfiguration="basicBinding" address="" binding="basicHttpBinding" contract="ConStringTest.Services.IFileService">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>             
        </service>          
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="MyServiceBehavior">
                <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                <serviceMetadata httpGetEnabled="true"/>
                <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

更新:这是在服务中调用的方法。就像我说的,它适用于小文件。

    public Boolean UploadFile(Byte[] file, string filename)
    {
        FileStream stream = new FileStream("C:\Temp\" + filename, FileMode.Create, FileAccess.ReadWrite);
        stream.Write(file, 0, file.Length);
        stream.Close();
        Console.WriteLine(file.Length);
        return true;
    }

我做错了什么?如有任何帮助,我们将不胜感激。更新:我已经如上修改了服务配置文件,但仍然没有乐趣。更新:已修复。我只需要将服务名称设置为具有命名空间的完全限定名称。e.ConStringTest.Services.FileService

问题在于将名称放在配置中。这不是一个arbritary名称,而是服务类文件的名称。如果错误,则不会应用配置,而是使用默认配置。将MyService更改为服务类的完全限定名称。。

<service behaviorConfiguration="MyServiceBehavior" name="ConStringTest.Services.FileService">
    <endpoint  bindingConfiguration="basicBinding" address="" binding="basicHttpBinding" contract="ConStringTest.Services.IFileService">
        <identity>
            <dns value="localhost" />
        </identity>
    </endpoint>             
</service> 

最新更新