首页 新闻 赞助 找找看

找不到类型“TService.MyService”,它在 ServiceHost 指令中提供为 Service 特性值

1
悬赏园豆:80 [已解决问题] 解决于 2011-09-27 07:46

找不到类型“TService.MyService”,它在 ServiceHost 指令中提供为 Service 特性值,或在配置元素 system.serviceModel/serviceHostingEnvironment/serviceActivations 中提供。

配置一个WCF,配置文件如下:

<system.serviceModel>    

     <behaviors>

      <serviceBehaviors>  

       <behavior name="HttpGet">      

     <serviceMetadata httpGetEnabled="true"/>     

    </behavior>

      </serviceBehaviors>   

  </behaviors>    

 <services>      

<service name="Service.MyService" behaviorConfiguration="HttpGet">      

   <endpoint binding="basicHttpBinding" contract="Contract.IMyContract"></endpoint>       </service>    

 </services>  

</system.serviceModel>

用IIS访问会报错:http://localhost/Testweb/MyService.svc

找不到类型“Service.MyService”,它在 ServiceHost 指令中提供为 Service 特性值,或在配置元素 system.serviceModel/serviceHostingEnvironment/serviceActivations 中提供。

但在用VS调试的可以,http://localhost:51583/MyServicea.svc

不知道是什么原因,我是直接把Testweb做虚拟目录的。能访问站点的网页。

 

 

小角的主页 小角 | 初学一级 | 园豆:72
提问于:2011-09-24 12:14
< >
分享
最佳答案
-1

IIS中访问的是MyService.svc,VS中访问是的MyServicea.svc。

检查一下MyService.svc的代码。

收获园豆:80
dudu | 高人七级 |园豆:31075 | 2011-09-24 17:23

是我疏忽,粘贴错了。

MyServicea.svc是我用来测试

<serviceHostingEnvironment>  

   <serviceActivations>       

  <add relativeAddress="MyServicea.svc" service="Service.MyService"></add>             </serviceActivations>   

  </serviceHostingEnvironment>

的代码。

我的全部代码结构如下:

IMyContract.cs
 1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.ServiceModel;
6
7 namespace Contract
8 {
9 [ServiceContract(Namespace="MyNamespace")]
10 public interface IMyContract
11 {
12 [OperationContract]
13 string MyMethod(string text);
14 }
15 }
IMyOtherContract
 1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.ServiceModel;
6
7 namespace Contract
8 {
9 [ServiceContract(Namespace = "MyNamespace")]
10 public interface IMyOtherContract
11 {
12 [OperationContract]
13 string MyOtherMethod();
14 }
15 }
MyService
 1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using Contract;
6
7 namespace Service
8 {
9 public class MyService: IMyContract,IMyOtherContract
10 {
11 public string MyMethod(string text)
12 {
13 return "Hello WCF" + text;
14 }
15
16 public string MyOtherMethod()
17 {
18 throw new NotImplementedException();
19 }
20 }
21
22
23 }
Web.config
 1 <?xml version="1.0"?>
2
3 <!--
4 有关如何配置 ASP.NET 应用程序的详细信息,请访问
5 http://go.microsoft.com/fwlink/?LinkId=169433
6 -->
7
8 <configuration>
9 <connectionStrings>
10 <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
11 </connectionStrings>
12
13 <system.web>
14 <compilation debug="true" targetFramework="4.0" />
15
16 <authentication mode="Forms">
17 <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
18 </authentication>
19
20 <membership>
21 <providers>
22 <clear />
23 <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
24 </providers>
25 </membership>
26
27 <profile>
28 <providers>
29 <clear />
30 <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
31 </providers>
32 </profile>
33
34 <roleManager enabled="false">
35 <providers>
36 <clear />
37 <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
38 <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
39 </providers>
40 </roleManager>
41
42 </system.web>
43
44 <system.webServer>
45 <modules runAllManagedModulesForAllRequests="true" />
46 </system.webServer>
47
48 <system.serviceModel>
49 <!--<serviceHostingEnvironment>
50 <serviceActivations>
51 <add relativeAddress="MyService.svc" service="Service.MyService"></add>
52 </serviceActivations>
53 </serviceHostingEnvironment>-->
54 <behaviors>
55 <serviceBehaviors>
56 <behavior name="HttpGet">
57 <serviceMetadata httpGetEnabled="true"/>
58 </behavior>
59 </serviceBehaviors>
60 </behaviors>
61 <services>
62 <service name="Service.MyService" behaviorConfiguration="HttpGet">
63 <endpoint binding="basicHttpBinding" contract="Contract.IMyContract"></endpoint>
64 </service>
65 </services>
66 </system.serviceModel>
67
68 </configuration>
MyService.svc
1 <%@ ServiceHost Language="C#" Service="Service.MyService" %>

 

小弟初学WCF,希望支持一下,不胜感激。




 

 

MyService
 1 using System;  2 using System.Collections.Generic;  3 using System.Linq;  4 using System.Text;  5 using System.ServiceModel;  6   7 namespace Contract  8 {  9     [ServiceContract(Namespace = "MyNamespace")] 10     public interface IMyOtherContract 11     { 12         [OperationContract] 13         string MyOtherMethod(); 14     } 15 }
小角 | 园豆:72 (初学一级) | 2011-09-25 20:35

现在确定了,是IIS的问题,不是代码的问题。

小角 | 园豆:72 (初学一级) | 2011-09-25 22:27

 把IIS的虚拟目录转换为应用程序就行了。

小角 | 园豆:72 (初学一级) | 2011-09-27 07:45
其他回答(2)
0

跟你一模一样的问题,解决方案无效,求解q174216500

潜心求教 | 园豆:204 (菜鸟二级) | 2012-08-22 11:08

加跨域访问文件策略两个文件到项目下面就可以了。具体谷歌一下

支持(0) 反对(0) daixunry | 园豆:200 (初学一级) | 2012-11-02 10:16
0

IIS7和IIS6不同,将添加虚拟目录改成添加运用程序就可以了

浪子小清 | 园豆:202 (菜鸟二级) | 2013-11-19 17:14
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册