我是 StackOverflow 的新手,所以如果我弄错了请原谅我。调用 wcf 服务时出现错误请求错误。该方法将字节数组作为参数。它适用于小文件,但不适用于长度为 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>
这是在我的服务网络配置文件中
<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;
}
我做错了什么?任何帮助将不胜感激。 更新:我已经像上面那样修改了服务配置文件,但仍然没有任何乐趣。 更新:已修复。我只需要将服务名称设为带命名空间的完全限定名称。 IE。 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>
关于c# - 调用 WCF 服务传递字节数组的错误请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20408720/