WCF POST Service 500内部服务器错误

时间:2015-03-10 04:54:43

标签: asp.net web-services wcf

这是带有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');
        }
    });

请提出一些建议。 Application和Service都托管在不同的服务器上。许可也给予了许可。还添加了Global.asax,其中包含与头相关的代码访问源...

1 个答案:

答案 0 :(得分:5)

500 internal server error表示错误源自Web服务主机。

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

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

System.Diagnostics程序

   <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

  <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