我一直在尝试按照本教程将 WCF 示例部署到 IIS 。我无法让它工作。这是一个托管站点,但我确实拥有对服务器的 IIS 管理器访问权限。但是,在本教程的第 2 步中,我无法“创建物理上位于此应用程序目录中的新 IIS 应用程序”。我似乎找不到菜单项、上下文菜单项或什么不创建新应用程序。我一直在疯狂地右键单击,但仍然无法弄清楚如何创建一个新应用程序。我想这可能是根本问题,但我尝试了其他一些事情(如下所述),以防万一这实际上不是问题。这是我在 IIS 管理器中看到的图片,以防我的话不公平:
此处没有添加应用程序 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.
有趣的是,如果我单击查看应用程序,虚拟目录似乎是一个应用程序(见下图)......尽管根据上面的错误消息,它不起作用。
这是一个应用程序还是不是?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;
}
}
}