我一直在尝试按照这个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.csservice.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;
}
}
}发布于 2010-04-30 10:27:50
好吧,看起来我把这个弄好了。我仍然无法在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的地址。
这个集合中的每个方案最多只能有一个地址。“错误的解决方案是将以下内容添加到system.serviceModel下的web.config文件中:
<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文件,如下所示(即,添加behaviors部分,并在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中,我在http://msdn.microsoft.com/en-us/library/ms733133.aspx将svcutil指向http://test.com.cws1.my-hosting-panel.com/IISHostedCalc/service.svc?wsdl,从而创建了客户端代理。然而,当我运行客户端时,我得到了一个“调用者没有被服务验证”的错误。解决这个问题的方法是最简单的:只需在服务的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>发布于 2010-08-26 04:53:27
为了创建一个新的应用程序,右击默认的Web站点节点。从上下文菜单中选择添加应用程序。
发布于 2011-07-22 10:15:26
我也犯了同样的错误,对我来说,问题只是我缺少服务器上的程序集,而这些程序集是服务编译所需的。
这里描述的所有内容对我来说都不是必要的。
要找出错误所在,可以尝试将service.svc和service.svc.cs文件移动到App_Code目录。这样,您将获得与实际错误更好地相关的错误消息。
在我的例子中,因为忘记部署一些程序集而丢失的命名空间。我上传了丢失的程序集,正确地运行了服务,然后将服务文件移回了它们所属的位置。
https://stackoverflow.com/questions/2739465
复制相似问题