2011-04-13 92 views
4

您好,非常感謝您的閱讀。IIS 7.5中的REST/SOAP端點的WCF 4服務

我想獲得一個服務託管在IIS 7.5,有多個端點公開。

我有一種感覺問題在於我的web.config,但我會在這裏發佈我的服務代碼。沒有接口文件,因爲我使用WCF 4的新功能,也沒有.svc文件。

根據我的理解,所有的路由都使用RouteTable功能在Global.asax.cs中處理。

無論如何,到代碼/配置 -

[ServiceContract] 
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] 
// NOTE: If the service is renamed, remember to update the global.asax.cs file 
public class Service1 
{ 
    // TODO: Implement the collection resource that will contain the SampleItem instances 

    [WebGet(UriTemplate = "HelloWorld")] 
    public string HelloWorld() 
    { 
     // TODO: Replace the current implementation to return a collection of SampleItem instances 
     return "Hello World!"; 
    } 
} 

而現在,配置和我認爲需要作出(我不知道如果我需要保持standardEndpoints阻塞的變化,但有或沒有它,我仍然得到錯誤信息 -

<services> 
    <service name="AiSynthDocSvc.Service1" behaviorConfiguration="HttpGetMetadata"> 
    <endpoint name="rest" 
       address="" 
       binding="webHttpBinding" 
       contract="AiSynthDocSvc.Service1" 
       behaviorConfiguration="REST" /> 
    <endpoint name="soap" 
       address="soap" 
       binding="basicHttpBinding" 
       contract="AiSynthDocSvc.Service1" /> 
    <endpoint name="mex" 
       address="mex" 
       binding="mexHttpBinding" 
       contract="IMetadataExchange" /> 
    </service> 
</services>  

<behaviors> 
    <endpointBehaviors> 
    <behavior name="REST"> 
     <webHttp/> 
    </behavior> 
    </endpointBehaviors> 
    <serviceBehaviors> 
    <behavior name="HttpGetMetadata"> 
     <serviceMetadata httpGetEnabled="true" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 

<standardEndpoints> 
    <webHttpEndpoint> 
    <!-- 
     Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
     via the attributes on the <standardEndpoint> element below 
    --> 
    <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/> 
    </webHttpEndpoint> 
</standardEndpoints> 

的的Global.asax.cs文件被單獨留在家中

再次我敢肯定它是與我的配置。 Ť當我嘗試訪問任何定義的端點時,他遇到的錯誤是 -

''處的端點沒有與無消息版本的綁定。 'System.ServiceModel.Description.WebHttpBehavior'僅用於WebHttpBinding或類似的綁定。

任何人對此有任何意見?

感謝,

扎卡里·卡特

+0

你用什麼URL來訪問你的服務? – 2011-04-13 15:49:45

+0

另外:你說你沒有* .svc文件 - 你的服務如何激活呢?您可能需要* .svc文件,或者您需要在配置文件中添加標籤。 – 2011-04-13 15:50:51

+0

該服務被部署到端口80上的默認網站,因此它只是 - http:// localhost/WebApp/ServiceName來訪問它。另外,在沒有.svc文件的情況下創建服務的功能是.NET 4.0中的一項新功能。不是擊中svc文件,而是添加了一個新類,以將請求正確路由到相應的服務。 – 2011-04-13 16:58:59

回答

7

OK,我試圖複製你的東西 - 就像我的一個魅力:-)

  • 我用你的服務類 - 沒有改變
  • 我用你的RegisterRoutes致電global.asax.cs

當我在Visual Studio中啓動Web應用程序時,我得到了卡西尼(內置Web服務器)http://localhost:3131/ - 這可能會對您的情況有所警惕。現在

,我可以很容易地與另一個瀏覽器窗口導航那裏,我得到這個URL簡單地回答:

http://localhost:3131/Service1/HelloWorld 
+--------------------+ 
from Cassini 
        +--------+ 
        name (first param) in ServiceRoute registration 
           +-----------+ 
           from your URI template on the WebGet attribute 

爲你做同樣的網址工作?

更新:這裏是我的配置 - 我可以使用REST連接到http://localhost:3131/Service1/HelloWorld在瀏覽器中,我可以與WCF測試客戶端連接到http://localhost:3131/Service1/soap做出SOAP調用(我Service1生活在RestWebApp命名空間 - 這樣我服務和合同的名稱是比你不同的一點點 - 但除此之外,我認爲這是等同於你自己的配置):

<system.serviceModel> 
    <serviceHostingEnvironment  
     aspNetCompatibilityEnabled="true" /> 
    <services> 
     <service name="RestWebApp.Service1" behaviorConfiguration="Meta"> 
     <endpoint name="rest" 
        address="" 
        binding="webHttpBinding" 
        contract="RestWebApp.Service1" 
        behaviorConfiguration="REST" /> 
     <endpoint name="SOAP" 
      address="soap" 
      binding="basicHttpBinding" 
      contract="RestWebApp.Service1" /> 
     <endpoint name="mex" 
      address="mex" 
      binding="mexHttpBinding" 
      contract="IMetadataExchange" /> 
     </service> 
    </services> 
    <behaviors> 
     <endpointBehaviors> 
     <behavior name="REST"> 
      <webHttp/> 
     </behavior> 
     </endpointBehaviors> 
     <serviceBehaviors> 
     <behavior name="Meta"> 
      <serviceMetadata httpGetEnabled="true" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <standardEndpoints> 
     <webHttpEndpoint> 
     <!-- 
     Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
     via the attributes on the <standardEndpoint> element below 
     --> 
     <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/> 
     </webHttpEndpoint> 
    </standardEndpoints> 
    </system.serviceModel> 
+0

馬克,它絕對如果我離開配置文件。我的問題是,當我嘗試公開一個配置爲使用basicHttpBinding的附加端點時,原始的REST端點會伸出,並且新發現的端點也無法找到。 – 2011-04-13 19:25:13

+0

我SOAP端點的樣子 - <端點名稱= 「肥皂」 地址= 「肥皂」 綁定= 「basicHttpBinding的」 合同= 「AiSynthDocSvc.Service1」/> 但導航到http://本地主機:80 /服務1/soap產生以下錯誤消息 - 'http://vm-scctest.amcad.com/AiSynthDocSvc/Service1/soap'上的端點沒有與無消息版本的綁定。 'System.ServiceModel.Description.WebHttpBehavior'僅用於WebHttpBinding或類似的綁定。 – 2011-04-13 19:34:19

+0

我再次想到這與服務有一個行爲配置設置爲webHttpBinding和端點行爲配置設置爲使用basicHttpBinding。 – 2011-04-13 19:34:54

0

感謝這一點,對我幫助很大。

我的情況是,我有一個默認行爲配置,其中包含webHttp。給它的名稱=「REST」並設置我的webHttpBinding端點behaviourConfiguration =「REST」我沒有進一步的錯誤。

<system.serviceModel> 
<bindings> 
    <customBinding> 
    <binding name="CustomBinding_IMobileService"> 
     <binaryMessageEncoding /> 
     <httpTransport /> 
    </binding> 
    </customBinding> 
</bindings> 
<client> 
    <endpoint address="http://localhost:6862/silverlight/services/MobileService.svc" 
    binding="customBinding" bindingConfiguration="CustomBinding_IMobileService" 
    contract="AlchemyMobileService.IMobileService" name="CustomBinding_IMobileService" /> 
</client> 
<services> 
    <service name="MobileService.Alchemy"> 
    <endpoint address="http://localhost:8732/mobileservice" binding="webHttpBinding" contract="MobileService.IAlchemy" behaviorConfiguration="REST"> 
    </endpoint> 
    </service> 
</services> 
<behaviors> 
    <serviceBehaviors> 
    <behavior> 
     <serviceDebug includeExceptionDetailInFaults="True" /> 
    </behavior> 
    </serviceBehaviors> 
    <endpointBehaviors> 
    <behavior name="REST"> 
     <webHttp /> 
    </behavior> 
    </endpointBehaviors> 
</behaviors>