gpt4 book ai didi

wcf - 在 IIS7 上部署 WCF 教程应用程序 : "The type could not be found"

转载 作者:行者123 更新时间:2023-12-04 00:59:32 25 4
gpt4 key购买 nike

我一直在努力关注这个 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;
}
}
}

最佳答案

好吧,看来我让这个工作了。我仍然无法在 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 实现的契约(Contract)列表中找不到契约(Contract)名称 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>

最后,我能够通过将 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>

关于wcf - 在 IIS7 上部署 WCF 教程应用程序 : "The type could not be found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2739465/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com