3

我正在尝试运行一个简单的 Web 服务,该服务会在被触发时发送电子邮件,但在尝试设置它时出现以下错误:

由于 EndpointDispatcher 中的 ContractFilter 不匹配,无法在接收方处理带有操作“localhost/IFabricService/StartMailRun”的消息。这可能是因为合约不匹配(发送方和接收方之间的操作不匹配)或发送方和接收方之间的绑定/安全不匹配。检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息、传输、无)。

我的服务编码如下:

namespace Project.Fabric
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IFabricService
{
    [OperationContract(IsOneWay=true)]
    void StartMailRun(int id, string customerGuid);

}


// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class CompositeType
{
    bool boolValue = true;
    string stringValue = "Hello ";

    [DataMember]
    public bool BoolValue
    {
        get { return boolValue; }
        set { boolValue = value; }
    }

    [DataMember]
    public string StringValue
    {
        get { return stringValue; }
        set { stringValue = value; }
    }
}

}

这是从名为 Project.Biz 的类库中调用的,文件名为 EmailBiz.cs,使用以下代码:

public void StartEmailRun(int id)
    {
        WS2007HttpBinding myBinding = new WS2007HttpBinding();
        myBinding.Security.Mode = SecurityMode.TransportWithMessageCredential;
        myBinding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate;

        // Create the endpoint address.
        EndpointAddress ea = new EndpointAddress("https://fabric.metalearning.net/FabricService.svc");

        // Create the client.                       
        MetaLearning.Fabric.Console.ServiceReference1.FabricServiceClient svc = new MetaLearning.Fabric.Console.ServiceReference1.FabricServiceClient(myBinding, ea);


        // Specify a certificate to use for authenticating the client.
        svc.ClientCredentials.ClientCertificate.SetCertificate(
        StoreLocation.LocalMachine,
        StoreName.My,
        X509FindType.FindByThumbprint,
        "thumbprinthere");

        // Begin using the client.
        try
        {
            svc.Open();
            //this will need changed to include correct string of GUID and correct ID for email campaign.
            svc.StartMailRun(id, "a67f8076-82c6-427c-ac34-fb34aee59e0b");
            System.Console.ReadLine();

            // Close the client.
            svc.Close();
        }
        catch (Exception ex)
        {
        }  
    }

Fabric 服务的 web.config 如下所示:

<system.serviceModel>
<services>
  <service behaviorConfiguration="ServiceCredentialsBehaviour" name="MetaLearning.Fabric.FabricService">
    <endpoint binding="ws2007HttpBinding" bindingConfiguration="WSHttpBinding_IFabricService" name="SecuredByClientCertificate" contract="MetaLearning.Fabric.IFabricService" />
  </service>
</services>
<bindings>
  <ws2007HttpBinding>
    <binding name="WSHttpBinding_IFabricService">
      <security mode="TransportWithMessageCredential">
        <message clientCredentialType="Certificate" />
      </security>
    <!--<security mode="Transport"> 
      <transport clientCredentialType="None" proxyCredentialType="None" realm=""/> 
      <message clientCredentialType="Certificate" algorithmSuite="Default" />
    </security>--> 
    </binding>
  </ws2007HttpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceCredentialsBehaviour">
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false" />
      <serviceMetadata httpsGetEnabled="true" />
      <serviceCredentials>
        <serviceCertificate findValue="thumbprinthere" x509FindType="FindByThumbprint" storeLocation="LocalMachine" />
      </serviceCredentials>
    </behavior>
  </serviceBehaviors>
</behaviors>
<protocolMapping>
    <add binding="ws2007HttpBinding" scheme="https" />
</protocolMapping>    
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="false" />

谁能看到我忽略的会导致此问题的内容?

4

0 回答 0