簡體   English   中英

WCF服務引發內部服務器錯誤

[英]WCF Service Throws Internal Server Error

我已經達到了極限。 當我使用Visual Studio 2013在本地運行時,我有一個WCF服務。我從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文件時,默認情況下會創建一個接口類。 最初,我刪除了那個班級。 我創建了一個測試服務類,這次保留了界面,服務運行正常。

除非有人在這里看到了什么問題,否則我可能必須從下周開始,並在構建過程中慢慢地工作,看看我可能在哪里搞砸了小狗。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM