Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot set service name attribute in web.config for WCF web service

Tags:

c#

wcf

I have a WCF web service I wrote which works fine, I then copied the contents of the web service from another application and created a new WCF file which created a new in web.config but the name attribute says the namespace cannot be found.

Here is an example of the first few lines of my WCF:

namespace Testing.ws.mainGrid
{
    [WebService(Namespace = "")]
    [ScriptService]
    [ToolboxItem(false)]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class Test : WebService
    {
        [ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
        [WebMethod]
        public void GetRecords()
        {
            ((NameValueCollection)new WebClient().Headers).Add("accept", "text/xml");
            string str1 = "1";
            string str2 = "1";
            string str3 = "1";

Here is my web.config:

  <system.serviceModel>
        <services>
            <service name="Testing.ws.getStaffTree">
                <endpoint address="" behaviorConfiguration="Testing.ws.getStaffTreeAspNetAjaxBehavior"
                    binding="webHttpBinding" contract="Testing.ws.getStaffTree" />
            </service>
            <service name="Testing.ws.mainGrid.Test">
                <endpoint address="" behaviorConfiguration="Testing.ws.mainGridAspNetAjaxBehavior"
                    binding="webHttpBinding" contract="Testing.ws.mainGrid" />
            </service>
        </services>

Basically name="Testing.ws.mainGrid.Test" does not work and it cannot find it.

I'm not sure what i'm doing wrong but i've spent ages on this! This first works fine but its the second one with the issue.

The actual error is:

the 'name' attribute is invalid - The value Testing.ws.mainGrid.Test is invalid according to its datatype 'serviceNameType' - The enumeration constraint failed

If you let intellisense do its work then it displays the first web service but not my new one!

like image 352
realtek Avatar asked Feb 12 '14 15:02

realtek


1 Answers

Your second service should be as follows I think. Note the change in contract name:

<service name="Testing.ws.mainGrid.Test">
    <endpoint address="" behaviorConfiguration="Testing.ws.mainGridAspNetAjaxBehavior"
        binding="webHttpBinding" contract="Testing.ws.mainGrid.Test" />
</service>

Before it was pointing to the namespace, not the class type.

like image 167
Jon Barker Avatar answered Sep 27 '22 19:09

Jon Barker