在 IIS7 上部署 WCF 教程应用程序:“找不到类型”
我一直在尝试按照此教程将 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;
}
}
}
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:
No add Application Here http://www.freeimagehosting.net/uploads/d6edbaaf3c.png
This is "deployed" at http://test.com.cws1.my-hosting-panel.com/IISHostedCalcService/Service.svc . The error says:
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.
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.
Is this an app or not? http://www.freeimagehosting.net/uploads/f3230be046.png
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 contains:
<%@ServiceHost language=c# Debug="true" Service="Microsoft.ServiceModel.Samples.CalculatorService"%>
(I tried with quotes around the c# attribute, as this looks a little strange without quotes, but it made no difference)
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 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;
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
嗯,看来我已经成功了。我在 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 的正下方:
之后,我在访问时遇到了新错误http://test.com.cws1.my-hosting-panel .com/IISHostedCalc/Service.svc :“在服务 CalculatorService 实现的合约列表中找不到合约名称 IMetadataExchange”,解决方案是将 web.config 文件修改为如下(即,在服务元素中添加行为部分和behaviorConfiguration =“SimpleServiceBehavior”):
最后,我能够通过将svcutil指向http://test.com.cws1.my-hosting-panel.com/IISHostedCalc/service.svc?wsdl在 http://msdn.microsoft.com/en- 教程的步骤 5c 中us/library/ms733133.aspx 。但是,当我运行客户端时,出现“调用者未经服务验证”错误。解决方案是最简单的:只需将服务的 web.config 和客户端的 web.config 中的 binding="wsHttpBinding" 更改为 binding="basicHttpBinding"(或在更改服务的 web.config 后重新运行 svcutil)。
web.config 最终看起来像这样:
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.
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 .
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:
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):
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).
The web.config ended up looking like this:
为了创建新的应用程序,请右键单击“默认网站”节点。从上下文菜单中选择添加应用程序。
In order to create a new application, right-click on the Default Web Site node. From the context menu select Add Application.
我遇到了同样的错误,对我来说问题只是我在服务器上缺少服务编译所需的程序集。
这里描述的所有内容对我来说都是不必要的。
要找出错误所在,您可以尝试将 service.svc 和 service.svc.cs 文件移动到 App_Code 目录。这样,您将获得与实际错误更相关的错误消息。
就我而言,由于我忘记部署一些程序集,因此缺少命名空间。我上传了丢失的程序集,正确运行服务,然后将服务文件移回原来的位置。
I had the same error and for me the problem was just that I was missing assemblies on the server that were needed by the service to compile.
All that is described here was not necessary to me.
To find out what your error is, you can try to move your service.svc and service.svc.cs files to the App_Code directory. That way you will get an error message better related to the real error you have.
In my case, the namespace that was missing because I forgot to deploy some assemblies. I uploaded the missing assemblies, run the service correctly then moved back the services files were they belonged.
我有这个问题。
解决方案
在职的...
I had this issue.
Resolution
Working...