gpt4 book ai didi

WCF HTTP 服务 : installing vs2012 broke app

转载 作者:行者123 更新时间:2023-12-04 21:15:00 24 4
gpt4 key购买 nike

我有一个自托管网络服务 (WebServiceHost),它还提供 html 站点(带有 JavaScript 文件、图像等)。该服务在 .net 4.0(使用 vs2010)中运行良好。

现在我已经安装了 vs2012,但我的应用程序似乎已损坏(仍在使用 vs2010 - 也许安装 .net 4.5 是原因)。它编译得很好,我也没有运行时错误,但 html 和 JavaScript 在某些情况下似乎被破坏了。以下是(我认为)相关的代码片段:

使用的接口(interface)(System.Data.Services):

public interface IRequestHandler
{
Message ProcessRequestForMessage(Stream messageBody);
}

消息的创建:

string filePath = _physicalPath + string.Join("\\", incomingRequest.UriTemplateMatch.RelativePathSegments.ToArray());
HttpResponseMessageProperty responseProperty = new HttpResponseMessageProperty();

if (File.Exists(filePath) && SetContentType(responseProperty.Headers, Path.GetExtension(filePath).ToLower()))
{
Message message = Message.CreateMessage(MessageVersion.None, "", HttpServiceBodyWriter.Create(filePath));
message.Properties.Add(WebBodyFormatMessageProperty.Name, new WebBodyFormatMessageProperty(WebContentFormat.Raw));
message.Properties.Add(HttpResponseMessageProperty.Name, responseProperty);
}

HttpServiceBodyWriter:

class HttpServiceBodyWriter : StreamBodyWriter
{
private System.IO.Stream _source = null;

private HttpServiceBodyWriter(System.IO.Stream source) : base(false)
{
_source = source;
}

protected override void OnWriteBodyContents(System.IO.Stream stream)
{
_source.CopyTo(stream);
}

internal static HttpServiceBodyWriter Create(System.Net.WebResponse response)
{
return new HttpServiceBodyWriter(response.GetResponseStream());
}

internal static HttpServiceBodyWriter Create(string filePath)
{
return new HttpServiceBodyWriter(File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
}
}

如果我请求一个 HTML 页面,这有时会提供一个损坏的页面(请参阅双 dtd 定义和“head”之后的空标记):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<>
.....

有时会传送正确的页面:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="UTF-8" />
....

似乎初始页面请求总是提供正确的页面。后续请求损坏。

有没有人解释这种奇怪的行为?感谢任何帮助(这个问题让我想起了 C++ 时代)。

这是 App.Config 的 serviceModel 部分:

<system.serviceModel>
<diagnostics>
<messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="false" logMessagesAtTransportLevel="true" maxMessagesToLog="300000" maxSizeOfMessageToLog="200000" />
</diagnostics>
<services>
<service name="WcfTest.HttpService" behaviorConfiguration="DataServiceBehavior">
<endpoint name="DataService" binding="webHttpBinding" bindingConfiguration="DataService" contract="System.Data.Services.IRequestHandler" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/TestSite/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors />
<serviceBehaviors>
<behavior name="DataServiceBehavior">
<serviceDebug includeExceptionDetailInFaults="False" />
<dataContractSerializer maxItemsInObjectGraph="1000000" />
<serviceMetadata httpGetEnabled="true" />
<serviceThrottling maxConcurrentCalls="200" maxConcurrentInstances="2147483647" maxConcurrentSessions="200" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="DataService" maxReceivedMessageSize="5000000" maxBufferPoolSize="5000000" maxBufferSize="5000000" closeTimeout="00:03:00" openTimeout="00:03:00" receiveTimeout="00:10:00" sendTimeout="00:03:00">
<readerQuotas maxStringContentLength="5000000" maxArrayLength="5000000" maxBytesPerRead="5000000" />
<security mode="None"/>
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>

更新

我创建了一个小项目,您可以在其中重现此问题。您可以在这里下载:https://skydrive.live.com/redir?resid=CBC3C885DE2032B8!131&authkey=!ALZOaSL0V0s-itM

只需按几次浏览器的刷新按钮,直到出现损坏的 html。

最佳答案

这是 webHttpBinding + 4.5 关于启用消息日志记录的已知问题。并且与 http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/2bc5e5a6-1971-46cb-8b4f-f1c46130faca 相同.在服务中启用消息日志记录时会发生此问题。在针对此问题提供修复程序之前,请通过从您的配置中注释掉这些行来禁用您的应用程序配置文件中的消息记录。我验证了您的应用程序在禁用消息日志记录方面工作正常。希望这对您有所帮助!

<!--
<messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="false" logMessagesAtTransportLevel="true"
maxMessagesToLog="300000" maxSizeOfMessageToLog="200000" />-->

关于WCF HTTP 服务 : installing vs2012 broke app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13418612/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com