代码之家  ›  专栏  ›  技术社区  ›  Jimmy

在IIS7上部署WCF教程应用程序:“找不到类型”

  •  12
  • Jimmy  · 技术社区  · 15 年前

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

    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;
            }
        }
    }
    
    4 回复  |  直到 13 年前
        1
  •  7
  •   Jimmy    15 年前

    好吧,看来我有办法了。我仍然找不到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 :“在服务计算器服务实现的协定列表中找不到协定名称imetadataexchange。”解决方案是按如下方式修改web.config文件(即添加behaviors部分,并在service元素中添加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>
    

    最后,我可以通过将svcutil指向 http://test.com.cws1.my-hosting-panel.com/IISHostedCalc/service.svc?wsdl 在教程的步骤5c中 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>
    
        2
  •  4
  •   jdc    14 年前

    要创建新应用程序,请右键单击默认网站节点。从上下文菜单中选择“添加应用程序”。

        3
  •  1
  •   Jonx    14 年前

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

    这里所描述的一切对我来说都是不必要的。

    要找出错误所在,可以尝试将service.svc和service.svc.cs文件移动到app_code目录。这样,您将得到一个错误消息更好地相关的真实错误你有。

    在我的例子中,由于忘记部署一些程序集而丢失的命名空间。我上载了丢失的程序集,正确运行服务,然后将服务文件移回它们所属的位置。

        4
  •  1
  •   sjngm quinti    13 年前

    我有这个问题。

    1. 我把发布的文件保存在wwwroot下
    2. 单击浏览.svc文件
    3. 引发相同的异常

    分辨率

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

    工作。。。

    推荐文章