1

I'm rather new to WCF so I'm struggling with the web.config.

I created a WCF service on IIS10. Here is my web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <system.web>
    <customErrors mode="Off" />
    <compilation targetFramework="4.0" debug="true">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
    <caching>
      <outputCacheSettings>
        <outputCacheProfiles>
          <add name="DefaultCache" duration="60" varyByParam="none" />
        </outputCacheProfiles>
      </outputCacheSettings>
    </caching>
    <authentication mode="Windows" />
  </system.web>

  <system.serviceModel>
    <services>
      <service name="FileStorageService.FileService">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpBindingConfiguration" contract="FileStorageService.IFileService" />

        <!--<endpoint address="mex"  
                  binding="mexHttpsBinding"  
                  contract="IMetadataExchange" />-->
      </service>
    </services>

    <bindings>
      <basicHttpBinding>
        <binding name="basicHttpBindingConfiguration">
          <security mode="Transport">
            <transport clientCredentialType="Basic" proxyCredentialType="None" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>

    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpsGetEnabled="true" httpGetEnabled="false" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>


  <system.webServer>
    <httpErrors errorMode="Detailed" />
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
  <connectionStrings>
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

I can reference the api but I'm getting this message when I attempt to use it:

Server stack trace: at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter) at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at PpsTransactionFile.MyFileServiceReference.IFileService.DownloadPpsZipFile(DownloadFileRequest downloadFileRequest) at PpsTransactionFile.MyFileServiceReference.FileServiceClient.DownloadPpsZipFile(DownloadFileRequest downloadFileRequest) in D:\Source\Sub\Web Projects\WebStorageApps\PpsTransactionFile\Service References\MyFileServiceReference\Reference.cs:line 493 at PpsTransactionFile.download.DownloadFile.DownloadPpsZipFile(FileParms fileParms) in D:\Source\Sub\Web Projects\WebStorageApps\PpsTransactionFile\download\DownloadFile.cs:line 155

My code:

public static Status DownloadPpsTransactionFile(FileParms fileParms)
{
  var client = new FileServiceClient();

  try
  {
    var downloadstatus = new Status();
    downloadstatus.ProgramSendType = fileParms.SendGet;

    client.ClientCredentials.UserName.UserName = "xxxxxx";
    client.ClientCredentials.UserName.Password = "xxxxxxxxxxx";
    var trucks = fileParms.Trucks.Split(Convert.ToChar(","));

    foreach (var truck in trucks)
    {
      int trk;
      if (!int.TryParse(truck, out trk))
      {
        continue;
      }

      var downloadrequest = new DownloadFileRequest();
      downloadrequest.CompanyCode = fileParms.CompanyCode;
      downloadrequest.FileType = 1;
      downloadrequest.TruckNumber = trk;
      DownloadFileResponse download;

      do
      {
        download = client.DownloadPpsTransactionFile(downloadrequest);

It's failing on the last line when I call the wfc method. I cannot seem to get the IIS settings and web.config to work right.

My settings on IIS:

enter image description here

What am I doing wrong?

CLIENT SIDE CONFIG

<?xml version="1.0"?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IFileService">
          <security mode="Transport">
            <transport clientCredentialType="Basic" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="https://SOMEDOMAIN.COM/api/fileservice/FileService.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IFileService"
        contract="MyFileServiceReference.IFileService" name="BasicHttpBinding_IFileService" />
    </client>
  </system.serviceModel>

</configuration>

ADDITIONAL INFO

I found this in the event viewer. I'm currently researching it to see what it means.

FailedRequestTracing module failed to write buffered events to log file for the request that matched failure definition. No logs will be generated until this condition is corrected. The problem happened at least 1 times in the last 5 minutes. The data is the error.

ErocM
  • 4,505
  • 24
  • 94
  • 161
  • What's the exception message? Also, is server exposed on ssl ? – Wiktor Zychla Jan 03 '21 at 16:04
  • What is the **client-side** WCF config?? If you have a C# client - is that a command line app with an `app.config` - what does that look like? Is it a web app with a `web.config` - then what does that look like? You have to have the "same" configuration at your client side in order to talk to the WCF Service you've defined on the server. – marc_s Jan 03 '21 at 17:26
  • @WiktorZychla Thx for the reply. I have an ssl certificate installed if that what you are asking? – ErocM Jan 03 '21 at 17:59
  • @marc_s I've posted the client side config. – ErocM Jan 03 '21 at 18:57
  • @marc_s It's a winforms application that connects to a WCF service hosted by IIS10. I posted both the web and app config above, does that answer your questions? – ErocM Jan 04 '21 at 20:24
  • Yes, thanks - but it doesn't seem to be a config-related issue - the two configs seem to agree on all the important bits and pieces. I guess it was to be something somewhere in your service and/or client code - but I'm not clear on what that might be – marc_s Jan 04 '21 at 20:26
  • Perhaps it is just a typo as I noticed you misspelled in the client side endpoint configuration: ` – Lucky Brain Jan 05 '21 at 21:05
  • Just to make sure: the call to `client.DownloadPpsTransactionFile`, which itself is called inside `DownloadPpsTransactionFile`, is not recursive, right? – OfirD Jan 07 '21 at 13:21
  • can you show the definition for client.DownloadPpsTransactionFile(downloadrequest);? @ErocM – LinkedListT Jan 08 '21 at 14:39
  • Your `web.config`s seems ok, you should add your client code (`IFileService` and its implementing class), the problem is probably there. I also recommend to follow this [answer](https://stackoverflow.com/a/59141712/3002584) and add a `` configuration on the server side. – OfirD Jan 11 '21 at 10:50

3 Answers3

0

This is not my answer but I can't post this as a comment. This is a more clean way to show the exception which gives you an exact line number in D:\Source\Sub\Web Projects\WebStorageApps\PpsTransactionFile\download\DownloadFile.cs:line 155. It also indicates the exception has been rethrown impliying the fault is understood so you could start investigating there:

Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at PpsTransactionFile.MyFileServiceReference.IFileService.DownloadPpsZipFile(DownloadFileRequest downloadFileRequest)

at PpsTransactionFile.MyFileServiceReference.FileServiceClient.DownloadPpsZipFile(DownloadFileRequest downloadFileRequest)
in D:\Source\Sub\Web Projects\WebStorageApps\PpsTransactionFile\Service References\MyFileServiceReference\Reference.cs:line 493

at PpsTransactionFile.download.DownloadFile.DownloadPpsZipFile(FileParms fileParms)
in D:\Source\Sub\Web Projects\WebStorageApps\PpsTransactionFile\download\DownloadFile.cs:line 155

Also perhaps it is just a typo as I noticed you misspelled in the client side endpoint configuration: <endpoint address="https://SOMEDOMIAN.COM ... and I guess it should be <endpoint address="https://SOMEDOMAIN.COM... instead (NOTE the "IA" instead of "AI" in DOMAIN).

Lucky Brain
  • 1,551
  • 12
  • 14
0

I cannot post it as a comment but I suggest you to find the exception Message along with the stack trace. It may tell the reason why the response is not deserialised.

If this does not help, I would try Wireshark or logging proxy to trace and see what server replies to you request.

funnymay
  • 341
  • 1
  • 6
0

It looks like you have been following this guide:

https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-configure-an-iis-hosted-wcf-service-with-ssl

Does your code work if you set it up exactly like their example?

<?xml version="1.0"?>  
<configuration>  
  
  <system.web>  
    <compilation debug="true" targetFramework="4.0" />  
  </system.web>  
  <system.serviceModel>  
    <services>  
      <service name="MySecureWCFService.Service1">  
        <endpoint address=""  
                  binding="basicHttpBinding"  
                  bindingConfiguration="secureHttpBinding"  
                  contract="MySecureWCFService.IService1"/>  
  
        <endpoint address="mex"  
                  binding="mexHttpsBinding"  
                  contract="IMetadataExchange" />  
      </service>  
    </services>  
    <bindings>  
      <basicHttpBinding>  
        <binding name="secureHttpBinding">  
          <security mode="Transport">  
            <transport clientCredentialType="None"/>  
          </security>  
        </binding>  
      </basicHttpBinding>  
    </bindings>  
    <behaviors>  
      <serviceBehaviors>  
        <behavior>  
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->  
          <serviceMetadata httpsGetEnabled="true"/>  
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->  
          <serviceDebug includeExceptionDetailInFaults="false"/>  
        </behavior>  
      </serviceBehaviors>  
    </behaviors>  
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />  
  </system.serviceModel>  
  <system.webServer>  
    <modules runAllManagedModulesForAllRequests="true"/>  
  </system.webServer>  
  
</configuration>

Given the error:

FailedRequestTracing module failed to write buffered events to log file for the request that matched failure definition. No logs will be generated until this condition is corrected. The problem happened at least 1 times in the last 5 minutes. The data is the error.

Look into configuration here:

https://learn.microsoft.com/en-us/iis/troubleshoot/using-failed-request-tracing/troubleshooting-failed-requests-using-tracing-in-iis-85

I would also recommend you start simple: Create a Basic WCF Web HTTP Service that works and then modify. This will probably be a lot easier if you have not already tried that.

Console example:

Service.cs:

using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Web;
using System.Text;

namespace Microsoft.ServiceModel.Samples.BasicWebProgramming
{
    [ServiceContract]
    public interface IService
    {
        [OperationContract]
        [WebGet]
        string EchoWithGet(string s);

        [OperationContract]
        [WebInvoke]
        string EchoWithPost(string s);
    }
    public class Service : IService
    {
        public string EchoWithGet(string s)
        {
            return "You said " + s;
        }

        public string EchoWithPost(string s)
        {
            return "You said " + s;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            WebServiceHost host = new WebServiceHost(typeof(Service), new Uri("http://localhost:8000/"));
            try
            {
                ServiceEndpoint ep = host.AddServiceEndpoint(typeof(IService), new WebHttpBinding(), "");
                host.Open();
                using (ChannelFactory<IService> cf = new ChannelFactory<IService>(new WebHttpBinding(), "http://localhost:8000"))
                {
                    cf.Endpoint.Behaviors.Add(new WebHttpBehavior());

                    IService channel = cf.CreateChannel();

                    string s;

                    Console.WriteLine("Calling EchoWithGet via HTTP GET: ");
                    s = channel.EchoWithGet("Hello, world");
                    Console.WriteLine("   Output: {0}", s);

                    Console.WriteLine("");
                    Console.WriteLine("This can also be accomplished by navigating to");
                    Console.WriteLine("http://localhost:8000/EchoWithGet?s=Hello, world!");
                    Console.WriteLine("in a web browser while this sample is running.");

                    Console.WriteLine("");

                    Console.WriteLine("Calling EchoWithPost via HTTP POST: ");
                    s = channel.EchoWithPost("Hello, world");
                    Console.WriteLine("   Output: {0}", s);
                    Console.WriteLine("");
                }

                Console.WriteLine("Press <ENTER> to terminate");
                Console.ReadLine();

                host.Close();
            }
            catch (CommunicationException cex)
            {
                Console.WriteLine("An exception occurred: {0}", cex.Message);
                host.Abort();
            }
        }
    }
}

https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-create-a-basic-wcf-web-http-service

Ogglas
  • 62,132
  • 37
  • 328
  • 418