![](/img/trans.png)
[英]WCF Error - Could not find default endpoint element that references contract
[英]WCF Error - Could not find default endpoint element that references contract 'UserService.UserService'
任何想法如何解決這一問題?
UserService.UserServiceClient userServiceClient = new UserServiceClient();
userServiceClient.GetUsersCompleted += new EventHandler<GetUsersCompletedEventArgs>(userServiceClient_GetUsersCompleted);
userServiceClient.GetUsersAsync(searchString);
。
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_UserService"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:52185/UserService.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_UserService"
contract="UserService.UserService"
name="BasicHttpBinding_UserService" />
</client>
<behaviors>
<serviceBehaviors>
<behavior name="Shell.Silverlight.Web.Service3Behavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<service behaviorConfiguration="Shell.Silverlight.Web.Service3Behavior"
name="Shell.Silverlight.Web.Service3">
<endpoint address=""
binding="basicHttpBinding"
contract="Shell.Silverlight.Web.Service3" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
無法在ServiceModel客戶端配置部分中找到引用合同“UserService.UserService”的默認端點元素。 這可能是因為沒有為您的應用程序找到配置文件,或者因為在客戶端元素中找不到與此合同匹配的端點元素。
解決!
我沒有提到這是一個Silverlight應用程序。 我在DLL中有wcf引用,它有自己的“ServiceReferences.ClientConfig”文件。 我將DLL的ServiceReferences.ClientConfig的內容移動到主Silverlight項目並且它工作了。
我遇到了同樣的問題。 我的應用程序也是一個Silverlight應用程序,該服務是從類庫中調用的,其中包含正在使用的自定義UserControl。
解決方案很簡單。 將端點定義從類庫的配置文件(例如ServiceReferences.ClientConfig)復制到silverlight應用程序的配置文件。 我知道你希望它能夠在不必這樣做的情況下工作,但顯然雷蒙德的某個人當天有個假期。
您還可以在類庫中以編程方式設置這些值,這樣可以避免配置文件在庫中不必要地移動。 簡單的BasciHttpBinding的示例代碼是 -
BasicHttpBinding basicHttpbinding = new BasicHttpBinding(BasicHttpSecurityMode.None);
basicHttpbinding.Name = "BasicHttpBinding_YourName";
basicHttpbinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
basicHttpbinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
EndpointAddress endpointAddress = new EndpointAddress("http://<Your machine>/Service1/Service1.svc");
Service1Client proxyClient = new Service1Client(basicHttpbinding,endpointAddress);
以防萬一在使用WPF(而不是WCF或Silverlight)時遇到同樣的問題:
連接到Web服務時出現此錯誤。 當我的代碼在“主要”WPF應用程序解決方案中,沒有問題,它完美地工作。 但是當我將代碼移動到更合理的DAL層解決方案時,它會拋出異常。
無法在ServiceModel客戶端配置部分中找到引用合同“MyWebService.MyServiceSoap”的默認端點元素。 這可能是因為沒有為您的應用程序找到配置文件,或者因為在客戶端元素中找不到與此合同匹配的端點元素。
正如此線程中“Sprite”所述,您需要手動復制標記。
對於WPF應用程序,這意味着復制從app.config中的標簽在我的DAL解決主WPF應用解決方案的app.config。
我遇到了同樣的問題,無論出於什么原因,當我第一次添加服務時,Visual Studio沒有更新Web配置。 我發現更新服務參考也解決了這個問題。
腳步:
將WCF服務的web.config更改為“endpoint address =”“binding =”basicHttpBinding“...”(先前綁定=“wsHttpBinding”)構建應用程序后,在“ServiceReferences.ClientConfig”中“”配置>具有該值。 然后它會正常工作。
將svcutil.exe生成的output.config重命名為app.config。 它對我有用。
你有一個“UserService”類實現的接口嗎?
您的端點應指定contract屬性的接口:
contract="UserService.IUserService"
不確定這是否是一個問題。 端點和綁定都具有相同的名稱
不確定它是否真的有問題,但我看到你的綁定配置名稱相同()。
我通常嘗試將我的端點稱為“UserServiceBasicHttp”或類似的東西(“Binding”在這里沒有任何事情要做),我嘗試用“.... Configuration”調用我的綁定配置,例如“UserServiceDefaultBinding”,以避免任何潛在的名稱沖突。
渣
當您通過其他應用程序使用您的服務時會出現此問題。如果應用程序有配置文件,只需將您的服務配置信息添加到此文件。 在我的情況下,沒有任何配置文件所以我使用這種技術,它工作正常。只需在應用程序中存儲url地址,讀取它並使用BasicHttpBinding()方法將其作為參數發送到服務應用程序。這是簡單的演示我是怎么做的它:
Configuration config = new Configuration(dataRowSet[0]["ServiceUrl"].ToString());
var remoteAddress = new System.ServiceModel.EndpointAddress(config.Url);
SimpleService.PayPointSoapClient client =
new SimpleService.PayPointSoapClient(new System.ServiceModel.BasicHttpBinding(),
remoteAddress);
SimpleService.AccountcredResponse response = client.AccountCred(request);
必須在調用App.config文件中添加服務才能使其正常工作。 畢竟確保你,但它。 這似乎對我有用。
對於那些使用AX 2012 AIF服務並嘗試在AX(x ++)內調用C#或VB項目並遭受“無法找到默認端點”的錯誤 ......或“找不到合同”的人 ...返回到您的visual studio(c#)項目並在定義服務客戶端之前添加這些行,然后部署項目並重新啟動AX客戶端並重試:注意,該示例適用於NetTcp適配器 ,您可以根據需要輕松使用任何其他適配器。
Uri Address = new Uri("net.tcp://your-server:Port>/DynamicsAx/Services/your-port-name");
NetTcpBinding Binding = new NetTcpBinding();
EndpointAddress EndPointAddr = new EndpointAddress(Address);
SalesOrderServiceClient Client = new SalesOrderServiceClient(Binding, EndPointAddr);
如果您使用PRISM框架使用WPF應用程序,則配置應該存在於您的啟動項目中(即在您的引導程序所在的項目中)。
簡而言之,只需將其從類庫中刪除並放入啟動項目即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.