2012-11-28 10 views
5

Sto sviluppando un servizio WCF con C# e .NET Framework 4.0.basicHttpBinding e webHttpBinding together

sto usando webHttpBinding per fare questo:

[OperationContract] 
[WebInvoke(Method = "POST", 
    ResponseFormat = WebMessageFormat.Json, 
    BodyStyle = WebMessageBodyStyle.Bare, 
    UriTemplate = "filteredOrders/")] 
OrderContract[] GetOrders(IdsMessage msg); 

[OperationContract] 
[WebInvoke(Method = "POST", 
    ResponseFormat = WebMessageFormat.Json, 
    BodyStyle = WebMessageBodyStyle.Bare, 
    UriTemplate = "completeFilteredOrders/")] 
OrderContract[] LoadCompleteFilteredOrders(IdsMessage msg); 

Ma ora ho bisogno di inviare le immagini a quel servizio Web utilizzando streamming e ho bisogno di aggiungere basicHttpBinding per farlo.

Come posso fare un nuovo [OperationContract] a questo servizio Web WCF che utilizza basicHttpBinding?

Siamo spiacenti, sono molto nuovo sullo sviluppo di WCF.

Tra l'altro, questo è il mio web.config:

<configuration> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 
    <services> 
     <service name="EReportService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour"> 
     <endpoint address="" binding="webHttpBinding" contract="EReportService.IRestServiceImpl" behaviorConfiguration="web"> 
     </endpoint> 
     </service> 
    </services> 
    <bindings> 
     <webHttpBinding> 
     <binding maxReceivedMessageSize="2097152" maxBufferSize="2097152" transferMode="Streamed"/> 
     </webHttpBinding> 
    </bindings> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="ServiceBehaviour"> 
      <serviceMetadata httpGetEnabled="true"/>  
      <serviceDebug includeExceptionDetailInFaults="true"/> 
     </behavior> 
     </serviceBehaviors> 
     <endpointBehaviors> 
     <behavior name="web"> 
      <webHttp/> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
    <connectionStrings> 

    </connectionStrings> 
</configuration> 
+1

Una possibile soluzione: http://debugmode.net/2011/12/22/how-to-enable-rest-and-soap-both-on-the-same-wcf-service/ – VansFannel

risposta

8

basta creare un altro endpoint utilizzando un indirizzo diverso (due punti finali non possono condividere lo stesso indirizzo) - è possibile modificare la vigente OperationContract per creare i metodi non RESTful.

<system.serviceModel> 
    <services> 
     <service name="EReportService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour"> 
     <endpoint address="" binding="webHttpBinding" contract="EReportService.IRestServiceImpl" behaviorConfiguration="web"> 
     </endpoint> 
     <endpoint address="soap" binding="basicHttpBinding" contract="EReportService.IRestServiceImpl" > 
     </endpoint> 
     </service> 
    </services> 
</system.serviceModel> 
Problemi correlati