【问题标题】:Deploying WCF Tutorial App on IIS7: "The type could not be found"在 IIS7 上部署 WCF 教程应用程序:“找不到类型”
【发布时间】:2011-02-13 22:21:19
【问题描述】:

我一直在尝试遵循 tutorial 将 WCF 示例部署到 IIS 。 我无法让它工作。这是一个托管站点,但我确实拥有对服务器的 IIS 管理器访问权限。但是,在本教程的第 2 步中,我无法“创建物理上位于此应用程序目录中的新 IIS 应用程序”。我似乎找不到菜单项、上下文菜单项或什么不创建新应用程序。我一直在疯狂地右键单击,但仍然无法弄清楚如何创建一个新应用程序。我想这可能是根本问题,但我尝试了其他一些事情(如下所述),以防万一这实际上不是问题。这是我在 IIS 管理器中看到的图片,以防我的话不公平:

No add Application Here http://www.freeimagehosting.net/uploads/d6edbaaf3c.png

这是在http://test.com.cws1.my-hosting-panel.com/IISHostedCalcService/Service.svc“部署”的。错误说:

    The type 'Microsoft.ServiceModel.Samples.CalculatorService', 
provided as the Service attribute value in the ServiceHost directive, 
or provided in the configuration element
 system.serviceModel/serviceHostingEnvironment/serviceActivations 
could not be found.

我还尝试在 dotnetpanel 中创建一个指向 IISHostedCalcService 的虚拟目录 (IISHostedCalc)。当我导航到 http://test.com.cws1.my-hosting-panel.com/IISHostedCalc/Service.svc 时,会出现不同的错误:

This collection already contains an address with scheme http.  
There can be at most one address per scheme in this collection.

有趣的是,如果我点击查看应用程序,虚拟目录似乎是一个应用程序(见下图)......尽管根据上面的错误消息,它不起作用。

Is this an app or not? http://www.freeimagehosting.net/uploads/f3230be046.png

根据教程,不涉及编译;我只是将文件放在服务器上的文件夹 IISHostedCalcService 中,如下所示:

service.svc
Web.config
<dir: App_Code>
   Service.cs

service.svc 包含:

<%@ServiceHost language=c# Debug="true" Service="Microsoft.ServiceModel.Samples.CalculatorService"%>

(我尝试在 c# 属性周围加上引号,因为没有引号看起来有点奇怪,但没有区别)

Web.config 包含:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="Microsoft.ServiceModel.Samples.CalculatorService">

        <!-- This endpoint is exposed at the base address provided by host:                                        http://localhost/servicemodelsamples/service.svc  -->
        <endpoint address=""
                  binding="wsHttpBinding"
                  contract="Microsoft.ServiceModel.Samples.ICalculator" />

        <!-- The mex endpoint is explosed at http://localhost/servicemodelsamples/service.svc/mex -->
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>
  <system.web>
    <customErrors mode="Off"/>
  </system.web>
</configuration>

Service.cs 包含:

using System;
using System.ServiceModel;

namespace Microsoft.ServiceModel.Samples
{

    [ServiceContract]
    public interface ICalculator
    {
        [OperationContract]
        double Add(double n1, double n2);
        [OperationContract]
        double Subtract(double n1, double n2);
        [OperationContract]
        double Multiply(double n1, double n2);
        [OperationContract]
        double Divide(double n1, double n2);
    }


    public class CalculatorService : ICalculator
    {
        public double Add(double n1, double n2)
        {
            return n1 + n2;
        }
        public double Subtract(double n1, double n2)
        {
            return n1 - n2;
        }
        public double Multiply(double n1, double n2)
        {
            return n1 * n2;
        }
        public double Divide(double n1, double n2)
        {
            return n1 / n2;
        }
    }
}

【问题讨论】:

    标签: wcf iis-7 iis-manager


    【解决方案1】:

    我遇到了这个问题。

    1. 我将发布的文件保存在 wwwroot 下
    2. 单击 .svc 文件上的浏览
    3. 这个抛出相同的异常

    分辨率

    1. 我为它创建了一个虚拟目录
    2. 尝试浏览 .svc 文件。

    工作中...

    【讨论】:

      【解决方案2】:

      我遇到了同样的错误,对我来说,问题只是我在服务器上缺少服务编译所需的程序集。

      这里描述的所有内容对我来说都是不必要的。

      要找出您的错误是什么,您可以尝试将您的 service.svc 和 service.svc.cs 文件移动到 App_Code 目录。这样,您将收到与您的实际错误更相关的错误消息。

      在我的例子中,因为我忘记部署一些程序集而丢失的命名空间。我上传了丢失的程序集,正确运行服务,然后将服务文件移回原来的位置。

      【讨论】:

      • 我也有这个问题。我需要在我引用的程序集之一上设置“复制本地”以将其包含在我的网站中。
      【解决方案3】:

      为了创建一个新的应用程序,右键单击默认网站节点。从上下文菜单中选择添加应用程序。

      【讨论】:

        【解决方案4】:

        好吧,看来我已经成功了。我仍然无法在 IIS 管理器中找到“创建应用程序”项。这部分有点令人沮丧,但我很高兴它似乎仍然有效。

        我在 wwwroot 下创建了物理目录 IISHostedCalcService。这造成了一些混乱。这意味着http://test.com.cws1.my-hosting-panel.com/IISHostedCalcService/Service.svc 几乎可以工作,但它不应该。我将 IISHostedCalcService 移到 wwwroot 之外,现在唯一可以访问该服务的地方是 http://test.com.cws1.my-hosting-panel.com/IISHostedCalc/Service.svc

        然后,访问http://test.com.cws1.my-hosting-panel.com/IISHostedCalc/Service.svc 会抛出“这个集合已经包含一个带有 http 方案的地址。
        此集合中每个方案最多只能有一个地址。”错误。事实证明,解决方案是将以下内容添加到 web.config 文件中,就在 system.serviceModel 下:

        <serviceHostingEnvironment>
          <baseAddressPrefixFilters>
            <add prefix="http://test.com.cws1.my-hosting-panel.com"/>
          </baseAddressPrefixFilters>
        </serviceHostingEnvironment>
        

        之后我在访问http://test.com.cws1.my-hosting-panel.com/IISHostedCalc/Service.svc 时遇到一个新错误:“在服务 CalculatorService 实现的合约列表中找不到合约名称 IMetadataExchange”。事实证明,解决方案是修改 web.config 文件如下(即,添加行为部分,并在服务元素中添加 behaviorConfiguration="SimpleServiceBehavior"):

        <configuration>
          <system.serviceModel>
            <serviceHostingEnvironment>
              <baseAddressPrefixFilters>
                <add prefix="http://test.com.cws1.my-hosting-panel.com"/>
              </baseAddressPrefixFilters>
            </serviceHostingEnvironment>
            <services>
              <service name="Microsoft.ServiceModel.Samples.CalculatorService" behaviorConfiguration="SimpleServiceBehavior">
              ...
              </service>
            </services>
            <behaviors>
              <serviceBehaviors>
                <behavior name="SimpleServiceBehavior">
                  <serviceMetadata httpGetEnabled="True" policyVersion="Policy15" />
                </behavior>
              </serviceBehaviors>
            </behaviors>
          </system.serviceModel>
          <system.web>
            <customErrors mode="Off"/>
          </system.web>
        </configuration>
        

        最后,我能够在教程的第 5c 步中将 svcutil 指向 http://test.com.cws1.my-hosting-panel.com/IISHostedCalc/service.svc?wsdl http://msdn.microsoft.com/en-us/library/ms733133.aspx 来创建客户端代理。但是,当我运行客户端时,出现“调用者未通过服务验证”错误。解决这个问题最简单:只需在服务的 web.config 和客户端的 web.config 中将 binding="wsHttpBinding" 更改为 binding="basicHttpBinding" (或在更改服务的 web.config 后重新运行 svcutil)。

        web.config 最终看起来像这样:

        <?xml version="1.0" encoding="utf-8" ?>
        <configuration>
          <system.serviceModel>
            <serviceHostingEnvironment>
              <baseAddressPrefixFilters>
                <add prefix="http://test.com.cws1.my-hosting-panel.com"/>
              </baseAddressPrefixFilters>
            </serviceHostingEnvironment>
            <services>
              <service name="Microsoft.ServiceModel.Samples.CalculatorService" behaviorConfiguration="SimpleServiceBehavior">
        
                <!-- This endpoint is exposed at the base address provided by host:                                        http://localhost/servicemodelsamples/service.svc  -->
                <endpoint address=""
                          binding="basicHttpBinding"
                          contract="Microsoft.ServiceModel.Samples.ICalculator" />
        
                <!-- The mex endpoint is explosed at http://localhost/servicemodelsamples/service.svc/mex -->            
                <endpoint address="mex"
                          binding="mexHttpBinding"
                          contract="IMetadataExchange" />
        
              </service>
            </services>
            <behaviors>
              <serviceBehaviors>
                <behavior name="SimpleServiceBehavior">
                  <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                  <serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />
                  <!-- 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>
          <system.web>
            <customErrors mode="Off"/>
          </system.web>
        </configuration>
        

        【讨论】:

        • 请先尝试添加应用程序(jdc 的回答),然后再执行所有这些操作...这对我来说更容易并且对我有用!
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-03
        • 1970-01-01
        • 2018-02-10
        • 1970-01-01
        相关资源
        最近更新 更多