对于在 Azure 中托管 WCF 时遇到的问题,我到处搜索并放弃了。现在问这个问题,希望有人能回答。
我的 IIS7 中的 WCF 运行良好,并且我的客户端应用程序已经顺利连接到它。这一切都在本地工作。我的 WCF 配置文件中有这个绑定配置:
<system.serviceModel>
<standardEndpoints />
<bindings>
<basicHttpBinding>
<binding name="basicHttp" closeTimeout="00:10:00" openTimeout="00:10:00"
sendTimeout="00:10:00" allowCookies="true" maxBufferSize="2147483647"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
<webHttpBinding>
<binding name="webHttp" closeTimeout="00:10:00" openTimeout="00:10:00"
sendTimeout="00:10:00" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="SurveyWCFService.SurveyService">
<clear />
<endpoint address="soap" binding="basicHttpBinding" bindingConfiguration="basicHttp"
bindingName="basicHttp" contract="SurveyWCFService.SurveyService" />
<endpoint address="json" behaviorConfiguration="jsonBehavior"
binding="webHttpBinding" bindingConfiguration="webHttp" contract="SurveyWCFService.SurveyService" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="jsonBehavior">
<webHttp />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="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="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
如您所见,我有 2 个端点,一个用于连接到我的服务的 C# 应用程序的 SOAP 端点,以及一个用于使用 REST 访问它的客户端的 JSON 命名端点。我使用“Azure Web Role”模板中的默认配置将其部署到 Azure,我的客户端已经可以访问 Azure 生成的给定 URL。但这里有一些奇怪的东西:
1)每当我的客户使用任何给定的服务方法时,它都会带回这个异常:
System.ServiceModel.EndpointNotFoundException: There was no endpoint listening at
http://<hostedservicename>/SurveyService.svc that could accept the message.
This is often caused by an incorrect address or SOAP action.
See InnerException, if present, for more details. --->
System.Net.WebException: The remote name could not be resolved: '<hostedservicename>'
这很奇怪,因为这意味着我的应用程序没有连接到 .cloudapp.net。所以我尝试使用我的浏览器调用一些服务方法。Fiddler 告诉我响应是“HTTP 400”。在引用端点地址的 URL 后,我还仔细检查了生成的客户端配置文件,地址是正确的。
2) Azure 决定用自己的端点和绑定替换我的端点和绑定。当我使用 Fiddler 检查并检查 wsdl 文件时,我得出了这个结论,这里是 wsdl 文件的底部:
本地 WSDL
<wsdl:service name="SurveyService"><wsdl:port name="basicHttp_SurveyService"
binding="tns:basicHttp_SurveyService"><soap:address location="http://localhost
/SurveyServiceLibrary/SurveyService.svc/soap"/></wsdl:port></wsdl:service>
Azure WSDL
<wsdl:service name="SurveyService"><wsdl:port name="BasicHttpBinding_SurveyService"
binding="tns:BasicHttpBinding_SurveyService"><soap:address location=
"http://<hostedservicename>.cloudapp.net/SurveyService.svc"/></wsdl:port>
</wsdl:service>
如何让我的 WCF 像在本地环境中一样工作?我需要在 WCF 上进行一些配置吗?在 Azure 上?