【发布时间】:2015-12-18 22:34:54
【问题描述】:
我是 WCF 服务的新手。我正在浏览一些教程并获得了一个简单的程序并尝试在 C# 中的 WCF 服务应用程序中执行。代码如下所示。
IService1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace WcfService1
{
[ServiceContract]
public interface IService1
{
int calculatedays(int day,int month,int year);
}
}
Service1.svc.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace WcfService1
{
public class Service1 : IService1
{
public int calculatedays(int day, int month, int year)
{
DateTime dt = new DateTime(year, month, day);
int datetodays = DateTime.Now.Subtract(dt).Days;
return datetodays;
}
}
}
web.config
<?xml version="1.0"?>
<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>
当我运行应用程序时,它给出的错误是
错误:无法从http://localhost:2049/Service1.svc 获取元数据 如果这是您使用的 Windows (R) Communication Foundation 服务 有访问权限,请检查您是否已在以下位置启用元数据发布 指定的地址。如需帮助启用元数据发布,请 请参阅 MSDN 文档 http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata交流 错误 URI:http://localhost:2049/Service1.svc 元数据包含 无法解析的引用: 'http://localhost:2049/Service1.svc'。服务器没有提供 有意义的回复;这可能是由于合同不匹配造成的,a 会话过早关闭或内部服务器错误
【问题讨论】:
-
您如何托管 WCF 服务,我们也可以看到该代码
-
您还没有将接口方法签名设置为也具有 OperationContract 属性...
标签: c# visual-studio-2010 wcf