得到错误,同时运行服务
我已创建WCF服务,但同时运行我得到以下错误的服务: 错误:得到错误,同时运行服务
Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.
Error Details:
Warning: No code was generated.If you were trying to generate a client, this could be because the metadata documents did not contain any valid contracts or servicesor because all contracts/services were discovered to exist in /reference assemblies. Verify that you passed all the metadata documents to the tool.Warning: If you would like to generate data contracts from schemas make sure to use the /dataContractOnly option.
代码:
namespace WCFTest
{
[ServiceContract]
public class EmployeeDetails
{
[OperationContract]
public List<Employee> GetDetails()
{
List<Employee> emp = new List<Employee>()
{
new Employee(){Fname="AA",Lname="BB",EmpId=1,Desg="A"},
new Employee(){Fname="CC",Lname="DD",EmpId=1,Desg="B"},
new Employee(){Fname="EE",Lname="FF",EmpId=1,Desg="C"},
new Employee(){Fname="GG",Lname="HH",EmpId=1,Desg="D"},
new Employee(){Fname="II",Lname="JJ",EmpId=1,Desg="A"},
new Employee(){Fname="KK",Lname="LL",EmpId=1,Desg="B"}
};
return emp;
}
}
// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
[KnownType(typeof(Employee))]
public class Person
{
[DataMember]
public string Fname { get; set; }
[DataMember]
public string Lname { get; set; }
}
[DataContract]
public class Employee : Person
{
[DataMember]
public int EmpId { get; set; }
[DataMember]
public string Desg { get; set; }
}
}
namespace WCFTest
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class Service1
{
public List<Employee> GetData(int value)
{
EmployeeDetails ed = new EmployeeDetails();
return ed.GetDetails();
}
}
}
但是我能看到的元数据暴露在web.config中。
Web.config文件:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
任何线索我要去的地方错了吗?
编辑:我认为错误背后的原因是我正在使用一个类作为服务合同,现在当我将其更改为一个接口,事情按预期工作,不知道为什么我得到错误,如果我指定该类作为服务合同。
我没有在您的配置中看到任何<services>
节点 - 您根本没有配置服务 - 因此没有任何连接。
你需要扩展你的配置,包括这样的事情:
<configuration>
<system.serviceModel>
<services>
<service name="WCFTest.EmployeeDetails">
<endpoint name="Default"
address="/default"
binding="basicHttpBinding" bindingConfiguration=""
contract="WCFTest.EmployeeDetails" />
<endpoint kind="mexEndpoint" address="/mex" />
</service>
</services>
</system.serviceModel>
</configuration>
现在,你有一个服务和一个元数据端点的服务,现在你的WCF测试客户端应该能够找到的东西连接到....
我没有在您的web.config中看到任何节点.....另外:你是如何尝试从服务创建代理:在Visual Studio中添加服务引用或运行svcutil在命令行? –
2010-10-02 16:47:05
不,我不想创建任何代理,我所做的是 - 创建new-> project> WCF应用程序,然后添加此代码,并尝试运行WCF sln。 – Wondering 2010-10-02 16:51:06
默认的WCF应用程序以这种方式工作(我的意思是没有在C#或web.config中更改anu代码的缺省值) – Wondering 2010-10-02 16:52:01