none
Getting an INCORRECT SERVICE NAME in the autogenerated code for WCF RRS feed

  • Question

  • I am trying to call a WCF service through jQuery.Ajax().  While doing so,  when I Add a WCF-Service (Ajax- enabled) to my project, the web.config changes.

    But the problem is with the auto generated service name. Suppose if my

    Namespace = Demo

    Service Name = EmployeeService

    then the following name gets generated

    <service name="Demo.EmployeeService">

            <endpoint address=" Demo.EmployeeService"     

                      behaviorConfiguration="Demo.EmployeeServiceAspNetAjaxBehavior"

                      binding="webHttpBinding"

                      contract="Demo.EmployeeService" />

    </service>

    TO MY SURPRISE, the auto generated service name  is not accepted as a valid service name by the compiler. service name="Demo.EmployeeService" is underlined and so is contract.

    This being the case, I am not able to proceed for calling the service in the client side.

    Any help! 

    Wednesday, June 22, 2016 7:57 AM

Answers

  • Hi Ganesh,

    >> TO MY SURPRISE, the auto generated service name  is not accepted as a valid service name by the compiler.  service name="Demo.EmployeeService" is underlined and so is contract.

    Demo.EmployeeService is correct. We could create wcf by using an interface and a class. WCF-Service (Ajax- enabled) use a class to create wcf contract. I made a test with this in MVC and webForm project, I could get this warning in WebForm Project, but this is a warning, and I think we could ignore it. And I assume this is related with project template.

    >> This being the case, I am not able to proceed for calling the service in the client side.

    How did you call this service in client side? Did you get any error? Do you call service through jQuery.Ajax()? If so, you need to add “[WebGet]” in the OperationContract.

    Here is a simple demo:

    //web.config
    
          <service name="WebApplication1.Service2">
    
            <endpoint address="" behaviorConfiguration="WebApplication1.Service2AspNetAjaxBehavior"
    
              binding="webHttpBinding" contract="WebApplication1.Service2" />
    
          </service>
    
    //contract
    
    namespace WebApplication1
    
    {
    
        [ServiceContract(Namespace = "")]
    
        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    
        public class Service2
    
        {  
    
            // Add more operations here and mark them with [OperationContract]
    
            [OperationContract]
    
           [WebGet]
    
            public string Test()
    
            {
    
                return "Test";
    
            }
    
        }
    
    }
    
    //jQuery.Ajax request
    
    function test() {
    
                $.ajax({
    
                    url: "http://localhost:28482/Service2.svc/Test",
    
                    type:"get"
    
                }).success(function (data) {
    
                    console.log(data);
    
                })
    
            }

    You could refer the link below for more information about calling WCF service using jQuery.Ajax.

    #Calling WCF Services using jQuery

    http://www.codeproject.com/Articles/132809/Calling-WCF-Services-using-jQuery 

    Best Regards,

    Tony


    Help each other

    Friday, June 24, 2016 5:20 AM