我試圖創建一個可以接受文件,並不會託管在IIS上的Web服務(我計劃將其作爲獨立服務運行)。我找到了一個如何在這裏執行此操作的示例:https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-create-a-basic-wcf-web-http-service接受大的帖子到WCF的Web服務不是由IIS託管
使用上述示例,我能夠啓動並運行所有內容,並且一切正常,直到我嘗試將它放在「較大」文件中, 413錯誤告訴我,我的提交是大的。我做了一些搜索,發現有一個緩衝區和/或最大提交大小變量需要修改,以允許更大的上傳,這是在App.config文件和/或web.config文件中完成的。我的問題是我不熟悉這些文件的結構,以及我創建項目的方式,沒有Web.config文件,我不知道必須的代碼應該放在App.config文件中。這是迄今爲止我所擁有的。
WCF服務合同
[ServiceContract]
public interface IService
{
[OperationContract]
[WebGet(UriTemplate = "/{profile}/GetFileIfExists/{fileName}", ResponseFormat = WebMessageFormat.Json)]
Stream GetFileIfExists(string fileName, string profile);
[OperationContract]
[WebInvoke(UriTemplate = "/{profile}/ReceiveFile",Method = "POST",BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)]
string ReceiveFile(string profile, Stream ORU);
}
這裏就是 「服務器/服務」 主機啓動
ep = host.AddServiceEndpoint(typeof(IService), new WebHttpBinding(), "");
host.Open();
cf = new ChannelFactory<IService>(new WebHttpBinding(), "http://localhost:9000");
cf.Endpoint.Behaviors.Add(new WebHttpBehavior());
這裏還有什麼是目前在App.config文件。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="WebMatrix.Data" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
我需要創建一個Web.config或者我可以把需要的組件中的App.config ..如果是這樣,我在哪裏把他們的文件中。我已經試過把下面的代碼放在「」開始標記下面,但沒有運氣......但我確信我錯過了一些明顯的東西。
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<readerQuotas maxStringContentLength="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
如果幫助,您可以設定[在代碼中綁定的值(https://stackoverflow.com/questions/2457408/how-to -set-the-maxreceivedmessagesize-programatically-when-using-a-wcf-client) – stuartd
現在我很尷尬,我沒有弄清楚自己!如果您將該答案作爲答案提交,我會接受它。否則,我將標記解決方案。 – jrlambs
這只是一個鏈接的答案,所以我不想發佈。樂意效勞。 – stuartd