简体   繁体   中英

WCF Service Throws Internal Server Error

I have pretty much reached my limits on this one. I have a WCF service that works when I run locally using Visual Studio 2013. I am calling the service from a WPF application.

I have checked other threads that seem to point to config settings and I've tried them with no luck.

Here is the code for my service.

    [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;
    }

And here are the important settings in the 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"/>

Here is the App.config in the calling application.

  <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>

And, finally, the code calling the service.

            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"
        });

The service immediately creates a log when called. The log file is never created, so the error is thrown before the actual call is made - but occurs during the rs.Send() method.

I've checked permissions on the server to make sure permissions are correct for creating the log file. It seems to me that the config files are ok, but something is obviously wrong. Does anyone have any ideas?

NEW INFO: I turned on WCF Tracing and am getting this error:

The message with To ' http://psictsweb01.psi.pri:65530/DocVerify/VerificationRequest.svc/Send ' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher. Check that the sender and receiver's EndpointAddresses agree.

Using this information, I have changed the web.config endpoint information to:

  <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>

In the application, the binding and endpoint are:

  <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"/>

The endpoints match. What am I doing wrong?

I don't think this really answers this question, but I did get a service to work. First, I created the service as a web site, something I don't think I should have to do. However, this removed the need for the endpoint address matching. Second, when creating a new .svc file in the project, it creates an interface class by default. Originally, I removed that class. I created a test service class and kept the interface this time and the service worked fine.

Unless someone sees what is wrong here, I may have to start from scratch next week and work slowly through the build process to see where I may have screwed the pooch.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM