web-services - 无法添加托管在 azure 中的 WCF 服务
问题描述
我在服务器上托管了一项 WCF 服务
http://firstdomain.com/WebStorePrice/PickStorePrice.svc
它在我的机器上运行。现在我将它作为 azure 服务托管到新服务器,当尝试添加服务引用时出现错误
下载“ https://service.azurewebsites.net/PickStorePrice.svc/$metadata ”时出错。请求失败,HTTP 状态为 404:未找到。元数据包含无法解析的引用:“ https://service.azurewebsites.net/PickStorePrice.svc ”。在https://service.azurewebsites.net/PickStorePrice.svc上没有可以接受消息的端点侦听。这通常是由不正确的地址或 SOAP 操作引起的。有关更多详细信息,请参阅 InnerException(如果存在)。远程服务器返回错误:(404) Not Found。如果在当前解决方案中定义了服务,请尝试构建解决方案并再次添加服务引用。wcf 服务的 webconfig 看起来像
<system.serviceModel>
<services>
<service name="WebStorePrice.PickStorePrice" behaviorConfiguration="cstmServiceConfig">
<endpoint address="" binding="basicHttpBinding" contract="WebStorePrice.IPickStorePrice"/>
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="secure">
<security mode="Transport">
<transport clientCredentialType="Basic"/>
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="cstmendpointConfig">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="cstmServiceConfigOnline">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
<behavior name="cstmServiceConfig">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"/>
</system.serviceModel>
解决方案
从服务配置来看,我们的服务不支持Https
协议,因为Azure
docker(Paas)server 默认通过 Https 进行通信。因此,我们应该配置一个额外的服务端点来支持 WCF over https。
对于 Soap 风格的 Web 服务,请参考以下配置。
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
<add binding="basicHttpBinding" scheme="http"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
关于 WCF Restful 风格的服务。
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior>
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="mybinding">
<security mode="Transport">
<transport clientCredentialType="None"></transport>
</security>
</binding>
</webHttpBinding>
</bindings>
<protocolMapping>
<add binding="webHttpBinding" scheme="http"/>
<add binding="webHttpBinding" scheme="https" bindingConfiguration="mybinding"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
如果问题仍然存在,请随时告诉我。
推荐阅读
- xslt - If else 条件使用 BI Publisher RTF
- ios - iOS获取没有DST偏移的时区字符串
- javascript - reactjs航点导入问题
- git - WSL.exe 中的 VSCode 'Git Status' 不同(与 powershell 相比)
- javascript - 如何在 SAPUI5 表中使用 odata 扩展参数?
- javascript - 关闭后如何清除字段并重置模式内的表单?
- sql-server - 将 Oracle 正则表达式查询转换为 MSSQL
- android - 如何在不创建新活动的情况下重用活动?
- python - 如何按用户查找 Django 应用程序中的登录总数?
- bash - 变量未在通过heredoc 传递的脚本中初始化