我最近创建了一个WCF服务(dll)和一个服务主机(exe).我知道我的WCF服务正常工作,因为我能够成功地将服务添加到WcfTestClient.
但是,当我从服务主机(exe)使用我的WCF时,我似乎遇到了一个问题.我可以向我的服务主机(exe)添加对WCF(dll)的引用,并为exe创建必要的组件; 例如服务安装程序,服务主机和app.config,编译然后最后使用InstallUtil安装exe.但是,当我尝试在Microsoft管理控制台中启动该服务时,该服务在启动后立即停止.
所以我开始调查可能导致此问题的原因是从事件查看器中的应用程序日志中得出此错误.
描述:
服务无法启动.System.InvalidOperationException:服务"服务"具有零应用程序(非基础结构)端点.这可能是因为没有为您的应用程序找到配置文件,或者因为在配置文件中找不到与服务名称匹配的服务元素,或者因为在service元素中没有定义端点.
这个错误实际上是在OnStart; 当我执行此调用时,我的exe ServiceHost.Open().我看过很多其他人遇到过这个问题的帖子,但是大多数(如果不是全部的话)声称服务名称或合同; 命名空间和类名,未指定.我在配置文件中检查了这两个条目; 在exe和dll中,它们完美匹配.我已经让办公室里的其他人仔细检查我,以确保我不会在某一点上失明,但当然他们得出了与我相同的结论,即一切看起来都是正确的.对于此时发生的事情,我真的很迷茫.任何人都可以帮我解决这个问题吗?
另一件可能导致这种情况发生的原因是app.config永远不会被读取; 至少不是我认为应该阅读的那个.这可能是问题吗?如果是这样,我该如何解决这个问题.再次,任何帮助将不胜感激.
我的本地计算机上运行的WCF服务正常运行.我把它放在服务器上,我收到以下错误:
接收到http://xx.xx.x.xx:8200/Services/WCFClient.svc的HTTP响应时发生错误 .这可能是由于服务端点绑定不使用HTTP协议.这也可能是由于服务器中止HTTP请求上下文(可能是由于服务关闭).有关详细信息,请参阅服务器日志.
我已经去了url中的服务,它正常工作.我正在为函数做的就是将一个字符串返回到一个图像名称,因此传递的数据不是很多.我已经跟踪了日志,它给了我相同的信息.这是我的客户端配置:
<binding name="basicHttpBinding_IWCFClient" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<endpoint name="basicHttpBinding_IWCFClient"
address="http://localhost:4295/Services/WCFClient.svc"
binding="basicHttpBinding"
bindingConfiguration="basicHttpBinding_IWCFClient"
behaviorConfiguration="WCFGraphicManagementTool.Services.ClientBehavior"
contract="WCFClient.IWCFClient" />
Run Code Online (Sandbox Code Playgroud)
这是我的服务器配置:
<service behaviorConfiguration="WCFGraphicManagementTool.Services.WCFClientBehavior"
name="WCFGraphicManagementTool.Services.WCFClient">
<endpoint name="basicHttpBinding_IWCFClient"
address=""
binding="basicHttpBinding"
contract="WCFGraphicManagementTool.Contracts.IWCFClient" />
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
<behavior name="WCFGraphicManagementTool.Services.WCFClientBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<serviceThrottling maxConcurrentCalls="120" maxConcurrentSessions="120"
maxConcurrentInstances="120" />
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" /> …Run Code Online (Sandbox Code Playgroud) 我有一个wcf服务,它使用两个端点公开服务.一个端点用于Web服务调用,而另一个端点用于休息.
有没有办法确定从哪个端点调用服务器功能?
我已经创建了一个类似的EndpointAddress
EndpointAddress address = new EndpointAddress("http://example.com/services/OrderService.svc");
Run Code Online (Sandbox Code Playgroud)
但我无法以编程方式将此行为添加到此端点.
行为如下:
<behaviors>
<endpointBehaviors>
<behavior name="NewBehavior">
<dataContractSerializer maxItemsInObjectGraph="6553600" />
</behavior>
</endpointBehaviors>
</behaviors>
Run Code Online (Sandbox Code Playgroud) 我有一个在LAN上正常工作的WCF服务,但是当尝试从外部访问它时,服务引用失败.
我的WCF服务托管在使用静态IP无域的win2k3盒子上.
我有一个WCF Windows服务,在服务的配置文件中指定了端点.
<baseAddresses>
<add baseAddress="net.tcp://localhost:9000/MyEndpoint"/>
</baseAddresses>
Run Code Online (Sandbox Code Playgroud)
一切正常.但是,在某些情况下,端口9000可能已在使用中,导致ServiceHost在Open()上失效.我需要能够在代码中覆盖配置文件中指定的默认基址.例如,假设环境变量包含要使用的端口号.
有没有办法以编程方式执行此操作?
在构造ServiceHost之后,我可以看到BaseAddresses属性,该属性返回从配置文件中获取的Uri列表.但是,这是一个只读集合,因此不能用于更改默认值.
如果我在ServiceHost构造函数中指定替换Uri,我得到
此集合已包含方案net.tcp的地址.此集合中每个方案最多只能有一个地址.如果您的服务在IIS所驻留你可以通过设置"system.serviceModel/serviceHostingEnvironment/multipleSiteBindingsEnabled"为真或指定"system.serviceModel/serviceHostingEnvironment/baseAddressPrefixFilters"解决问题.
如果我创建一个CustomServiceHost并尝试设置替换基地址,我会得到相同的错误.
class CustomHost : ServiceHost
{
public CustomHost(Type serviceType) : base (serviceType)
{
}
protected override void ApplyConfiguration()
{
base.ApplyConfiguration();
this.AddBaseAddress(new Uri("net.tcp://localhost:9010/MyEndpoint"));
}
}
Run Code Online (Sandbox Code Playgroud)
我知道,如果我离开这个配置文件基址的空白,并通过基址到ServiceHost的构造函数,然后是正常工作 - 即我可以指定新的基地.但是,我想使用配置文件来指定默认值(而不是硬编码).
我创建了三个组件.Web站点,WCF服务和包含服务实现的接口的合同程序集.我想使用Castle Windsor在客户端(网站)上为我创建服务,这样我就不必在我希望使用的每个服务的web.config网站中都有一个端点.
我想查看契约程序集并获取命名空间中的所有服务接口.现在,对于每个服务,我在使用容器注册组件时都会遇到以下情况.
container.Register(Component.For<ChannelFactory<IMyService>>().DependsOn(new { endpointConfigurationName = "MyServiceEndpoint" }).LifeStyle.Singleton);
container.Register(Component.For<IMyService>().UsingFactoryMethod((kernel, creationContext) => kernel.Resolve<ChannelFactory<IMyService>>().CreateChannel()).LifeStyle.PerWebRequest);
Run Code Online (Sandbox Code Playgroud)
在我的web.config中我有设置代码.
<system.serviceModel>
<extensions>
<behaviorExtensions>
<add name="AuthToken" type="MyNamespace.Infrastructure.AuthTokenBehavior, MyNamespace.Contracts" />
</behaviorExtensions>
</extensions>
<behaviors>
<endpointBehaviors>
<behavior>
<AuthToken />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00">
<readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647"></readerQuotas>
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint name="MyServiceEndpoint" address="http://someurl/MyService.svc" binding="wsHttpBinding" contract="MyNamespace.Contracts.IMyService"></endpoint>
</client>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
我最终得到了几个看起来几乎完全相同的服务端点,当我们部署到客户端机器上时,他们必须设置每个端点的地址,即使每个端点的基本URL都相同.
我希望在我的web.config中有一个基本URL,它通过代码获取,然后使用合同程序集上的反射向容器注册服务.我确实需要上面配置文件中的专门端点行为.
我从哪里开始?WcfFacility看起来很棒但是doco有点缺乏......
我正在尝试自己学习一些WCF.我有C#/ ASP.net知识,但我是WCF的新手.我在学习的过程中使用Visual Studio 2010来开发一些应用程序.
我开发了一个小型Web服务,它充当TODO /任务管理器的后端,用户可以在其中创建/删除/编辑新事件; 这一切都非常简单和基本.
我的问题如下:
我有一个WCF服务让我们称之为UserService.它UserService有一个类库的引用.我们称之为DoWork.dll.它DoWork.dll具有对我们将调用的不同服务的WCF服务引用CompanyService.
现在,当我第一次尝试调用时,UserService我会得到一个端点未配置的错误消息.各地的网络阅读后,我发现我需要在添加CompanyService绑定和客户信息进入UserService的web.config下<system.serviceModel>节点.
这里是:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IComapnyService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint name="BasicHttpBinding_ICompanyService"
address="http://it-dev.company.local:81/Project/Copmpany/CompanyService.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IComapnyService"
contract="CompanyService.ICompanyService" />
</client>
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是contract="CompanyService.ICompanyService"向我显示错误:
'contract'属性无效 - 值'CompanyService.ICompanyService'根据其数据类型'clientContractType'无效 - Enumeration约束失败.
现在,如果我将CompanyService引用直接添加到UserServiceWCF项目,则错误消失(显然).但是,我不应该这样做.我已经尝试完全限定ICompanyService合同所在的命名空间,但也不起作用.我删除了.suo文件并重建项目,但也无法工作(在网络上的其他地方建议).此外,如果我输入contract=,我会得到下拉列表,但CompanyService.ICompanyService无处可寻(只有当我直接在UserService项目中引用服务时).
我已经尝试使用配置它Tools > WCF Service Configuration Editor,但没有帮助.
我应该注意到一切似乎工作正常,但我不喜欢intellisense给我蓝色波浪线下划线和错误信息的事实.我有一种感觉,我需要其他的东西,web.config以便让它工作,因为UserService引用DoWork.dll,反过来引用CompanyService谁的合同,我无法正确看到.
任何建议都非常感谢.提前致谢.
我正在尝试跟随初学者的演示视频到MSDN上的WCF页面.
第一个视频或多或少都很好.我现在正走向第二个视频的结尾.我正在使用VS2010/.NET 4.0,而视频似乎使用的是VS2008(我假设是.NET 3.5,但我不记得).
我们刚刚添加了3个端点:一个普通的http,net.tcp和net.pipe.当我现在尝试运行项目时,Web服务无法启动.
System.InvalidOperationException: Cannot load the X.509 certificate identity specified in the configuration.
at System.ServiceModel.Description.ConfigLoader.LoadIdentity(IdentityElement element)
at System.ServiceModel.Description.ConfigLoader.LoadServiceDescription(ServiceHostBase host, ServiceDescription description, ServiceElement serviceElement, Action`1 addBaseAddress)
at System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader configLoader, ServiceDescription description, ServiceElement serviceSection)
at System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader configLoader, ServiceDescription description, String configurationName)
at System.ServiceModel.ServiceHostBase.ApplyConfiguration()
at System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses)
at System.ServiceModel.ServiceHost.InitializeDescription(Type serviceType, UriSchemeKeyedCollection baseAddresses)
at System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses)
at Microsoft.Tools.SvcHost.ServiceHostHelper.CreateServiceHost(Type type, ServiceKind kind)
at Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo info)
Run Code Online (Sandbox Code Playgroud)
基于我的Google fu,我遇到了这个帖子:"无法加载配置中指定的X.509证书标识"
我真的不想参与证书,因为我还在尝试基础知识,所以我按照该帖子中的建议添加<dns value="localhost" />标签.异常更改:
Please try changing the …Run Code Online (Sandbox Code Playgroud) wcf ×10
wcf-endpoint ×10
.net ×5
c# ×2
wcf-binding ×2
hostheaders ×1
json ×1
net.tcp ×1
wcffacility ×1
web-config ×1
x509 ×1
xml ×1