WCF如何启用元数据? [英] WCF How to enable metadata?

查看:71
本文介绍了WCF如何启用元数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使svc文件在IIS下工作.在我的项目中,当我按F5键时,svc就可以正常工作了.所以我知道一切都很好,对吧?除了IIS.

I am trying to get my svc file working under IIS. In my project, when I press F5 I got the svc working. So I know everything is okay, right? Except for IIS.

我正在Windows XP Pro计算机上工作,并在IIS中添加了一个虚拟目录.

I am working on a Windows XP Pro machine and in IIS I've added a virtual directory.

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

Here's my code: IcarePlanActions (project: A)

namespace WcfServiceLibrary
{
    [ServiceContract]
    public interface ICarePlanActions
    {
        [OperationContract]
        List<string> GetAllClients();
    }
}

客户:(项目:A)

namespace WcfServiceLibrary
{
    public class Client : ICarePlanActions
    {
        public List<string> GetAllClients()
        {
            List<string> clients = new List<string>();
            clients.Add("Hendrik de Jong");
            clients.Add("Miep de Berg");
            clients.Add("Jaap Jongeneel");
            clients.Add("Joop Prakman");
            clients.Add("Pieter Schaakman");

            return clients;

        }
    }
}

Web.config(项目:B)

Web.config (project: B)

  <configuration>
    <system.serviceModel>
      <services>
        <service behaviorConfiguration="CarePlanService.Service1Behavior"
          name="WcfServiceLibrary.Client">
          <endpoint address="" binding="wsHttpBinding" contract="WcfServiceLibrary.ICarePlanActions">
            <identity>
              <dns value="localhost" />
            </identity>
          </endpoint>
          <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        </service>
      </services>
      <behaviors>
        <serviceBehaviors>
          <behavior name="CarePlanService.Service1Behavior">
            <!-- 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>
    </system.serviceModel>
  </configuration>

CarePlan.svc

CarePlan.svc

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

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

When I run this service (which is on IIS) with wfctestclient I get this error

错误:无法从中获取元数据 http://localhost/CarePlanService/CarePlan.svc 如果这是Windows(R)通信 您拥有的基础服务 访问权限,请检查您是否具有 在以下位置启用了元数据发布 指定的地址.

Error: Cannot obtain Metadata from http://localhost/CarePlanService/CarePlan.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address.

我在做什么错了?

解决方案

我没有使该服务在IIS下运行.首先,我手动创建一个虚拟目录,并指向svc所在的目录.这没用.我不知道为什么.

I didn't get the service working under IIS. First I manually create a virtual directory and pointed to the directiry where the svc is located. This didn't work. I don't know why.

然后我去Visual Studio并更改了服务器设置(在项目,属性,选项卡Web上单击鼠标右键,单击Use local IIS Web Server,然后单击Create Virtual Directory.这样做之后,它可以在IIS上使用上面的代码工作.

Then I went to Visual Studio and changed the server setting (Right mouse on the project, properties, tab Web, click Use local IIS Web Server and click Create Virtual Directory. When I did this, it worked under IIS with the code above.

推荐答案

解决方案

我没有使该服务在IIS下运行.首先,我手动创建一个虚拟目录,并指向svc所在的目录.这没用.我不知道为什么.

I didn't get the service working under IIS. First I manually create a virtual directory and pointed to the directiry where the svc is located. This didn't work. I don't know why.

然后,我进入Visual Studio并更改了服务器设置(在项目,属性,Web选项卡上单击鼠标右键,单击使用本地IIS Web服务器",然后单击创建虚拟目录".执行此操作时,它在IIS下使用代码工作)以上.

Then I went to Visual Studio and changed the server setting (Right mouse on the project, properties, tab Web, click Use local IIS Web Server and click Create Virtual Directory. When I did this, it worked under IIS with the code above.

这篇关于WCF如何启用元数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆