我在这里找到了我想要的东西:http://support.microsoft.com/kb/308001
看起来只有很小的代码更改需要实现。希望这对其他人也有帮助。
2019 年 6 月 21 日编辑
@Vermin 问我是否能找到链接,我找不到,但我确实找到了我的一个非常老的代码库,其中包含一些令人尴尬的代码,至少可以提供一些起点/方向(希望对其他人也是如此)。如果我没有很好地说明其中一些项目背后的“原因”,请原谅我(这是不久前的事了,我还没有完全理解到我应该理解的深度)。
1) 服务合约
[ServiceContract] public interface <svcName> ...
{
[OperationContract]
[WebGet(UriTemplate = "/*", BodyStyle = WebMessageBodyStyle.Bare)]
Stream MyGetMethod();
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "/*", BodyStyle = WebMessageBodyStyle.Bare)]
Stream MyPostMethod(Stream bodyStream);
2) 我还必须提供一个内容映射器(我真的不记得为什么了)
public class RawContentTypeMapper : WebContentTypeMapper
{
public override WebContentFormat GetMessageFormatForContentType(string contentType)
{
return WebContentFormat.Raw;
}
}
3) 然后我需要在 web.config 中做一些事情...
<system.serviceModel>
<services>
<service name="<namespace>.<svcName>" behaviorConfiguration="<behaviorName>">
<endpoint address="" binding="customBinding" behaviorConfiguration="<behaviorName>" contract="<namespace>.<svcName>" bindingConfiguration="<customBinding>"/>
</service>
</services>
<bindings>
<customBinding>
<binding name="<customBinding>">
<!-- Used for REST. See http://www.codehosting.net/blog/BlogEngine/post/WebContentFormatRaw-in-your-WCF-config-file.aspx -->
<!-- Provide the fully qualified name of the WebContentTypeMapper, set max message size to 500MB -->
<webMessageEncoding webContentTypeMapperType="<namespace>.RawContentTypeMapper, <namespace>, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<httpTransport manualAddressing="true" maxReceivedMessageSize="524288000" transferMode="Buffered" />
</binding>
</customBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="<behaviorName>">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="<behaviorName>">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
</behaviors>
<diagnostics performanceCounters="All"/>
</system.serviceModel>
我还在项目的 cmets 中看到了这个链接,这可能很有用:http://www.codehosting.net/blog/BlogEngine/post/WebContentFormatRaw-in-your-WCF-config-file
如果我无法真正解释上述所有内容的“原因”,您将不得不原谅我。其中一些很容易理解(映射 GET、POST 方法),其中一些我觉得我只是在尝试一些东西(web.config 的东西)。
在某些情况下,我记得我正在迁移的应用程序有代码来处理所有底层 HTTP 连接等,一旦我使用上述方法将它迁移到 IIS,并不是说它非常脆弱,我只是觉得好像我失去了很多控制权,却没有真正了解如何或为什么,并且需要做出改变确实让我觉得它很脆弱。这也是我构建 Watson Webserver(无耻插件)以快速构建 RESTful 服务器的原因之一:https://www.nuget.org/packages/Watson/2.0.5