在IIS7上部署WCF教程应用程序:“无法找到类型” [英] Deploying WCF Tutorial App on IIS7: "The type could not be found"

查看:134
本文介绍了在IIS7上部署WCF教程应用程序:“无法找到类型”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've been trying to follow this tutorial for deploying a WCF sample to IIS . I can't get it to work. This is a hosted site, but I do have IIS Manager access to the server. However, in step 2 of the tutorial, I can't "create a new IIS application that is physically located in this application directory". I can't seem to find a menu item, context menu item, or what not to create a new application. I've been right-clicking everywhere like crazy and still can't figure out how to create a new app. I suppose that's probably the root issue, but I tried a few other things (described below) just in case that actually is not the issue. Here is a picture of what I see in IIS Manager, in case my words don't do it justice:

这里没有添加应用程序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 ,然后有一个不同的错误:

I also tried to create a virtual dir (IISHostedCalc) in dotnetpanel that points to IISHostedCalcService . When I navigate to http://test.com.cws1.my-hosting-panel.com/IISHostedCalc/Service.svc , then there is a different error:

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

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

Interestingly enough, if I click on View Applications, it seems like the virtual directory is an application (see image below)... although, as per the error message above, it doesn't work.

这是一个应用程序吗? http://www.freeimagehosting.net/uploads/f3230be046.png

根据教程,没有涉及编译;我刚刚删除了服务器上的文件,如下面的文件夹IISHostedCalcService:

As per the tutorial, there was no compiling involved; I just dropped the files on the server as follow inside the folder IISHostedCalcService:

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

service.svc包含:

service.svc contains:

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

(我尝试使用c#属性的引号,因为这看起来有点奇怪没有引号,但它没有区别)

(I tried with quotes around the c# attribute, as this looks a little strange without quotes, but it made no difference)

Web.config包含:

Web.config contains:

<?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包含:

Service.cs contains:

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管理器中找到创建应用程序项。那部分是令人沮丧的,但我很高兴它似乎仍在工作。

Well, it seems I got this to work. I still can't find the "Create Application" item in IIS Manager. That part is kind of frustrating, but I'm glad it appears to be working anyway.

我在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

I had create the physical directory IISHostedCalcService under wwwroot. That was creating some confusion; it meant that http://test.com.cws1.my-hosting-panel.com/IISHostedCalcService/Service.svc was almost working, but it shouldn't. I moved IISHostedCalcService outside wwwroot and now the only place to access the service is 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下:

Then, accessing http://test.com.cws1.my-hosting-panel.com/IISHostedCalc/Service.svc was throwing that "This collection already contains an address with scheme http.
There can be at most one address per scheme in this collection." error. It turns out the solution to that is to add the following to the web.config file, right under 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):

After that I got a new error when ccessing http://test.com.cws1.my-hosting-panel.com/IISHostedCalc/Service.svc : "The contract name IMetadataExchange could not be found in the list of contracts implemented by the service CalculatorService". It turns out the solution to that is to modify the web.config file as follows (i.e., add the behaviors section, and behaviorConfiguration="SimpleServiceBehavior" in the service element):

<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 http://的教程的步骤5c中msdn.microsoft.com/en-us/library/ms733133.aspx 。但是,当我运行客户端时,我得到了调用者没有通过服务进行身份验证错误。对此的解决方案是最简单的:只需将binding =wsHttpBinding更改为服务的web.config中的binding =basicHttpBinding和客户端的web.config(或者在更改服务的web.config后重新运行svcutil)。

Finally, I was able to create client proxies by pointing svcutil at http://test.com.cws1.my-hosting-panel.com/IISHostedCalc/service.svc?wsdl in step 5c of the tutorial at http://msdn.microsoft.com/en-us/library/ms733133.aspx . However, when I ran the client, I got a "The caller was not authenticated by the service" error. The solution to this was the simplest: just change binding="wsHttpBinding" to binding="basicHttpBinding" in the service's web.config and the client's web.config (or re-run svcutil after changing the service's web.config).

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

The web.config ended up looking like this:

<?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>

这篇关于在IIS7上部署WCF教程应用程序:“无法找到类型”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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