调用简单服务失败,显示错误的错误消息

时间:2015-06-05 17:51:23

标签: c# wcf

当我调用此服务时,收到此错误消息:

  

ContractDescription没有任何操作;合同必须至少有   一次操作

因为我的界面函数定义了[OperationContract()]属性,所以没有任何意义。

界面:

[ServiceContract()]
public interface ITest
{

    [OperationContract()]
    bool Connect(string password);

}

SVC:

<%@ ServiceHost Language="CS" Debug="true" Service="TestService.Test" CodeBehind="Test.svc.cs" %>

svc.cs:

public class Test : ITest
{

public bool Connect(string password)
{
    return true;
}

}

电话: 配置是以编程方式定义的,因为它是一个库

public sealed class Validator
{

    public static bool Connect(string password)
    {
        return ObtenirCLient().Connect(password);
    }

    private static LicensingService.LLMrqLicensingClient ObtenirCLient()
    {
        dynamic endpoint = new EndpointAddress("http://localhost/TestService/Test.svc");
        LicensingService.LLMrqLicensingClient client = new LicensingService.LLMrqLicensingClient(ObtenirBinding(), endpoint);

        client.Endpoint.Name = "LicHttp";
        client.Endpoint.Contract = new Description.ContractDescription("TestService.ITest");

        return client;
    }

    private static BasicHttpBinding ObtenirBinding()
    {
        return new BasicHttpBinding {
            Name = "LicHttp",
            Security = ObtenirSecurity()
        };
    }

    private static BasicHttpSecurity ObtenirSecurity()
    {
        return new BasicHttpSecurity {
            Mode = BasicHttpSecurityMode.TransportCredentialOnly,
            Transport = ObtenirTransport()
        };
    }

    private static HttpTransportSecurity ObtenirTransport()
    {
        return new HttpTransportSecurity { ClientCredentialType = HttpClientCredentialType.Windows };
    }

}

如果您发现任何奇怪的内容,请告诉我们!

1 个答案:

答案 0 :(得分:5)

而不是

client.Endpoint.Contract = new Description.ContractDescription("TestService.ITest");

试试这个:

client.Endpoint.Contract = ContractDescription.GetContract(typeof(ITest));
相关问题