Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF如何启用元数据?_C#_Wcf_Metadata - Fatal编程技术网

C# WCF如何启用元数据?

C# WCF如何启用元数据?,c#,wcf,metadata,C#,Wcf,Metadata,我正在尝试让我的svc文件在IIS下工作。在我的项目中,当我按下F5时,svc开始工作。所以我知道一切都很好,对吗?除了IIS 我在Windows XP Pro机器上工作,在IIS中我添加了一个虚拟目录 这是我的密码: IcarePlanActions(项目:A) 名称空间WcfServiceLibrary { [服务合同] 公共接口iCalReplacations { [经营合同] 列出getAllClient(); } } 客户:(项目:A) 名称空间WcfServiceLibrary {

我正在尝试让我的svc文件在IIS下工作。在我的项目中,当我按下F5时,svc开始工作。所以我知道一切都很好,对吗?除了IIS

我在Windows XP Pro机器上工作,在IIS中我添加了一个虚拟目录

这是我的密码: IcarePlanActions(项目:A)

名称空间WcfServiceLibrary
{
[服务合同]
公共接口iCalReplacations
{
[经营合同]
列出getAllClient();
}
}
客户:(项目:A)

名称空间WcfServiceLibrary
{
公共类客户端:iCalReplacations
{
公共列表GetAllClient()
{
列表客户端=新列表();
客户。添加(“Hendrik de Jong”);
客户。添加(“Miep de Berg”);
客户。添加(“Jaap Jongenel”);
客户。添加(“Joop Prakman”);
客户。添加(“Pieter Schaakman”);
返回客户;
}
}
}
Web.config(项目:B)


护理计划

<%@ ServiceHost Language="C#" Debug="true" Service="WcfServiceLibrary.Client" %>

当我使用wfctestclient运行此服务(在IIS上)时,我收到此错误

错误:无法从中获取元数据 如果这是Windows(R)通信 你的基础服务 访问,请检查您是否有 已在上启用元数据发布 指定的地址

我做错了什么

解决方案

我没有让服务在IIS下工作。首先,我手动创建一个虚拟目录,并指向svc所在的目录。这不管用。我不知道为什么


然后我转到VisualStudio并更改了服务器设置(在项目、属性、选项卡Web上单击鼠标右键,单击
使用本地IIS Web服务器
,然后单击
创建虚拟目录
。当我这样做时,它在IIS下使用上面的代码工作。

您引用数据协定作为服务的实现。这是无效的

[DataContract]
public class Client : ICarePlanActions
{

<service behaviorConfiguration="CarePlanService.Service1Behavior"
      name="WcfServiceLibrary.Client">
[DataContract]
公共类客户端:iCalReplacations
{
将此更改为引用服务的实现!服务的实现是什么样子的


也许您应该从客户端类中删除DataContract属性。此外,这不是您的“客户端”,而是服务的实现。

首先,删除客户端中的[DataContract]属性

然后,重新编译并确保虚拟目录的/bin目录中有WcfServiceLibrary.dll

您的配置应将此端点用于metadataexchange:

<endpoint address="mex" 
    binding="mexHttpBinding" 
    contract="IMetadataExchange"/>

解决方案

我没有让服务在IIS下工作。首先,我手动创建了一个虚拟目录,并指向svc所在的目录。这不起作用。我不知道为什么

然后我转到Visual Studio并更改了服务器设置(右键单击项目上的“属性”选项卡“Web”,单击“使用本地IIS Web服务器”,然后单击“创建虚拟目录”。执行此操作时,它在IIS下工作,代码如上所述

  • 运行
    “\%windir%\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe”-i

  • 删除虚拟目录并再次创建它


  • 只需在
    service.svc
    文件中检查服务名称

    <ServiceHost Language="C#" Debug="true" Service="SvcCalculator.**Calculator**"
               CodeBehind="**Calculator.svc.cs**" %>
    
    
    

    希望它能起作用。

    确保您的服务命名空间和服务类的名称与App.config文件相对应

     <system.serviceModel>
      <services>
       <service name="WcfCustomLibrary.Service1">
        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary/Service1/" />
          </baseAddresses>
        </host>
       </service>
      </services>
     </system.serviceModel>
    
    
    namespace WcfCustomLibrary
    {
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
    public class Service1 : IService1
    {
    
    
    命名空间WcfCustomLibrary
    {
    //注意:您可以使用“重构”菜单上的“重命名”命令同时更改代码和配置文件中的类名“Service1”。
    公共类服务1:IService1
    {
    
    Edited title-这与C#编程语言无关。我没有像这样使用WCF,但你应该将你的服务实现放在datacontract中吗?如果是这样的话,契约中没有定义datamember。我只是觉得很奇怪。但我从来没有在IIS中托管过…@Martijn:真傻的问题:当你试图使用WcfTestClient进行nect,网站启动了吗?如果您执行此处建议的更改(删除[DataContract],对mex端点使用“mexHttpBinding”),则获取元数据一点都不困难。但您必须执行“在浏览器中查看”首先在*.svc文件上启动内置web服务器,然后您可以使用WcfTestClient@Marc:我已按以下建议进行了更改。我希望在本地IIS上承载该服务。当我执行“在浏览器中查看”时该服务由Visual Studio托管,对吗?@Martijn:该服务由集成web服务器Cassini托管,是的-重点是:它需要“启动并运行”在您可以访问它之前。可以通过定义的IIS虚拟目录,也可以通过在Cassini中启动它。我已更改了文件,但仍然无法使其正常工作。我已使用这些更改修改了startpost。这对我有效,这意味着它可以在IIS服务器中工作,但不能在Visual Studio development server中工作。您知道为什么吗?
    <endpoint address="mex" 
        binding="mexHttpBinding" 
        contract="IMetadataExchange"/>
    
    <ServiceHost Language="C#" Debug="true" Service="SvcCalculator.**Calculator**"
               CodeBehind="**Calculator.svc.cs**" %>
    
     <system.serviceModel>
      <services>
       <service name="WcfCustomLibrary.Service1">
        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary/Service1/" />
          </baseAddresses>
        </host>
       </service>
      </services>
     </system.serviceModel>
    
    
    namespace WcfCustomLibrary
    {
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
    public class Service1 : IService1
    {