2012-04-22 54 views
0

我试图让我的WCF服务,让他们能够通过代理客户端,并通过REST调用被称为操作,我使用了以下配置:WCF多个端点不工作

<services> 
    <service behaviorConfiguration="SecureBehavior" name="Payment"> 
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="secureWS" contract="IPayment"/> 
    <endpoint address="rest" binding="webHttpBinding" behaviorConfiguration="webBehavior" contract="IPayment"/> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
    </service> 
    <bindings> 
    <mexHttpBinding> 
     <binding name="userMex"/> 
    </mexHttpBinding> 
    <wsHttpBinding> 
     <binding name="secureWS"> 
     <security mode="Message"> 
      <message clientCredentialType="Windows" negotiateServiceCredential="true" establishSecurityContext="true"/> 
     </security> 
     </binding> 
     <binding name="publicWS"> 
     <security mode="None"/> 
     </binding> 
    </wsHttpBinding> 
    </bindings> 
    <behaviors> 
    <serviceBehaviors> 
     <behavior name="SecureBehavior"> 
     <serviceMetadata httpGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="true"/> 
     <serviceCredentials> 
      <windowsAuthentication allowAnonymousLogons="false"/> 
     </serviceCredentials> 
     </behavior> 
     <behavior name="PublicBehavior"> 
     <serviceMetadata httpGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="true"/> 
     <serviceCredentials> 
      <windowsAuthentication allowAnonymousLogons="true"/> 
     </serviceCredentials> 
     </behavior> 
    </serviceBehaviors> 
    <endpointBehaviors> 
     <behavior name="webBehavior"> 
     <webHttp/> 
     </behavior> 
    </endpointBehaviors> 
    </behaviors> 
</services> 

,这里是我的代码:

[ServiceContract] 
public interface IPayment 
{ 
    [OperationContract] 
    PaymentResult Finalize(string TransactionID, string CertificatePath); 

    [OperationContract] 
    [WebGet(UriTemplate = "rest")] 
    System.IO.Stream GetPayment(); 
} 

现在,每当我跑我的服务,我收到此错误:

Operation 'Finalize' of contract 'IPayment' specifies multiple request body parameters to be serialized without any wrapper elements. At most one body parameter can be serialized without wrapper elements. Either remove the extra body parameters or set the BodyStyle property on the WebGetAttribute/WebInvokeAttribute to Wrapped.

其中h我想保持Finalize操作只能通过.NET客户端调用,并且可以通过任何浏览器调用GetPayment操作。

回答

0

如果您不希望从通过webhttp端点连接的客户端调用Finalize方法,并且您不希望从通过wshttp连接的客户端调用GetPayments,则可以简单地将您的合同分成两部分。

假设你在IIS中托管,你可能需要做一些小技巧来确保它能正常工作。让我利用这个问题的细节给你举个例子...

的一切都在这里首先是两个服务代码...

[ServiceContract] 
public interface IPayment 
{ 
    [OperationContract] 
    [WebGet(UriTemplate = "rest")] 
    System.IO.Stream GetPayment(); 
} 

[DataContract] 
public class PaymentResult 
{ 
} 

[ServiceContract] 
public interface IMakePayment 
{ 
    [OperationContract] 
    PaymentResult Finalize(string TransactionID, string CertificatePath); 
} 

// Maybe you really should have the two services separate but if you do 
// want to implement them both in a single class you can do this 
public abstract class PaymentBase : IMakePayment, IPayment 
{ 
    // ... Implement both interfaces here 
    public PaymentResult Finalize(string TransactionID, string CertificatePath) 
    { 
     return null; 
    } 

    public System.IO.Stream GetPayment() 
    { 
     return null; 
    } 
} 

public class MakePayment : PaymentBase 
{ 
    // Empty 
} 

public class Payment : PaymentBase 
{ 
    // Empty 
} 

现在创建两个文件的.svc像这样:

MakePayment.svc

<%@ ServiceHost Language="C#" Debug="true" Service="WebApplication1.MakePayment" %> 

Payment.svc

<%@ ServiceHost Language="C#" Debug="true" Service="WebApplication1.Payment" %> 

最后这里是system.servicemodel配置:

<system.serviceModel> 
    <services>  
    <service behaviorConfiguration="SecureBehavior" name="WebApplication1.MakePayment">   
     <endpoint binding="wsHttpBinding" bindingConfiguration="secureWS" contract="WebApplication1.IMakePayment"/> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" bindingConfiguration="userMex"/> 
    </service> 
    <service behaviorConfiguration="PublicBehavior" name="WebApplication1.Payment"> 
     <endpoint binding="webHttpBinding" behaviorConfiguration="webBehavior" bindingConfiguration="publicWS" contract="WebApplication1.IPayment"/> 
    </service>  
    </services> 
    <bindings> 
    <mexHttpBinding> 
     <binding name="userMex"/> 
    </mexHttpBinding> 
    <wsHttpBinding> 
     <binding name="secureWS"> 
     <security mode="Message"> 
      <message clientCredentialType="Windows" negotiateServiceCredential="true" establishSecurityContext="true"/> 
     </security> 
     </binding> 
    </wsHttpBinding> 
    <webHttpBinding> 
     <binding name="publicWS"> 
     <security mode="None"/> 
     </binding> 
    </webHttpBinding> 
    </bindings> 
    <behaviors> 
    <serviceBehaviors> 
     <behavior name="SecureBehavior"> 
     <serviceMetadata httpGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="true"/> 
     <serviceCredentials> 
      <windowsAuthentication allowAnonymousLogons="false"/> 
     </serviceCredentials> 
     </behavior> 
     <behavior name="PublicBehavior"> 
     <serviceMetadata httpGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="true"/> 
     <serviceCredentials> 
      <windowsAuthentication allowAnonymousLogons="true"/> 
     </serviceCredentials> 
     </behavior> 
    </serviceBehaviors> 
    <endpointBehaviors> 
     <behavior name="webBehavior"> 
     <webHttp/> 
     </behavior> 
    </endpointBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
</system.serviceModel> 

那里你去 - 如果你连接到/MakePayment.svc您将通过WSHTTP连接,并能够调用FinalizePayment,如果你去/Payments.svc/rest它会调用你正在返回一个流的GetPayment方法。

+0

我这样做了,但现在有一个新的错误:没有找到端点,任何想法? – akkad 2012-04-24 06:30:24

+0

更新了一个更具体的例子 – kmp 2012-04-24 07:56:24

+0

现在我迷失了:) 让我遍历你的代码并看看,无论如何谢谢。 – akkad 2012-04-24 09:10:25