2010-09-01 15 views
1

我創建了一個WCf服務,它具有一個可以使用WebGET屬性接收GET請求的方法,我希望同樣的方法也可以接收Soap調用(當程序員對WCF執行服務引用時,他將能夠調用該方法)。接收GET和SOAP請求的WCF方法

我的界面:

[ServiceContract] 
public interface IService1 
{ 
    [OperationContract] 
    [WebGet(UriTemplate = "GetData?value={value}")] 
    string GetData(int value); 
} 

我的配置是:

<configuration> 
<system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
</system.web> 
<system.serviceModel> 
    <behaviors> 
    <serviceBehaviors>  
    <behavior name="MyServiceBehavior"> 
    <serviceMetadata httpGetEnabled="true"/> 
    <serviceDebug includeExceptionDetailInFaults="true"/> 
    </behavior> 
    </serviceBehaviors> 
    <endpointBehaviors> 
    <behavior name="WebBehavior"> 
    <webHttp /> 
    </behavior> 
    </endpointBehaviors> 
    </behaviors> 
    <services> 
    <service name="WCFTestingGetService.Service1" behaviorConfiguration="MyServiceBehavior" > 
    <endpoint address="" binding="webHttpBinding" contract="WCFTestingGetService.IService1" behaviorConfiguration="WebBehavior"></endpoint> 
    </service> 
    </services> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
</system.serviceModel> 
<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
</system.webServer> 
</configuration> 

我可以讓德Web方法的GetData一個HTTP GET和SOAP的方法?

我需要將什麼添加到配置?

回答

1

您可以使用REST和SOAP在相同的服務,但在SOAP操作將HTTP POST被調用的情況。您的合同定義正確。您必須修改您的配置:

<services> 
    <service name="WCFTestingGetService.Service1" behaviorConfiguration="MyServiceBehavior" > 
    <endpoint address="" binding="webHttpBinding" contract="WCFTestingGetService.IService1" behaviorConfiguration="WebBehavior"/> 
    <endpoint address="soap" binding="basicHttpBinding" contract="WCFTestingGetService.IService1"/> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    </service> 
    </services> 
-1

我會刪除webget屬性並使用basichttpbinding。然後,您可以使用任何soap或wcf客戶端訪問該服務。

除了svc,你也可以託管一個asmx,但是這並不安靜。

問候,

米歇爾

+0

我刪除了Webget屬性並使用了Basichttpbinding,現在WCFtestClient不起作用。 我的配置是: <端點地址= 「」 綁定= 「basicHttpBinding的」 合同= 「WCFTestingGetService.IService1」 behaviorConfiguration = 「WebBehavior」> 是它好嗎? 如果我刪除Webget,我可以使用瀏覽器工作嗎? – Rodniko 2010-09-01 08:19:53

+0

還要添加,並確保在servicebehavior部分有這個: 2010-09-01 08:32:32