无法在web.config中为WCF Web服务设置服务名称属性

时间:2014-02-12 15:47:25

标签: c# wcf

我有一个我编写的WCF Web服务工作正常,然后我从另一个应用程序复制了Web服务的内容并创建了一个新的WCF文件,该文件在web.config中创建了一个新的,但name属性表明命名空间不能找到。

以下是我的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";

这是我的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>

基本上name="Testing.ws.mainGrid.Test"无效,无法找到它。

我不确定我做错了什么,但我花了很多时间在这上面!第一个工作正常,但第二个有问题。

实际错误是:

  'name'属性无效 - 值Testing.ws.mainGrid.Test根据其数据类型'serviceNameType'无效 - 枚举约束失败

如果让intellisense完成其工作,那么它会显示第一个Web服务,但不会显示我的新服务!

2 个答案:

答案 0 :(得分:9)

我认为你的第二项服务应该如下。请注意合同名称的更改:

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

在指向命名空间之前,而不是类类型。

答案 1 :(得分:0)

虽然我们遇到了同样的问题,但由于我们的开发环境对某些服务使用了Windows身份验证,而我们通过web.config特别禁用了它,因此我们的修复略有不同。

需要注释掉/删除web.config的以下部分

<system.webServer>
    <!--<security>
           <authentication>
               <windowsAuthentication enabled="false" />
           </authentication>
        </security>-->
</system.webServer>

这需要取消评论,因为出版到生产是唯一的事情。

相关问题