none
WCF Web Service - can't get an HTTP GET method RRS feed

  • Question

  • Summary: I've got an old web service that needs to be updated to include a HTTP GET-able method. However, no matter what I do, all the methods are only HTTP POST methods.

    -> Thank you in advance to anyone who takes the time to review this issue - I realize WCF may be ancient history and this issue may have been rehashed a billion different times elsewhere but I can't find any clear answers. <-

    I've created the simplest web services/SOAP example I can think of using Visual Studio 2017 Enterprise (version 15.9.12). This is the sample application that's created when I do File->New->Project-> Visual C#-> WCF -> WCF Service Application (using .Net Framework 4.6.1).

    I'm admittedly no MS wizard, so forgive me my sins...

    Here's the IService1.cs interface file:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.ServiceModel.Web;
    using System.Text;
     
    namespace TestWcfServiceApp1
    {
        // 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]
            [WebInvoke(Method = "GET")]
            string GetDataWebInvokeGet(int value);
     
            [OperationContract]
            [WebGet]
            string GetDataWebGet(int value);
     
            [OperationContract]
            string GetDataNada(int value);
     
            [OperationContract]
            [WebInvoke(Method = "POST")]
            string GetDataWebInvokePost(int value);
     
            // TODO: Add your service operations here
        }
    }
    

    Here's the code Service1.svc.cs:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.ServiceModel.Web;
    using System.Text;
     
    namespace TestWcfServiceApp1
    {
        // 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 GetDataWebInvokeGet(int value)
            {
                return string.Format("You entered: {0}", value);
            }
     
            public string GetDataWebGet(int value)
            {
                return string.Format("You entered: {0}", value);
            }
     
            public string GetDataNada(int value)
            {
                return string.Format("You entered: {0}", value);
            }
     
            public string GetDataWebInvokePost(int value)
            {
                return string.Format("You entered: {0}", value);
            }
        }
    }
    

    Here's the web.config:

    <?xml version="1.0"?>
    <configuration>
     
      <appSettings>
        <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
      </appSettings>
      <system.web>
        <compilation debug="true" targetFramework="4.6.1" />
        <httpRuntime targetFramework="4.6.1"/>
      </system.web>
      <system.serviceModel>
        <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"/>
        <!--
            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"/>
      </system.webServer>
     
    </configuration>
    

    When I test this using WcfTestClient, all the methods are called via HTTP POST, no matter how I "decorate" the interface methods. It feels like there is some larger configuration issue I just don't understand. I tried all the permutations with WebInvoke/WebGet I could think of. Help?!

    Thank you, again, for any help anyone can provide.

    Andrew B

    For additional reference:

    Microsoft Visual Studio Enterprise 2017 
    Version 15.9.12
    VisualStudio.15.Release/15.9.12+28307.665
    Microsoft .NET Framework
    Version 4.7.03062

    Installed Version: Enterprise

    Visual C++ 2017   00369-60000-00001-AA837
    Microsoft Visual C++ 2017

    ASP.NET and Web Tools 2017   15.9.04012.0
    ASP.NET and Web Tools 2017

    ASP.NET Core Razor Language Services   15.8.31590
    Provides languages services for ASP.NET Core Razor.

    ASP.NET Web Frameworks and Tools 2017   5.2.61435.0
    For additional information, visit https://www.asp.net/

    Azure App Service Tools v3.0.0   15.9.03024.0
    Azure App Service Tools v3.0.0

    Azure Functions and Web Jobs Tools   15.9.03024.0
    Azure Functions and Web Jobs Tools

    C# Tools   2.10.0-beta2-63501-03+b9fb1610c87cccc8ceb74a770dba261a58e39c4a
    C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

    CollapseAndSync   7.0.16.0
    Information about my package

    Command Task Runner   1.2.41
    Adds support for command line batch files in Visual Studio 2015's Task Runner Explorer. Supports .cmd, .bat, .ps1 and .psm1 files.

    Common Azure Tools   1.10
    Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

    Cookiecutter   15.9.18254.1
    Provides tools for finding, instantiating and customizing templates in cookiecutter format.

    CreateUnitTestBoilerplateCommand Extension   1.0
    CreateUnitTestBoilerplateCommand Visual Studio Extension Detailed Info

    Entity Framework Core Power Tools   1.0
    Adds useful design-time EF Core DbContext features to the Visual Studio Solution Explorer context menu. 



    Extensibility Message Bus   1.1.49 (remotes/origin/d15-8@ee674f3)
    Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

    HotCommands Extension   1.0
    HotCommands Visual Stuido Extension Detailed Info

    JavaScript Language Service   2.0
    JavaScript Language Service

    JavaScript Project System   2.0
    JavaScript Project System

    JavaScript UWP Project System   2.0
    JavaScript UWP Project System

    Microsoft Azure Tools   2.9
    Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.20417.1

    Microsoft Continuous Delivery Tools for Visual Studio   0.4
    Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

    Microsoft JVM Debugger   1.0
    Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

    Microsoft Library Manager   1.0
    Install client-side libraries easily to any web project

    Microsoft MI-Based Debugger   1.0
    Provides support for connecting Visual Studio to MI compatible debuggers

    Microsoft Visual C++ Wizards   1.0
    Microsoft Visual C++ Wizards

    Microsoft Visual Studio Tools for Containers   1.1
    Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

    Microsoft Visual Studio VC Package   1.0
    Microsoft Visual Studio VC Package

    MLGen Package Extension   1.0
    MLGen Package Visual Studio Extension Detailed Info

    Mono Debugging for Visual Studio   4.13.12-pre (9bc9548)
    Support for debugging Mono processes with Visual Studio.

    NuGet Package Manager   4.6.0
    NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

    Productivity Power Tools 2017/2019   16.0
    Installs the individual extensions of Productivity Power Tools 2017/2019

    ProjectServicesPackage Extension   1.0
    ProjectServicesPackage Visual Studio Extension Detailed Info

    Python   15.9.18254.1
    Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.

    Python - Django support   15.9.18254.1
    Provides templates and integration for the Django web framework.

    Python - IronPython support   15.9.18254.1
    Provides templates and integration for IronPython-based projects.

    Python - Profiling support   15.9.18254.1
    Profiling support for Python projects.

    ResourcePackage Extension   1.0
    ResourcePackage Visual Studio Extension Detailed Info

    ResourcePackage Extension   1.0
    ResourcePackage Visual Studio Extension Detailed Info

    Rewrap Extension   1.0
    Rewrap Extension Detailed Info

    SlowCheetah - XML config transforms   1.0
    This package enables you to transform your app.config or any other XML file based on the build configuration. It also adds additional tooling to help you create XML transforms.

    Snapshot Debugging Extension   1.0
    Snapshot Debugging Visual Studio Extension Detailed Info

    SQL Server Data Tools   15.1.61903.01040
    Microsoft SQL Server Data Tools

    SQLite & SQL Server Compact Toolbox   4.7
    SQLite & SQL Server Compact Toolbox adds scripting, import, export, rename, query execution and much more to SQL Server Compact & SQLite Data Connections.

    StylerPackage Extension   1.0
    StylerPackage Visual Stuido Extension Detailed Info

    TypeScript Tools   15.9.30410.2001
    TypeScript Tools for Microsoft Visual Studio

    Visual Basic Tools   2.10.0-beta2-63501-03+b9fb1610c87cccc8ceb74a770dba261a58e39c4a
    Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

    Visual F# Tools 10.2 for F# 4.5   15.8.0.0.  Commit Hash: 6e26c5bacc8c4201e962f5bdde0a177f82f88691.
    Microsoft Visual F# Tools 10.2 for F# 4.5

    Visual Studio Code Debug Adapter Host Package   1.0
    Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

    Visual Studio Spell Check Everywhere   VSSpellCheckEverywhere
    An extension that enables spell checking within any Visual Studio file editor or tool window that uses WPF text boxes.
    https://GitHub.com/EWSoftware/VSSpellChecker

    Visual Studio Spell Checker   VSSpellChecker
    An editor extension that checks the spelling of comments, strings, and plain text as you type or interactively with tool windows.
    https://GitHub.com/EWSoftware/VSSpellChecker

    Visual Studio Tools for Apache Cordova   15.123.7408.1
    Visual Studio Tools for Apache Cordova

    Visual Studio Tools for Containers   1.0
    Visual Studio Tools for Containers

    Visual Studio Tools for Universal Windows Apps   15.0.28307.665
    The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.

    VisualStudio.Mac   1.0
    Mac Extension for Visual Studio

    VSPackage Extension   1.0
    VSPackage Visual Studio Extension Detailed Info

    Xamarin   4.12.3.83 (d15-9@23fa80172)
    Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

    Xamarin Designer   4.16.30 (e0af99a34)
    Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

    Xamarin Templates   1.1.128 (6f5ebb2)
    Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

    Xamarin.Android SDK   9.1.7.0 (HEAD/ba9da7a76)
    Xamarin.Android Reference Assemblies and MSBuild support.

    Xamarin.iOS and Xamarin.Mac SDK   12.4.0.64 (9c8d8e0)
    Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

    Thursday, October 31, 2019 10:33 PM