3
我遵循一些指導,在我的Windows應用程序中使用WCF服務。 我的WCF服務對我的移動應用程序運行良好,但我無法在Windows應用程序中使用它。消費WCF服務 - 找不到默認的終端元素
當我嘗試運行代碼生成的錯誤是:
找不到,在ServiceModel客戶端配置單元參考合同「AllocationService.IAllocatingService」默認終結點元素。這可能是因爲沒有找到適用於您的應用程序的配置文件,或者因爲在客戶端元素中找不到匹配此合同的端點元素。
調用Web服務方法:
AllocationService.AllocatingServiceClient client = new AllocationService.AllocatingServiceClient();
client.notifyZoneChanged(1);
Web服務端:
[OperationContract]
void notifyZoneChanged(int LocationID);
Web服務的web.config:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="PCSDB" connectionString="Data Source=alj6d2eqa0.database.windows.net;Initial Catalog=StaffAllocatorDB;Persist Security Info=True;User ID=---;Password=---" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name ="StaffAllocator.AllocatingService">
<endpoint address="" behaviorConfiguration="AllocationBehavior" binding="webHttpBinding" bindingConfiguration="" contract="StaffAllocator.IAllocatingService">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- 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>
<endpointBehaviors>
<behavior name="AllocationBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
App.config中的Windows應用程序:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="PCSDB" connectionString="Data Source=alj6d2eqa0.database.windows.net;Initial Catalog=StaffAllocatorDB;Persist Security Info=True;User ID=---;Password=---" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="AllocationBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<endpoint Name="Default"
address="http://staffallocatingsystem.cloudapp.net/AllocatingService.svc"
binding="webHttpBinding"
behaviorConfiguration="AllocationBehavior"
contract="AllocationService.IAllocatingService" />
</system.serviceModel>
</configuration>
我剛纔試過這個IIS虛擬目錄,您
*.svc
文件的生活,和*.svc
文件本身的名稱(包括擴展名),它給了我同樣的錯誤,我更新了線程,腠你看看嗎? –我得到了 >>'System.ServiceModel.Diagnostics.TraceUtility'的類型初始值設定項引發了一個異常。 對不起,我真的不知道任何關於配置文件 –
@BloopieBloops:這是完全不相關的東西....儘量減少你的客戶端配置到最低限度 - 正如我在我的迴應中顯示的。有一個''節點沒有意義,你也不需要'和''節點 - 當我把端點名稱放入服務器端 –