2014-02-12 54 views
5

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

这里是我的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"不工作,它不能找到它。

我不知道我在做什么错,但我已经在这个上花了很多年了!这第一个正常工作,但它是第二个问题。

实际的错误是:

的“名称”属性无效 - 值Testing.ws.mainGrid.Test根据其数据类型“serviceNameType”是无效的 - 枚举约束失败

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

+1

看起来你正在将ASMX(你的类实现)与WCF(你的web.config)混合使用。 –

+0

另外,您正尝试使用'webHttpBinding'作为SOAP服务 - 'webHttpBinding'用于REST。 – Tim

回答

9

你的第二个服务应该如下我想。请注意合同名称中的更改:

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

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

0

尽管我们遇到了同样的问题,但由于我们的开发环境在某些服务中使用Windows身份验证,同时通过web.config专门禁用了它,因此我们的修补程序稍有不同。

所需注释掉/删除的web.config

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

这需要取消注释出版生产的以下部分是唯一的事情。