[英]WCF can't find the endpoint configuration issue
我有一個WCF的web服務我在我的本地機器上測試,它給了我一個headscratcher。
我的服務配置如下:
<system.serviceModel>
<services>
<service name="GHMDatroseIntegration.GHMDatroseWCFService.DatroseService"
behaviorConfiguration="DatroseServiceBehavior">
<endpoint
address="mex"
binding="basicHttpBinding"
contract="GHMDatroseIntegration.GHMDatroseWCFService.IDatroseService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DatroseServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
我的客戶端配置如下:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IDatroseService"
closeTimeout="00:02:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:02:00"
allowCookies="false" bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="524288" maxBufferPoolSize="524288"
maxReceivedMessageSize="524288"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas
maxDepth="32" maxStringContentLength="524288"
maxArrayLength="524288" maxBytesPerRead="524288"
maxNameTableCharCount="524288" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint name="BasicHttpBinding_IDatroseService"
address="http://localhost/DatroseWCFService/DatroseService.svc"
behaviorConfiguration="DatroseServiceBehavior"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IDatroseService"
contract="DatroseWCFService.IDatroseService" />
</client>
<behaviors>
<endpointBehaviors>
<behavior name="DatroseServiceBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
我收到的錯誤是:
在http://localhost/DatroseWCFService/DatroseService.svc上沒有可以接受該消息的端點。 這通常是由錯誤的地址或SOAP操作引起的。 有關更多詳細信息,請參閱InnerException(如果存在)。
...然而,如果我瀏覽到我獲得服務屏幕的位置,那么它似乎已正確設置。
我確定這與我的端點配置有關,但我無法弄清楚它們應該是什么樣子。 這里有一些幫助。
UPDATE whups我輸錯了錯誤信息。現在已經修復了。
根據我認為在這些響應中建議的更新2我已將服務器配置更改為:
<system.serviceModel>
<services>
<service name="GHMDatroseIntegration.GHMDatroseWCFService.DatroseService"
behaviorConfiguration="DatroseServiceBehavior">
<endpoint
address="/svc"
binding="basicHttpBinding"
contract="GHMDatroseIntegration.GHMDatroseWCFService.IDatroseService" />
<endpoint
address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DatroseServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
和我的客戶端配置:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IDatroseService"
closeTimeout="00:02:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:02:00"
allowCookies="false" bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="524288" maxBufferPoolSize="524288"
maxReceivedMessageSize="524288"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas
maxDepth="32" maxStringContentLength="524288" maxArrayLength="524288"
maxBytesPerRead="524288" maxNameTableCharCount="524288" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint name="BasicHttpBinding_IDatroseService"
address="http://localhost/DatroseWCFService/DatroseService.svc/svc"
behaviorConfiguration="DatroseServiceBehavior"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IDatroseService"
contract="DatroseWCFService.IDatroseService" />
</client>
<behaviors>
<endpointBehaviors>
<behavior name="DatroseServiceBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
當我運行這個時,我現在得到一個400(錯誤的請求)錯誤。 我不確定這是前進還是后退。 我是否創建了一個新問題,還是讓我清楚了解下一個問題?
更新3
根據niao的建議,我更改為服務器配置:
<system.serviceModel>
<services>
<service name="GHMDatroseIntegration.GHMDatroseWCFService.DatroseService" behaviorConfiguration="DatroseServiceBehavior">
<endpoint contract="GHMDatroseIntegration.GHMDatroseWCFService.IDatroseService" binding="basicHttpBinding" address="http://localhost/DatroseWCFService/DatroseService.svc"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DatroseServiceBehavior">
<!-- 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="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
...但是,當我瀏覽這個地址時,我得到了一個黃色的死亡屏幕:
'/ DatroseWCFService'應用程序中的服務器錯誤。
當'system.serviceModel / serviceHostingEnvironment / multipleSiteBindingsEnabled'在配置中設置為true時,端點需要指定相對地址。 如果要在端點上指定相對偵聽URI,則地址可以是絕對的。 要解決此問題,請為端點“http://localhost/DatroseWCFService/DatroseService.svc”指定相對uri。
......所以,我試着把它變成一條相對的路徑:
<endpoint
address="localhost/DatroseWCFService/DatroseService.svc"
binding="basicHttpBinding"
contract="GHMDatroseIntegration.GHMDatroseWCFService.IDatroseService" />
...但在發布之后,我收到404錯誤。 客戶端端點配置如下:
<endpoint name="BasicHttpBinding_IDatroseService"
address="http://localhost/DatroseWCFService/DatroseService.svc"
behaviorConfiguration="DatroseServiceBehavior"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IDatroseService"
contract="DatroseWCFService.IDatroseService" />
更新4根據marc_s的建議,我從客戶端刪除了綁定配置,所以我的配置如下所示:
<system.serviceModel>
<client>
<endpoint address="http://localhost/DatroseWCFService/DatroseService.svc" behaviorConfiguration="DatroseServiceBehavior"
binding="basicHttpBinding"
contract="DatroseWCFService.IDatroseService" name="BasicHttpBinding_IDatroseService" />
</client>
<behaviors>
<endpointBehaviors>
<behavior name="DatroseServiceBehavior">
<dataContractSerializer maxItemsInObjectGraph="10000000"/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
我的服務器配置如下所示:
<system.serviceModel>
<services>
<service name="GHMDatroseIntegration.GHMDatroseWCFService.DatroseService" behaviorConfiguration="DatroseServiceBehavior">
<endpoint contract="GHMDatroseIntegration.GHMDatroseWCFService.IDatroseService" binding="basicHttpBinding" address=""/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DatroseServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" httpsHelpPageEnabled="true" httpHelpPageEnabled="true"/>
<dataContractSerializer maxItemsInObjectGraph="10000000"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
我不再收到404錯誤。
但是,我確實得到了一個400(ProtocolException,Bad Request),沒有任何關於它得到的信息或為什么它不好的信息。 我希望我已經超越了端點問題,進入了全新的服務配置空間。
更新5
每個請求,我的服務的“骨架”(我假設接口會這樣做?):
[ServiceContract]
public interface IDatroseService
{
[OperationContract]
bool SubmitPayableTransaction(List<InvoiceItem> invoices);
[OperationContract]
Dictionary<string, bool> ValidateAccounts(List<string> accounts);
[OperationContract]
Dictionary<string, int> GetVendor1099Types(List<string> vendors);
[OperationContract]
Dictionary<string, string> GetPaymentTerms(List<string> vendors);
}
所以我假設您的服務是在IIS內托管的,對吧?
因此*.svc
所在的虛擬目錄基本上定義了您的服務地址 - 這個地址是否正確?
另外:您在服務端點上具有mex
“相對”地址
<endpoint
address="mex"
( 我認為這是一個非常糟糕的主意 - MEX代表元數據交換,我不會將該地址用於常規服務端點!它只是違反了最低驚喜原則 - 如果端點被稱為 MEX
,我希望它是BE元數據交換端點 - 不是常規服務端點...... )
無論如何 - 使用該常規地址,您的完整服務地址將變為:
http://yourserver/DatroseWCFService/DatroseService.svc/mex
如果您在該地址上撥打您的服務怎么辦?您會收到回復嗎?
更新:不確定您是如何嘗試測試的。
這是一個SOAP Web服務 - 您將在瀏覽器中看到服務的“登錄頁面”(“幫助”頁面),但是要測試服務本身,您需要使用支持SOAP的測試工具(如
WCF測試)客戶端或
SoapUI ) - 您無法通過瀏覽其Web地址來測試SOAP Web服務。
( 好吧,所以你通過從測試應用程序調用服務來測試它 - 這應該絕對有效! )
更新#2:因為您在IIS中托管它(對嗎?),您的服務地址基本上由* .svc文件所在的虛擬目錄定義。 所以我的下一次嘗試是:只需將該地址作為您的服務地址即可。
將服務端配置更改為:
<service name="GHMDatroseIntegration.GHMDatroseWCFService.DatroseService"
behaviorConfiguration="DatroseServiceBehavior">
<endpoint
address="" <!-- define nothing here - just let the *.svc file determine your service address -->
binding="basicHttpBinding"
contract="GHMDatroseIntegration.GHMDatroseWCFService.IDatroseService" />
<endpoint
address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
和您的客戶端配置 :
<endpoint name="BasicHttpBinding_IDatroseService"
address="http://localhost/DatroseWCFService/DatroseService.svc"
behaviorConfiguration="DatroseServiceBehavior"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IDatroseService"
contract="DatroseWCFService.IDatroseService" />
那樣有用嗎??
下一次嘗試是使用沒有bindingConfiguration=
值的客戶端配置 - 因為這也是你在服務器上所做的事情 - 只是絕對簡單的basicHttpBinding
而沒有任何修改 - 這basicHttpBinding
嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.