WCF服务引发内部服务器错误

马克·博纳夫

我几乎已经达到了这一极限。我有一个WCF服务,当我使用Visual Studio 2013在本地运行时可以使用。我从WPF应用程序调用该服务。

我检查了其他似乎指向配置设置的线程,但我尝试过这些都没有运气。

这是我的服务代码。

    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceContract]
public class VerificationRequest
{
    [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "send", RequestFormat = WebMessageFormat.Json)]
    public Stream Send(PatientVerificationRequest data)
    {
        try
        {
            using (StreamWriter sw = File.AppendText("RequestLog"))
            {
                sw.WriteLine("Request Received");
            }

            if (data == null)
            {
                return new MemoryStream(Encoding.UTF8.GetBytes("<html><body>Post Successful</body></html>"));
            }

            // Put back into json format
            string json = JsonConvert.SerializeObject(data);

            using (StreamWriter sw = File.AppendText("RequestLog"))
            {
                sw.WriteLine(json);
            }

            // Log the request to the database
            // First, the actual json string
            var jsonId = PhoenixProcedure.CreateCloudVerificationRequest(json);
            var cvrId = PhoenixProcedure.CreateCloudVerificationRequest(data);

            if (WebOperationContext.Current != null)
            {
                WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.OK;
                WebOperationContext.Current.OutgoingResponse.ContentType = "text/html";
            }

            return new MemoryStream(Encoding.UTF8.GetBytes("<html><body>Post Successful</body></html>"));
        }
        catch (Exception ex)
        {
            Logger.Instance.WriteEvent(new LogEntry
            {
                Application = "DocumentVerification",
                EntryType = LoggingEventType.Error,
                Error = ex,
                Message = "Error Sending Verification Request",
                Source = "Send",
                SystemUserId = 8
            });
        }

        return null;
    }

这是web.config中的重要设置。

      <system.serviceModel>
<bindings>
  <webHttpBinding>
    <binding name="http" maxBufferSize="20971520" maxBufferPoolSize="20971520" maxReceivedMessageSize="20971520">
      <readerQuotas maxDepth="32"
           maxArrayLength="200000000"
           maxStringContentLength="200000000"/>
    </binding>
  </webHttpBinding>
  <basicHttpBinding>
    <binding name="efHttp" maxReceivedMessageSize="20000000"
         maxBufferSize="20000000"
         maxBufferPoolSize="20000000">
      <readerQuotas maxDepth="32"
           maxArrayLength="200000000"
           maxStringContentLength="200000000"/>
    </binding>
  </basicHttpBinding>
</bindings>
<services>
  <service name="DocVerify.VerificationRequest" behaviorConfiguration="ServiceBehavior">
    <endpoint address="" binding="webHttpBinding" bindingConfiguration="http" name="http" contract="DocVerify.VerificationRequest"/>
    <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex"/>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceDebug includeExceptionDetailInFaults="true"/>
      <serviceMetadata httpGetEnabled="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>

这是调用应用程序中的App.config。

  <system.serviceModel>
<behaviors>
  <endpointBehaviors>
    <behavior name="WCFHttpBehavior">
      <callbackDebug includeExceptionDetailInFaults="true" />
    </behavior>
    <behavior name="webhttp">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>
<bindings>
  <basicHttpBinding>
    <binding name="WCFHttpBinding" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647">
      <readerQuotas maxArrayLength="2147483647" maxDepth="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647" />
    </binding>
  </basicHttpBinding>
  <webHttpBinding>
    <binding name="WCFWebBinding" openTimeout="00:10:00" closeTimeout="00:10:00" sendTimeout="00:10:00" receiveTimeout="00:30:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </binding>
    <binding name="VerificationBinding" allowCookies="true"
             maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000">
      <readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000"/>
    </binding>
  </webHttpBinding>
</bindings>
<client>
  <endpoint address="http://PSICTSWEB01:65530/DocVerify/VerificationRequest.svc"
            binding="webHttpBinding" bindingConfiguration="VerificationBinding" 
            contract="DocVerify.VerificationRequest"
            behaviorConfiguration="webhttp"/>
</client>

最后,调用服务的代码。

            DocVerify.VerificationRequest rs = new VerificationRequestClient();
        rs.Send(new PatientVerificationRequest
        {
            request_type = (int)PatientVerificationRequestType.Full,
            patient_id = 120053,
            fname = "FirstName",
            lname = "LastName",
            gender = "M",
            dob_month = 2,
            dob_day = 14,
            dob_year = 1982,
            address1 = "10 Main St.",
            city = "Hampton",
            state = "VA",
            zipcode = "23669",
            reported_income = 54000,
            primary_insurance_name = "United Health Care",
            primary_policy_number = "PN123456",
            primary_group_number = "GN67890",
            primary_policy_holder_fname = "FirstName",
            primary_policy_holder_lname = "LastName"
        });

该服务在被调用时会立即创建一个日志。永远不会创建日志文件,因此在进行实际调用之前会引发错误-但会在rs.Send()方法期间发生。

我已经检查了服务器上的权限,以确保权限正确无误,以创建日志文件。在我看来,配置文件还可以,但是显然有些错误。有人有什么想法吗?

新信息:我打开了WCF跟踪,并收到此错误:

由于EndpointDispatcher上的AddressFilter不匹配,无法在接收方处理带有To'http://psictsweb01.psi.pri:65530 / DocVerify / VerificationRequest.svc / Send '的消息检查发送方和接收方的EndpointAddresses是否一致。

使用此信息,我已将web.config端点信息更改为:

    <binding name="VerificationBinding" allowCookies="true"
             maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000">
      <readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000"/>
    </binding>
  <service name="DocVerify.VerificationRequest" behaviorConfiguration="ServiceBehavior">
    <endpoint address="http://PSICTSWEB01:65530/DocVerify/VerificationRequest.svc"
              binding="webHttpBinding" bindingConfiguration="VerificationBinding" name="VerificationBinding" contract="DocVerify.VerificationRequest" behaviorConfiguration="webhttp"/>
  </service>

在应用程序中,绑定和端点为:

    <binding name="VerificationBinding" allowCookies="true"
             maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000">
      <readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000"/>
    </binding>
  <endpoint address="http://PSICTSWEB01:65530/DocVerify/VerificationRequest.svc"
            binding="webHttpBinding" bindingConfiguration="VerificationBinding" 
            contract="DocVerify.VerificationRequest"
            behaviorConfiguration="webhttp"/>

端点匹配。我究竟做错了什么?

马克·博纳夫

我认为这并不能真正回答这个问题,但是我确实得到了一项服务。首先,我将服务创建为网站,我认为我不必这样做。但是,这消除了端点地址匹配的需要。其次,在项目中创建新的.svc文件时,默认情况下会创建一个接口类。最初,我删除了该课程。我创建了一个测试服务类,这次保留了接口,该服务运行良好。

除非有人发现这里有问题,否则下周我可能必须从头开始,并缓慢地进行构建过程,以了解可能是在哪里弄糟了。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章