none
WCF service on IIS RRS feed

  • Question

  • On the basis of examples I try to create WCF service on IIS how-to-host-a-wcf-service-in-iis, getting-started-tutorial.But when I try to link the project with a windows form I receive an error(http://localhost:8000/GettingStarted/CalculatorService). I Will be glad if you tell me what I'm doing wrong.

    App.config

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>

      <appSettings>
        <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
      </appSettings>
      <system.web>
        <compilation debug="true" />
      </system.web>
      <!-- Во время развертывания проекта библиотеки служб содержимое файла конфигурации необходимо добавить к файлу 
      app.config на узле. Файлы конфигурации для библиотек не поддерживаются System.Configuration. -->
      <system.serviceModel>
        <services>
          <service name="GettingStarted.CalculatorService">
            <endpoint address="" binding="wsHttpBinding" contract="GettingStarted.ICalculator">
              <identity>
                <dns value="localhost" />
              </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            <host>
              <baseAddresses>
                <add baseAddress = "http://localhost:8000/GettingStarted/CalculatorService" />
              </baseAddresses>
            </host>
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <!--Чтобы избежать раскрытия метаданных, 
              до развертывания задайте следующим параметрам значение "false".-->
              <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
              <!-- Чтобы получить сведения об исключениях в ошибках для отладки, 
              установите ниже значение TRUE. Перед развертыванием установите значение FALSE, 
               чтобы избежать разглашения сведений об исключении -->
              <serviceDebug includeExceptionDetailInFaults="False" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>

    </configuration>

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;

    namespace GettingStarted
    {
        // ПРИМЕЧАНИЕ. Команду "Переименовать" в меню "Рефакторинг" можно использовать для одновременного изменения имени интерфейса "IService1" в коде и файле конфигурации.
        [ServiceContract]
        public interface ICalculator
        {
            [OperationContract]
            double Add(double n1, double n2);
            [OperationContract]
            double Subtract(double n1, double n2);
            [OperationContract]
            double Multiply(double n1, double n2);
            [OperationContract]
            double Divide(double n1, double n2);
        }


    }

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;

    namespace GettingStarted
    {
        // ПРИМЕЧАНИЕ. Команду "Переименовать" в меню "Рефакторинг" можно использовать для одновременного изменения имени класса "Service1" в коде и файле конфигурации.
        public class CalculatorService : ICalculator
        {
            public double Add(double n1, double n2)
            {
                double result = n1 + n2;
                return result;
            }

            public double Subtract(double n1, double n2)
            {
                double result = n1 - n2;
                return result;
            }

            public double Multiply(double n1, double n2)
            {
                double result = n1 * n2;
                return result;
            }

            public double Divide(double n1, double n2)
            {
                double result = n1 / n2;
                return result;
            }
        }
    }

    GettingStarted.CalculatorService.svc

    <%@ServiceHost language=c# Debug="true" Service="GettingStarted.CalculatorService"%>

    Monday, July 1, 2019 7:53 PM

All replies

  • Hi ,

    Since the problem is more related to WCF, I'll help you to move this thread to the Windows Communication Foundation, Serialization, and Networking Forum. You could get more professional support about WCF there.

    Thank you for your patience.

    Best regards,

    Roy

     


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, July 2, 2019 2:17 AM
  • Hi IrinaSergeeva,
    We should specify the http base address in the IIS site binding module, instead of specifying the base address of the service in the configuration file

    Since the WCF document is too old, we could use the below configuration to simplify this.

    <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <protocolMapping>
          <add binding="wsHttpBinding" scheme="http"/>
        </protocolMapping>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
      </system.serviceModel>

    Then setup the http base address in http site binding module.
    Result.

    Feel free to let me know if there is anything I can help with.

    Best Regards

    Abraham


    Tuesday, July 2, 2019 3:35 AM
    Moderator