我正在编写一个需要托管多个WCF服务的应用程序.WCF的优势之一是能够通过在app.config文件中指定设置来配置服务而无需重新编译.
在自托管时,似乎没有一种开箱即用的方式来自动托管app.config文件中的服务.我发现这个问题提到了一个可能的解决方案,即在运行时动态枚举app.config中列出的服务,并为每个服务创建一个ServiceHost.
但是,我的服务,合同和托管应用程序都在不同的程序集中.这导致Type.GetType(string name)无法找到我的服务类型(返回null),因为它是在不同的程序集中定义的.
如何可靠地托管app.config文件中列出的所有服务(即,new ServiceHost(typeof(MyService))在我的自托管应用程序中没有硬编码?
注意:我的app.config是使用Visual Studio 2010中的"WCF配置编辑器"生成的.
另请注意:我的主要目标是由app.config文件驱动,因此只有一个配置点.我不想在一个单独的位置配置它.
编辑:我能够读取app.config文件(请参阅此处),但需要能够解析不同程序集中的类型.
编辑:下面的答案之一促使我尝试在app.config中指定AssemblyQualifiedName而不仅仅是基本类型名称.这能够解决Type.GetType()问题,但无论我如何获得类型,ServiceHost.Open()现在都失败了InvalidOperationException:
// Fails
string typeName = typeof(MyService).AssemblyQualifiedName;
Type myType = Type.GetType(typeName);
ServiceHost host = new ServiceHost(myType);
host.Open(); // throws InvalidOperationException
// Also fails
Type myType2 = typeof(MyService);
ServiceHost host2 = new ServiceHost(myType2);
host2.Open(); // throws InvalidOperationException
Run Code Online (Sandbox Code Playgroud)
例外细节:
Service 'SO.Example.MyService' has zero application (non-infrastructure) endpoints. This might be because no configuration file …
可以使用不同类型的主机.
Windows进程激活服务(WAS)
IIS
自我托管
托管在Windows服务中
使用一个在另一个上有优势吗?哪一个更好?
我创建了一个具有客户端 (WPF) 和服务器 (WCF) 的应用程序,该服务由 IIS 托管,目前我必须拥有 2 个版本的 vs 2010。一个在 IIS 中加载 wcf 服务,另一个在我的 Windows 中加载应用。
问题是它需要太多资源。
如果 wcf 服务“不是”托管在 IIS 中,那么我可以根据这个http://msdn.microsoft.com/en-us/library/bb157685.aspx同时启动两个项目
但是我的其他选择是什么?
我需要找到能够在调试时编译/运行 2 个项目并能够 STEP INTO 每个项目的最佳方法,而不使用太多资源或同时打开多个 2010。
我在自己的计算机(办公室)上开发了一些WCF服务.现在,我必须在办公室服务器上发布它.
Office服务器是Windows Server 2008 R2(IIS7).我该怎么办,在某个地址访问我的服务?喜欢192.168.1.99:5555?
我想知道开发人员对WCF WebApi服务的看法是什么.
在N层应用程序中,我们可以拥有多层服务.我们可以使用服务来消耗外部服务的数据.在那种情况下,使用WCF 4.0创建异步休息服务是值得的.
public interface IService
{
[OperationContractAttribute(AsyncPattern = true)]
IAsyncResult BeginGetStock(string code, AsyncCallback callback, object asyncState);
//Note: There is no OperationContractAttribute for the end method.
string EndGetStock(IAsyncResult result);
}
Run Code Online (Sandbox Code Playgroud)
但随着WCF WebApi的发布,这种方法仍然需要吗?创建异步服务?
如何在IIS/WAS /自托管中托管它们
期待建议和评论.
以下是场景。
我们有 F5 负载均衡器,传入的请求作为 HTTP 进入 F5 负载均衡器,然后它们被重定向到 WCF 服务服务器作为 HTTP。
我已经尝试了几乎所有可能的配置组合,但它不断给出两个不同的错误。例如,根据一些建议,我尝试将安全模式更改为“传输”,然后错误更改为:“无法为具有权限 'xxx.xxx.xxx.xxx:XXXX' 的 SSL/TLS 建立安全通道.”
<system.serviceModel>
<services>
<service behaviorConfiguration="NameofServiceBehaviour" name="NameOfServices">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpEndPointBinding" name="wsHttpEndPoint" contract="Name.IContractName" />
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="wsHttpEndPointBinding">
<security mode="None">
<!-- <transport clientCredentialType="Certificate" /> -->
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviourName">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<!-- <serviceCredentials>
<serviceCertificate findValue="CN=CertificateName" storeLocation="LocalMachine" />
</serviceCredentials> -->
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="wsHttpEndPoint">
<security mode="None" /> …Run Code Online (Sandbox Code Playgroud) 我用WCF服务创建了一个解决方案VS2010 C#,该库获取数据,该服务在解决方案中的控制台应用程序中运行良好.没问题.
对于旧项目,我必须在VS2008项目(以及稍后可能在VS2005上)上使用它.然后我启动VS2010我得到"WCF测试客户端".此时在VS2008中,我尝试在本地计算机上"添加Web引用"...没有结果.
然后我尝试使用Vs2010创建一个控制台应用程序来托管它,我这样做了:
Uri baseAddress = new Uri("http://localhost:8080/hello");
using (ServiceHost host = new ServiceHost(typeof(SecurityAccessWCF.WCFSecurityService), baseAddress))
{
// Enable metadata publishing.
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
host.Description.Behaviors.Add(smb);
host.Open();
Console.WriteLine("The service is ready at {0}", baseAddress);
Console.WriteLine("Press <Enter> to stop the service.");
Console.ReadLine();
// Close the ServiceHost.
host.Close();
}
Run Code Online (Sandbox Code Playgroud)
我得到一个错误Open(),我收到此错误"AddressAccessDeniedException - HTTP无法注册URL ...您的进程没有访问权限"(提供的链接不清楚,我在Win7 x64上作为本地管理员和在域)

我有一个带有以下app.config文件的WCF控制台应用程序
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netNamedPipeBinding>
<binding name="namedPipeBindingConfig" maxBufferPoolSize="268435456" maxBufferSize="16777216" maxReceivedMessageSize="16777216" />
</netNamedPipeBinding>
</bindings>
<services>
<service behaviorConfiguration="serviceBehavior" name="MyTestNamespace.MyTestClassService">
<endpoint address="net.pipe://localhost/MyService"
binding="netNamedPipeBinding" bindingConfiguration="namedPipeBindingConfig"
name="NamedPipeBinding" contract="MyTestNamespace.IMyTestContract" />
</service>
</services>
</system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)
我将它作为控制台应用程序托管(接口,实现和托管类都在一个项目中),基本上这样做:
ServiceHost host = new ServiceHost(typeof(MyTestClassService));
host.Open();
Run Code Online (Sandbox Code Playgroud)
我从命令提示符"C:\ SomePath \> RunMyService.exe"运行,它启动并运行良好.现在,我打算在IIS 7中托管这个,我没有找到任何关于如何在那里部署(特定的控制台应用程序)的好例子.我的问题很少:
1)我是否需要在IIS中"添加网站"或"添加应用程序"并将我的文件放在那里?
2)我需要一个.svc文件吗?如果是,它必须包含什么,如何告诉它启动此控制台应用程序.
3)这个控制台应用程序会在IIS中运行吗?这是如何运作的 ?
我是WCF的新手.我期待步骤在IIS上部署WCF并使用该服务.我遵循与在IIS上部署网站相同的步骤,也将默认文档设置为Service1.svc
现在当我尝试使用这个wcf服务时,它给了我以下错误.
Metadata contains a reference that cannot be resolved: 'http://manish-pc:8000/Service1.svc?wsdl'.
The WSDL document contains links that could not be resolved.
There was an error downloading 'http://manish-pc:8000/Service1.svc?xsd=xsd0'.
The underlying connection was closed: An unexpected error occurred on a receive.
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
An existing connection was forcibly closed by the remote host
Metadata contains a reference that cannot be resolved: 'http://localhost:8000/Service1.svc'.
Content Type application/soap+xml; charset=utf-8 …Run Code Online (Sandbox Code Playgroud) 我一直在研究网络服务,并通过直接从VS2012在浏览器中查看它进行测试,但现在我需要在IIS中托管它,出于某种原因,它根本不起作用.
我已经尝试将其作为我本地IIS下的新Web应用程序发布.它显示应该如此,但当我切换到IIS中的内容视图时,右键单击该MyService.svc文件,然后选择"浏览",我得到的是一个新的Web浏览器窗口,说明找不到该站点.
为了检查问题是否与我服务中的某些内容有关,或者是一般问题,我尝试从VS项目模板(一个新的WCF服务应用程序)创建一个新的测试服务,我编译好了,在我的浏览器中运行得很好,然后尝试了发布到IIS,具有相同的结果.
一点额外信息:
我最近能够在IIS中发布一个网站,它运行正常 - 我真的认为这个过程应该与服务大致相同,但显然我错过了一些东西.
更新:回复以下评论的一些额外信息:
.asmx文件,只有.svc文件,文件web.config和bin/文件夹.任何关于我可以尝试解决这个问题的提示将不胜感激....
我正在使用Visual Studio 2010,我正在尝试创建一个包含N层架构的解决方案.
每个级别都有一个项目
上面列出的项目也以相同的顺序调用; 因此,Web与服务层进行对话,服务层与业务和业务进行对话,然后与工厂进行对话,工厂项目负责与DB进行对话.
我遇到的问题是以一种方式设置我的项目,在按下F5启动Web项目之前 - 应首先启动ServiceHost(它只是WCF的自主控制台),以便Web调用服务时; 它已经启动并运行了.
注意:在珠三角; Web和WCF将完全托管在不同的盒子上,所以这不是问题,但是对于在本地机器上开发 - 我需要上面的内容.
临时解决方案 - 我已从解决方案中排除了ServiceHost项目,因此它不会通过Web启动,我从命令行外部运行ServiceHost可执行文件以启动并运行服务,然后我正常使用F5启动Web项目.
有人可以告诉我,为了达到上述目的,我该怎么办?
wcf-hosting ×11
wcf ×10
iis ×4
c# ×3
iis-7 ×3
.net ×1
asp.net ×1
https ×1
self-hosting ×1
wcf-client ×1
wcf-http ×1
wcf-rest ×1
wcf-web-api ×1
web-services ×1
windows-7 ×1