2011-08-08 50 views
1

我在項目中創建了WCF服務。現在使用Jquery,我成功地能夠使用服務,但是當我嘗試在Windows應用程序中添加服務作爲Web引用時,我無法調用它。如果我創建簡單的服務,我可以在Windows應用程序中成功調用,但是如果我做了更改以調用jQuery的服務,那麼通過執行一些Google搜索就可以找到它。我不知道我在哪裏失蹤。在Windows應用程序中使用WCF服務?

下面是我所做的代碼。 這是WCF的接口。

[ServiceContract] 
public interface ITestService 
{ 
    [OperationContract] 
    void DoWork(); 

    [OperationContract] 
    [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]  
    string HelloWorld(); 
} 

調用的類接口

public class TestService : ITestService 
{ 
    public void DoWork() 
    { 
    } 


    public string HelloWorld() 
    { 
     return "Hello World"; 
    } 
} 

}

,這裏是應用程序的Web配置。

<system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
      <behavior name="TestWCFBehavior"> 
       <serviceMetadata httpGetEnabled="true"/> 
       <serviceDebug includeExceptionDetailInFaults="false" /> 
      </behavior> 
     </serviceBehaviors> 
     <endpointBehaviors> 
     <behavior name="TestWCFBehavior"> 
      <webHttp/> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 

    <!--<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />--> 
    <services> 
    <service name="WebAppWithWCF.TestService" behaviorConfiguration="TestWCFBehavior"> 
     <endpoint address="" binding="webHttpBinding" contract="WebAppWithWCF.ITestService" behaviorConfiguration="TestWCFBehavior"/> 
    </service> 
    </services> 
</system.serviceModel> 

我已經做了一些嘗試和錯誤,但不能找到一種方法,到現在爲止...

請幫助...讓我知道,如果任何信息是從我的身邊缺少。

回答

2

webHttpBinding不公開元數據,因此您不能添加對它的引用。

基本上,添加服務引用特徵基於所謂的服務(通過元數據/WDSL曝光)的代理和類。

帶有wsHttpBinding或basicHttpBinding的服務都暴露您的服務的元數據。通常在您構建.NET到.NET客戶端 - 服務器應用程序時使用它們。

實現兩個結合:WCF Service with webHttpBinding-basicHttpBinding-wcHttpBinding

+0

我們可以添加多個綁定,這是非常方便,當我們想暴露於多件事情。謝謝Max。 – kunjee

+0

不客氣! – maxbeaudoin

相關問題