2011-05-13 75 views
0

我使用jQuery通過以下鏈接成功使用WCF服務:http://www.codeproject.com/KB/aspnet/WCF_JQUERY_ASMX.aspxWCF:使用jQuery消耗WCF服務,也可以在Windows應用程序

我只是做了我的POCO實體進行一些修改,以正確序列化。如果jQuery使用或使用瀏覽器查看(改變動詞獲取),一切工作正常。

現在我創建了一個Windows應用程序並添加了對此服務的服務引用。它成功完成,我可以看到類/方法和所有。但是,當我嘗試運行該應用程序時,出現以下錯誤:

「在ServiceModel客戶端配置部分找不到引用contract [ContractName]的默認端點元素,這可能是因爲找不到配置文件您的應用程序,或者因爲在客戶端元素中找不到與此合同匹配的端點元素。「

基於這個錯誤,我想我應該創建另一個端點來迎合非http應用程序?我真的不知道它是如何工作,但..

這裏是我的webconfig

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <connectionStrings> 
    <add name="EntityDataModelContainer" connectionString="metadata=res://*/EntityDataModel.csdl|res://*/EntityDataModel.ssdl|res://*/EntityDataModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=bdowrmg01;Initial Catalog=ORMU_Prototype;user=sa;password=Password1;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" /> 
    </connectionStrings> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="ORMDefaultServiceBehavior"> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
     </serviceBehaviors> 
     <endpointBehaviors> 
     <behavior name="ORMDefaultServiceBehavior"> 
      <webHttp/> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    <services> 
     <service behaviorConfiguration="ORMDefaultServiceBehavior" 
       name="ORM.Business.KCSA"> 
     <endpoint address="" binding="webHttpBinding" 
      contract="ORM.Business.IKCSA" 
      behaviorConfiguration="ORMDefaultServiceBehavior"/> 
     </service> 
    </services> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true" /> 
    </system.webServer> 
</configuration> 

而且,這裏的合同:

[ServiceContract] 
public interface IKCSA 
{ 
    [OperationContract] 
    [ApplyDataContractResolver] 
    [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped,Method="GET",ResponseFormat=WebMessageFormat.Json)] 
    JsonResponse<IEnumerable<KCSATopic>> GetTopics(); 
} 
+0

這只是一個可怕的努力來承載一個單一的Web服務。你應該看看http://servicestack.net,在那裏你可以花費更少的精力來構建一個完整的應用程序來配置一個WCF應用程序。檢出完整的TODO應用程序http://www.servicestack.net/Backbone.Todos/和整個.cs源代碼http://goo.gl/zA6hD – mythz 2011-05-13 10:09:01

回答

1

服務只引用與SOAP的Web服務的工作(通過一個WSDL定義),而不是Web HTTP(又名REST)服務,這就是你所擁有的。

因此,您需要使用HttpWebRequest類來使用您的服務,或者向wsHttpBinding類型的服務添加另一個綁定。

相關問題