Jaz*_*eff 7 wcf wcf-binding c#-4.0
首先我会道歉,因为这可能是重复的,但我读到的所有内容似乎都不完整或令人困惑,因为我对WCF很新.
我基本上希望在IIS中部署一个WCF服务,可以访问2个端点,并且整天都在圈子里走动:(
我有一个服务库WCF DLL具有以下结构
App.config
TestSvc1.cs
ITestSvc1.cs
TestSvc2.cs
ITestSvc2.cs
Run Code Online (Sandbox Code Playgroud)
这在VS WCF测试客户端中运行良好,现在我正在部署到IIS,因此我创建了一个WCF服务应用程序并引用了dll.该项目具有以下结构
Service1.svc
Web.config
Run Code Online (Sandbox Code Playgroud)
Service1.svc 包含这个
<%@ ServiceHost Language="C#" Debug="true"
Service="WCFServices.TestServices.ITestSvc1" CodeBehind="Service1.svc.cs" %>
Run Code Online (Sandbox Code Playgroud)
我web.config有以下几点
<services>
<service name="WCFServices.TestServices.TestSvc2">
<endpoint
address=""
binding="wsHttpBinding" bindingConfiguration="LargeSizeMessages"
contract="WCFServices.TestServices.ITestSvc2">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/wcf2/TestServices/TestSvc2/" />
</baseAddresses>
</host>
</service>
<service name="WCFServices.TestServices.TestSvc1">
<endpoint
address=""
binding="wsHttpBinding" bindingConfiguration="LargeSizeMessages"
contract="WCFServices.TestServices.ITestSvc1"
listenUri="http://localhost:8080/wcf2/service1.svc">
<identity>
<dns value="" />
</identity>
</endpoint>
<endpoint
address=""
binding="wsHttpBinding" bindingConfiguration="LargeSizeMessages"
contract="WCFServices.TestServices.ITestSvc2"
listenUri="http://localhost:8080/wcf2/service1.svc">
<identity>
<dns value="" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/wcf2/TestServices/TestSvc1/" />
</baseAddresses>
</host>
</service>
</services>
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.你可以看到我已经尝试添加一个额外的端点,web.config但是这不起作用,我得到一个错误,说在TestSvc1中找不到TestSvc2调用,我想这与入口有关Service1.svc
我还读到了创建一个继承这些接口的类,但我不确定如何根据我上面的内容实现它.我需要修改Service1.svc吗?
public interface MultipleSvc : ITestSvc1, ITestSvc2
{
// What exactly do I put here? I have no idea, do I leave it blank? This didn't work for me
}
Run Code Online (Sandbox Code Playgroud)
任何帮助将非常感谢伙计们:)
mar*_*c_s 11
黄金法则:一个.svc=一个服务(或更具体地说:一个服务实现类)
所以如果你有两个独立的,不同的服务(在类WCFServices.TestServices.TestSvc1和中WCFServices.TestServices.TestSvc2),那么你需要两个.svc文件(每个服务一个)
你可以做的是有一个服务实现类,它实现了两个服务契约:
public class MultipleServices : ITestSvc1, ITestSvc2
{
// implement the service logic here, for both contracts
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,一个svc文件就足够了(该.svc文件是每个实现类,可以托管多个服务契约).但是你也需要改变你的配置 - 因为你真的只有一个服务类(因此:一个<service>标签)和托管在其中的多个合同:
<services>
<service name="WCFServices.TestServices.MultipleServices">
<endpoint
address="Service1"
binding="wsHttpBinding" bindingConfiguration="LargeSizeMessages"
contract="WCFServices.TestServices.ITestSvc1">
<identity>
<dns value="" />
</identity>
</endpoint>
<endpoint
address="Service2"
binding="wsHttpBinding" bindingConfiguration="LargeSizeMessages"
contract="WCFServices.TestServices.ITestSvc2">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
Run Code Online (Sandbox Code Playgroud)
另外:由于您似乎在IIS中托管WCF服务,因此定义任何<baseAddress>值都没有意义- 服务的"基本"地址是*.svc文件所在的位置(URI).