2012-04-10 13 views
0

我是一位嘗試使用WCF的新手。我試圖使用Android訪問WCF,我遇到了麻煩,根據我的研究json需要訪問WCF,所以我試圖將其更改爲json。WCF中關於serviceHostingEnvironment的未處理錯誤

我改變了接口的對象類型,並開始具有低於

The exception message is: The type 'AddItemService.Login', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found..] 

我的接口方法中所示的錯誤:

[OperationContract] 
     [WebInvoke(Method = "POST", UriTemplate = "Login", BodyStyle = WebMessageBodyStyle.WrappedRequest, 
      ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)] 
     [Description("Returns the Login User ID")] 
     int GetUserId(Login login); 

我的web.config:

<?xml version="1.0"?> 
<configuration> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 
    <services> 
     <service name="AddItemService.Login" 
       behaviorConfiguration="RESTBehavior"> 
     <endpoint address="" 
        binding="webHttpBinding" 
        contract="AddItemService.ILogin" 
        behaviorConfiguration="MyEndpointBehavior"/> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="RESTBehavior"> 
      <serviceMetadata httpGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
     </behavior> 
     </serviceBehaviors> 
     <endpointBehaviors> 
     <behavior name="MyEndpointBehavior"> 
      <webHttp helpEnabled="true"/> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
</configuration> 

我不知道爲什麼它不起作用。誰能幫幫我嗎?

+0

GetUserId操作的參數類型是「Login」,但服務類型也是「Login」,它們是不同名稱空間中的兩種不同類型嗎?如果沒有,那可能是你的問題 - 服務名稱是服務的實現,在你的情況下,無論實現AddItemService.ILogin – kmp 2012-04-10 09:35:30

回答

1

聽起來像WCF服務(實際標記文件,而不是代碼隱藏文件)的.svc文件中指定的服務類型引用了不存在的服務類類型。

如果右鍵單擊Visual Studio中的.svc文件並選擇「查看標記」,該文件中的ServiceHost指令的「Service」屬性需要包含實現WCF服務接口的類的名稱。聽起來目前它引用AddItemService.Login,它不存在。