繁体   English   中英

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

[英]Bad Request calling WCF service passing byte array

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

这是在我的Web配置文件中

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

我究竟做错了什么? 任何帮助将不胜感激。 更新:我已经如上所述修改了服务配置文件,但仍然没有任何乐趣。 更新:它是固定的。 我只需要使用名称空间将服务名称命名为“完全限定名称”。 即。 ConStringTest.Services.FileService

问题出在放置名称的配置中。 这不是一个人为的名称,而是服务类文件的名称。 如果配置错误,则将不应用该配置,并将使用默认配置。 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> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM