我一直在尝试按照此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;
}
}
}
答案 0 :(得分:7)
嗯,好像我有这个工作了。我仍然无法在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文件,如下所示(即,在service元素中添加behavior部分和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://test.com.cws1.my-hosting-panel.com/IISHostedCalc/service.svc?wsdl的教程的步骤5c中将svcutil指向http://msdn.microsoft.com/en-us/library/ms733133.aspx来创建客户端代理。但是,当我运行客户端时,我得到了“调用者未通过服务进行身份验证”错误。对此的解决方案是最简单的:只需将binding =“wsHttpBinding”更改为服务的web.config中的binding =“basicHttpBinding”和客户端的web.config(或者在更改服务的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>
答案 1 :(得分:4)
要创建新应用程序,请右键单击“默认网站”节点。从上下文菜单中选择Add Application。
答案 2 :(得分:1)
我遇到了同样的错误,对我来说,问题只是我在服务器上缺少了要编译的服务所需的程序集。
这里描述的所有内容对我来说都没有必要。
要了解您的错误,可以尝试将service.svc和service.svc.cs文件移动到App_Code目录。这样,您将收到与您遇到的真实错误更相关的错误消息。
就我而言,由于忘记部署某些程序集而丢失了名称空间。我上传了丢失的程序集,正确运行服务然后移回了他们所属的服务文件。
答案 3 :(得分:1)
我有这个问题。
分辨率
...工作