locked
Web Config syntax errors RRS feed

  • Question

  • User1453549677 posted

    I am getting the following errors in syntax... can you help? Using VS 2015 and NET Framework 4.5

    ++++++++++++++++++ web.config file ++++++++++++++++++++++++++++

    <?xml version="1.0"?>
    <configuration>

    <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
    </appSettings>
    <system.web>
    <compilation debug="true" targetFramework="4.5"/>
    <httpRuntime targetFramework="4.5"/>
    <httpModules>
    <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
    </httpModules>
    </system.web>
    <system.serviceModel>
    <services>
    <service name="WcfRestBased.Service1"

    ++++++++++++ error here... The 'behaviorConfiguration' attribute is invalid. The value 'myService1Behavior' is invalid according to its datatype
    'serviceBehaviorConfigurationType' - the Enumeration constraint failed. +++++++++++++++++++++

    behaviorConfiguration="myService1Behavior">

    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    <endpoint name="webHttpBinding"

    address=""

    binding="webHttpBinding"

    contract="WcfRestBased.IService1"

    ++++++++++++ and error here... The 'behaviorConfiguration' attribute is invalid. The value 'webHttp' is invalid according to its datatype
    'endpointBehaviorConfigurationType' - the Enumeration constraint failed. +++++++++++++++++++++

    behaviorConfiguration="webHttp"

    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    >
    </endpoint>
    <endpoint name="mexHttpBinding"

    address="mex"

    binding="mexHttpBinding"

    contract="IMetadataExchange"

    />
    </service>
    </services>
    <behaviors>
    <serviceBehaviors>
    <behavior>
    <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
    <serviceMetadata httpGetEnabled="true" 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>
    <protocolMapping>
    <add binding="basicHttpsBinding" scheme="https"/>
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
    </system.serviceModel>
    <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
    <remove name="ApplicationInsightsWebTracking"/>
    <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
    preCondition="managedHandler"/>
    </modules>
    <!--
    To browse web app root directory during debugging, set the value below to true.
    Set to false before deployment to avoid disclosing web app folder information.
    -->
    <directoryBrowse enabled="true"/>
    <validation validateIntegratedModeConfiguration="false"/>
    </system.webServer>

    </configuration>

    ++++++++++++++++++++++++++++++++++++ IService1.cs +++++++++++++++++++++++++++++++++++

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

    namespace WcfRestBased
    {
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    [ServiceContract]
    public interface IService1
    {

    [OperationContract(Name = "PostSampleMethod")]
    [WebInvoke(Method = "POST",
    UriTemplate = "PostSampleMethod/New")]
    string PostSampleMethod(Stream data);

    [OperationContract(Name = "GetSampleMethod")]
    [WebGet(UriTemplate = "GetSampleMethod/inputStr/{name}")]
    string GetSampleMethod(string name);
    // TODO: Add your service operations here
    }


    // Use a data contract as illustrated in the sample below to add composite types to service operations.
    [DataContract]
    public class CompositeType
    {
    bool boolValue = true;
    string stringValue = "Hello ";

    [DataMember]
    public bool BoolValue
    {
    get { return boolValue; }
    set { boolValue = value; }
    }

    [DataMember]
    public string StringValue
    {
    get { return stringValue; }
    set { stringValue = value; }
    }
    }
    }

    +++++++++++++++++++++++++++++++ Service1.svc.cs ++++++++++++++++++++++++++++++++

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

    namespace WcfRestBased
    {
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
    public class Service1 : IService1
    {
    public string PostSampleMethod(Stream data)
    {
    // convert Stream Data to StreamReader
    StreamReader reader = new StreamReader(data);
    // Read StreamReader data as string
    string xmlString = reader.ReadToEnd();
    string returnValue = xmlString;
    // return the XMLString data
    return returnValue;
    }
    public string GetSampleMethod(string strUserName)
    {
    StringBuilder strReturnValue = new StringBuilder();
    // return username prefixed as shown below
    strReturnValue.Append(string.Format
    ("You have entered userName as {0}", strUserName));
    return strReturnValue.ToString();
    }
    }

    Thursday, March 1, 2018 7:13 PM

All replies

  • User1168443798 posted

    Hi drl,

    What behaviorConfiguration do you want to use for the service and endpoint? You need to create the required configuration like below:

      <system.serviceModel>
        <services>
          <service name="WcfRestBased.Service1"  behaviorConfiguration="myService1Behavior">
            <endpoint name="webHttpBinding"   address=""  binding="webHttpBinding"  contract="WcfRestBased.IService1"   behaviorConfiguration="webHttp">
            </endpoint>
            <endpoint name="mexHttpBinding" address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="myService1Behavior">
              <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
              <serviceMetadata httpGetEnabled="true" 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>
          <endpointBehaviors>
            <behavior name="webHttp">
              <webHttp/>
            </behavior>
          </endpointBehaviors>
        </behaviors>
        <protocolMapping>
          <add binding="basicHttpsBinding" scheme="https"/>
        </protocolMapping>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
      </system.serviceModel>
    

    You could refer the link below for more information.

    # How to: Create a Basic WCF REST Service

    https://msdn.microsoft.com/en-us/library/bb412178(v=vs.90).aspx

    Best Regards,

    Edward

    Friday, March 2, 2018 1:50 AM