一项服务、多个端点、WCF 上的多个绑定。为什么我无法到达终点?
我有一个由 IIS 运行的 WCF 服务。我想创建两个使用相同服务的不同客户端(WPF 和 WP7)。 WPF 客户端已使用 wsHttpBinding
和 https
处理端点。遗憾的是,WP7 不支持 wsHttpBinding
,仅支持 BasicHttpBinding
。所以我想我应该为两者公开不同的端点,这样它们就可以访问相同的服务,但具有不同的绑定等等...
所以这是我在 IIS 上的 Web.config:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="TransportSecurity">
<reliableSession enabled="true" />
<security mode="TransportWithMessageCredential" >
<transport clientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>
<basicHttpBinding>
<binding name="BasicTransportSecurity">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="SmartCook2.Server.ISmartCookServiceBehavior">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service behaviorConfiguration="SmartCook2.Server.ISmartCookServiceBehavior"
name="SmartCook2.Server.SmartCookService">
<endpoint address="WS" binding="wsHttpBinding" bindingConfiguration="TransportSecurity"
name="WS" contract="SmartCook2.Server.ISmartCookService" />
<endpoint address="Basic" binding="basicHttpBinding" bindingConfiguration="BasicTransportSecurity"
name="Basic" contract="SmartCook2.Server.ISmartCookService" />
<endpoint address="mex" binding="mexHttpsBinding" name="mex"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<connectionStrings>
<add name="SmartCookDBEntities" connectionString="metadata=res://*/SmartCookContext.csdl|res://*/SmartCookContext.ssdl|res://*/SmartCookContext.msl;provider=System.Data.SqlClient;provider connection string="data source=RENDERBETYAR;initial catalog=SmartCookDB;integrated security=True;pooling=False;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
现在,如果我做对了,端点应该是可通过以下地址访问:
https://localhost/IISHostedSmartCook/SmartCookService.svc/Basic
https://localhost/IISHostedSmartCook/SmartCookService.svc/WS
https://localhost/IISHostedSmartCook/SmartCookService.svc/mex
如果我在浏览器中检查它们,我什么也得不到。没有例外,但也没有内容。使用基地址(直到 .svc 部分)我获得默认服务页面,我可以访问 wsdl 并且它是有效的。据我所知,它具有正确的端点、我的服务方法等。
如果我尝试将 ServiceReference 添加到我的 WP7 项目是 Visual Studio,我只能在基地址下看到我的服务(特定端点地址不返回任何内容)。如果我添加它,类会生成正确的,只是我无法调用任何服务的方法,并且收到错误消息“没有端点在该地址侦听”。 (如果我使用需要端点名称的服务客户端构造函数,也会发生这种情况。)
我做错了什么?
I have a WCF service run by IIS. I would like to create two different clients (WPF and WP7), that are using the same service. The WPF client was already working with an endpoint using wsHttpBinding
and https
. Sadly WP7 doesn't do wsHttpBinding
, only BasicHttpBinding
. So I thought I would expose different endpoints for the two, so they could access the same service, but with different bindings and what not...
So here is my Web.config on IIS:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="TransportSecurity">
<reliableSession enabled="true" />
<security mode="TransportWithMessageCredential" >
<transport clientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>
<basicHttpBinding>
<binding name="BasicTransportSecurity">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="SmartCook2.Server.ISmartCookServiceBehavior">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service behaviorConfiguration="SmartCook2.Server.ISmartCookServiceBehavior"
name="SmartCook2.Server.SmartCookService">
<endpoint address="WS" binding="wsHttpBinding" bindingConfiguration="TransportSecurity"
name="WS" contract="SmartCook2.Server.ISmartCookService" />
<endpoint address="Basic" binding="basicHttpBinding" bindingConfiguration="BasicTransportSecurity"
name="Basic" contract="SmartCook2.Server.ISmartCookService" />
<endpoint address="mex" binding="mexHttpsBinding" name="mex"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<connectionStrings>
<add name="SmartCookDBEntities" connectionString="metadata=res://*/SmartCookContext.csdl|res://*/SmartCookContext.ssdl|res://*/SmartCookContext.msl;provider=System.Data.SqlClient;provider connection string="data source=RENDERBETYAR;initial catalog=SmartCookDB;integrated security=True;pooling=False;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
Now if I got it right the endpoints should be accessible on the following addresses:
https://localhost/IISHostedSmartCook/SmartCookService.svc/Basic
https://localhost/IISHostedSmartCook/SmartCookService.svc/WS
https://localhost/IISHostedSmartCook/SmartCookService.svc/mex
If I check them in my browser I get nothing. There's no exception, but no content either. Using the base address (till the .svc part) I get the default service page and I can access the wsdl and it is valid. It has the endpoints, my service's methods etc correctly as far as I can tell.
If I try to add the ServiceReference to my WP7 project is Visual Studio, I can only see my service under the base address (specific endpoint addresses return nothing). If I add it, the classes are generated about right, only I can't call any of my service's methods and I get the error message "There is no endpoint listening at this address". (This also happens if I use the service client's constructor requiring the endpoint's name.)
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
检查此处详细解释。
您需要指定的是
端点
中的地址:Check here for detailed explanation.
What you will need to specify is the address like so in your
endpoints
:您的所有配置都是正确的,如果您检查您的 wsdl,则 SOAP:address 属性将具有您指定的位置,即:
当您在项目中添加引用时,您只需要使用您想要的适当端点,即如果您想要使用 basicHttpBinding 然后使用其地址为的端点
当您在 IE 中浏览到这些地址时,您不会看到任何绝对正确的内容。为了使其更明智,请将 localhost 替换为您的计算机名称,该名称应该在您所在的网络上可见,以便可以通过网络访问服务。
还可以尝试构建一个 .NET 客户端来调用服务并确保您的服务完美运行。
All your configuration is correct and if you inspect your wsdl the SOAP:address attribute would have the locations as specified by you i.e:
When you add a reference in your projects you just need to use the appropriate endpoint which you want i.e. if you want to use basicHttpBinding then use that endpoint which has its address as
When you browse to these addresses in IE you would not see anything which is absolutely correct. To make it more sensibile replace localhost with your machine name which should be visible on the network you are in so that the services are accessible across the network.
Also try to build a .NET client to invoke the service and make sure your services are working perfectly.
我相信您可能需要将端点地址更改为相对位置:
并且
mex 地址是一种特殊情况,因此不需要更改。
有关更多详细信息,请参阅 MSDN 文档指定端点地址。
I believe that you may need to change your end point addresses to be relative locations:
and
The mex address is a special case, so shouldn't need to be changed.
See the MSDN documentation Specifying an Endpoint Address for more details.
在这里回答:
可以
基本上你 如上所述,在同一 URI 上没有不同的绑定 在这里
不过,同一绑定中可以有不同的绑定配置。
Answered here:
WCF: Multiple binding configurations for a single service
Basically you can't have different bindings at the same URI as mentioned Here
You can have different binding configurations in the same binding though.