wsHttpBinding 更改为客户端 app.config 中的 basicHttpBinding
在 WCF 服务中,我将端点绑定设置为 wsHttpBinding。但是,当我使用 Visual Studio 添加服务引用时,我的客户端 app.config 将绑定显示为 basicHttpBinding。有谁知道为什么会发生这种情况?
服务 web.config 中的我的端点(托管在 IIS 7.5 中)。从baseAddresses客户端app.config获取地址
<endpoint address=""
binding="wsHttpBinding"
bindingConfiguration="wsHttpServiceBinding"
contract="MyProject.IMyService" />
:
<client>
<endpoint address="http://example.com/MyService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_MyService"
contract="Service.MyService" name="BasicHttpBinding_MyService" />
</client>
In a WCF service I have an endpoint binding set as wsHttpBinding. However when I use Visual Studio to Add Service Reference my clients app.config shows the binding as basicHttpBinding. Does anybody know why this may be happening?
My Endpoint in the service web.config (hosted in IIS 7.5). Gets address from baseAddresses
<endpoint address=""
binding="wsHttpBinding"
bindingConfiguration="wsHttpServiceBinding"
contract="MyProject.IMyService" />
Client app.config:
<client>
<endpoint address="http://example.com/MyService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_MyService"
contract="Service.MyService" name="BasicHttpBinding_MyService" />
</client>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
-- Ladislav Mrnka 以此为我指明了正确的方向。非常感谢。
我试图让问题变得简单,因为我认为答案可能很简单。不过,我应该更详细地解释我的设置,因为这就是我的问题的答案所在。
我没有将服务契约 (IMyService) 驻留在我的 WCF 服务应用程序中,而是将其放在另一个域项目中,在该项目中保留所有接口,以便可以在许多不同的项目中重用它们。在我的 WCF 服务应用程序 .web.config 中,我的服务名称指向接口项目而不是实现。这导致 VS2010 (svcutil.exe) 根据默认设置创建代理和配置(我假设驻留在 machine.config 中(对于 WCF 4))。
因此,对于可能遇到此问题的其他人来说,总结一下,这是服务名称指向错误的位置。确保服务名称指向实现(通常在 WCF 服务应用程序中 - MyProject.MyService),并且端点协定指向服务协定(在 WCF 服务应用程序或外部项目中 - MyProject.IMyService 或 AnotherProject.Interfaces.IMyService) )。
感谢您的帮助。
-- Ladislav Mrnka pointed me in the right direction with this. Thanks very much.
I tried to keep the question simple as I thought the answer may be straight forward. However I should have explained my set up in a little bit more detail as this is where the answer to my problem lay.
Instead of having my service contract (IMyService) residing in my WCF Service Application I had it in another Domain project where I keep all my interfaces so that they can be reused throughout many different projects. In my WCF Service Application .web.config I had the service name pointing at the interface project rather than at the implementation. This caused VS2010 (svcutil.exe) to create a proxy and config based on default settings (I presume reside in the machine.config (for WCF 4)).
So to summarise for anybody else who may come across this issue it was service name pointing to the wrong location. Ensure that the service name points to the implementation (usually in the WCF Service Application - MyProject.MyService) and that the endpoint contract points to the service contract (In the WCF Service Application or external project - MyProject.IMyService or AnotherProject.Interfaces.IMyService).
Thanks for all your help.
就我而言,我对 App.config 进行了以下更改
在服务的 name 属性中,我给出了完整的命名空间和类名称,其中我有服务实现,并且在合同中,我有完整的命名空间和接口名称。
我的服务实现命名空间是这个
Registrar.Services.RegistrarPaperService
我的接口Registrar.Services.IRegistrarPaperService
如果您将服务及其接口放在同一个命名空间中,它将解决许多问题。
In my case, I made the following changes to my App.config
In name attribute of the service I gave the complete namespace and class name where I have service implementation and in the contract, I have complete name space and Interface name.
My Service Implementation namespace is this
Registrar.Services.RegistrarPaperService
My Interface
Registrar.Services.IRegistrarPaperService
IF you put both the service and its interface in the same namespace it will solve many issues.