2014-02-12 52 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> 

這需要取消註釋出版生產的以下部分是唯一的事情。