我是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>
这是我的服务网络配置文件
<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
答案 0 :(得分:1)
问题出在您输入名称的配置中。这不是一个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>