WCF 托管在 Windows 服务中,wsHttpBindngs 指向错误的位置
WCF hosted in Windows Service with wsHttpBindngs points to wrong location
简而言之,当我在 IIS 中使用相同的配置时,我可以看到:
当我转到 Service1
时,我可以看到 'wsdl' 信息。
现在,当我停止 IIS 并使用相同的配置启动 Windows 服务时:
<system.serviceModel>
<services>
<service name="WcfService1.Service1">
<host>
<baseAddresses>
<add baseAddress="https://localhost:443/WcfService1"/>
</baseAddresses>
</host>
<endpoint address=""
binding="basicHttpBinding"
contract="WcfService1.IService1"
bindingConfiguration="basicHttpBindingConfiguration"/>
<endpoint address="ws"
binding="wsHttpBinding"
contract="WcfService1.IService1"
bindingConfiguration="wsHttpBindingConfiguration"
behaviorConfiguration="wsBehaviorConfig"/>
<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBindingConfiguration">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="wsHttpBindingConfiguration">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<client />
<behaviors>
<endpointBehaviors>
<behavior name="wsBehaviorConfig">
<!-- <wsdlExtensions location="https://localhost:443/WcfService1/Service1.svc" singleFile="true" /> -->
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
当我在 https://localhost/WcfService1
刷新网页时,我看到了 WSDL 信息:
结果,我无法与该服务通话。我不明白我可能做错了什么。有什么建议吗?
在第一种情况下,您遇到的是基于 'WCF Service Application' 模板的启动项目的默认行为。您会看到给定地址的项目文件夹内容。
在第二种情况下,您会看到描述 'how to consume your service page' 因为您启用了 GET 页面
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
如果您想使用您的服务,则需要从您的 client-app 'add service reference' 或手动创建代理。
简而言之,当我在 IIS 中使用相同的配置时,我可以看到:
当我转到 Service1
时,我可以看到 'wsdl' 信息。
现在,当我停止 IIS 并使用相同的配置启动 Windows 服务时:
<system.serviceModel>
<services>
<service name="WcfService1.Service1">
<host>
<baseAddresses>
<add baseAddress="https://localhost:443/WcfService1"/>
</baseAddresses>
</host>
<endpoint address=""
binding="basicHttpBinding"
contract="WcfService1.IService1"
bindingConfiguration="basicHttpBindingConfiguration"/>
<endpoint address="ws"
binding="wsHttpBinding"
contract="WcfService1.IService1"
bindingConfiguration="wsHttpBindingConfiguration"
behaviorConfiguration="wsBehaviorConfig"/>
<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBindingConfiguration">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="wsHttpBindingConfiguration">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<client />
<behaviors>
<endpointBehaviors>
<behavior name="wsBehaviorConfig">
<!-- <wsdlExtensions location="https://localhost:443/WcfService1/Service1.svc" singleFile="true" /> -->
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
当我在 https://localhost/WcfService1
刷新网页时,我看到了 WSDL 信息:
结果,我无法与该服务通话。我不明白我可能做错了什么。有什么建议吗?
在第一种情况下,您遇到的是基于 'WCF Service Application' 模板的启动项目的默认行为。您会看到给定地址的项目文件夹内容。
在第二种情况下,您会看到描述 'how to consume your service page' 因为您启用了 GET 页面
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
如果您想使用您的服务,则需要从您的 client-app 'add service reference' 或手动创建代理。