![](/img/trans.png)
[英]WCF: Windows service cannot find endpoint when hosted in Winforms application
[英]Cannot find Endpoint in Azure Hosted WCF
我在高空搜尋了我在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角色”模板中的默認配置將其部署到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之后,我還仔細檢查了生成的client-config文件,該地址是正確的。
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上?
我建議你看一看調用 WCF服務的應用程序。 我覺得它沒有使用完整的URL。 查找client / endpoint元素,如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
...
<client>
<endpoint address="http://<hostedservicename>.cloudapp.net/SurveyService.svc" ... />
</client>
</system.serviceModel>
</configuration>
哦, “遠程名稱無法解析”錯誤也可能表示您尚未獲得DNS復制。 在這種情況下,我傾向於手動將DNS服務器更改為8.8.8.8(Google的DNS服務器),並且在大多數情況下可以正常工作(幾分鍾后您可以將其更改為自動)。
離開這個對於那些誰在同樣的問題絆倒:
我檢查,我提供我的服務配置文件的命名空間 ,我對命名空間錄入錯誤 , 愚蠢的我:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.