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

我一直在试图按照这个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中创建一个虚拟目录(IISHostedCalc),它指向IISHostedCalcService.当我导航到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;
        }
    }
}
嗯,看来我有这个工作.我仍然找不到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>

最后,我可以在http://msdn.microsoft.com/en-us/library/ms733133.aspx的教程的第5c步中将svcutil指向http://test.com.cws1.my-hosting-panel.com/IISHostedCalc/service.svc?wsdl来创建客户端代理.但是,当我运行客户端时,我得到一个“呼叫者未被服务认证”的错误.解决方案是最简单的:只需将binding binding =“wsHttpBinding”更改为服务的web.config和客户端的web.config中的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>
翻译自:https://stackoverflow.com/questions/2739465/deploying-wcf-tutorial-app-on-iis7-the-type-could-not-be-found

转载注明原文:在IIS7上部署WCF教程应用程序:“找不到类型”