gpt4 book ai didi

asp.net - WCF POST 服务 500 内部服务器错误

转载 作者:行者123 更新时间:2023-12-02 11:23:06 26 4
gpt4 key购买 nike

这是带有 ajaxcallback 的 WCF POST 服务。它在我这边工作正常,但在客户端工作不正常。它给出错误 - POST http://localhost/WCFService/EService.svc/GetTIDFromRID 500(内部服务器错误)。

方法:

[OperationContract]
[WebInvoke(Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.WrappedRequest
)]
string GetTIDFromRID(string RID);

服务Web.Config:

    <system.diagnostics>
<sources>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="messages"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="c:\logs\northwindservices.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
<system.serviceModel>
<diagnostics>
<messageLogging
logEntireMessage="false"
logMalformedMessages="true"
logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="false"
maxMessagesToLog="500"
maxSizeOfMessageToLog="5000"/>
</diagnostics>
</system.serviceModel>


<system.web>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
<compilation debug="true" targetFramework="4.0"/>
<authentication mode="None"></authentication>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/></system.web>
<appSettings>
<add key="ConStr" value="Data Source=C002;Initial Catalog=TEST;User ID=sa;Password=sa"/>
</appSettings>
<system.serviceModel>

<behaviors>
<serviceBehaviors>
<behavior name="EcubeBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<!--<webHttp/>-->
<enableWebScript/>
</behavior>
</endpointBehaviors>
</behaviors>

<services>
<service name="WCFService.EService" behaviorConfiguration="EBehavior">
<endpoint address="http://localhost/WCFService/EService.svc" behaviorConfiguration="web" binding="webHttpBinding" contract="WCFService.IEService"></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost/WCFService/EService.svc"/>
</baseAddresses>
</host>
</service>
</services>

<standardEndpoints>
<webScriptEndpoint>
<standardEndpoint name="" crossDomainScriptAccessEnabled="true"/>
</webScriptEndpoint>
</standardEndpoints>

<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
</serviceHostingEnvironment>

</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>

服务消耗:

$.ajax({
url: 'http://localhost/WCFService/EService.svc/GetTIDFromRID',
data: JSON.stringify({ "RID": "r1234" }),
dataType: 'json',
type: 'POST',
contentType: 'application/json; charset=utf-8',
success: function (data) {
},
error: function (data) {
alert('Response: Failed');
}
});

请给点建议。应用程序和服务都托管在不同的服务器上。也给予许可。还添加了 Global.asax,其中包含 Header 相关代码访问源...

最佳答案

一个500 internal server error指示错误源自 Web 服务主机。

为了帮助追踪问题,您可能需要考虑配置服务器端 WCF 跟踪,它将记录操作调用、代码异常、警告和其他重要处理事件。配置并启用 WCF 跟踪后,发送生成 http 状态 500 错误的消息并查看跟踪日志以查找任何潜在错误。

使用WCF Service Configuration Editor (Visual Studio -> 工具菜单)设置system.diagnostics跟踪值和相应的system.serviceModel配置文件的部分(下面的示例条目):

系统诊断

   <system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing" propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener" initializeData="wcf_trace_log.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
</configuration>

系统服务模型

  <system.serviceModel>
<diagnostics>
<messageLogging logEntireMessage="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true"/>
<endToEndTracing propagateActivity="true" activityTracing="true" messageFlowTracing="true"/>
</diagnostics>

https://msdn.microsoft.com/en-us/library/ms733025%28v=vs.110%29.aspx

关于asp.net - WCF POST 服务 500 内部服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28956420/

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