我有一个运行在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 项目中,它只会在基地址下显示我的服务(特定端点地址不返回任何内容)。如果我添加它,生成的类大致正确,只是我无法调用任何服务方法,并收到错误消息“在此地址上没有侦听端点”。(如果我使用需要端点名称的服务客户端构造函数,则也会发生这种情况。)
我做错了什么?