【问题标题】:No matching contract between WCF Service and QuickBooks Web ConnectorWCF 服务和 QuickBooks Web 连接器之间没有匹配的合同
【发布时间】:2015-08-23 19:58:13
【问题描述】:

我正在尝试编写一个小型 SOAP 服务器,它连接到 QuickBooks Web 连接器,但我很难找到正确的合同。我总是收到以下错误:

网络连接器

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

我创建了一个空的 ASP .NET Web 应用程序并添加了一个 WCF 服务。您将在这里找到authenticate 方法的 sn-p:

WCF 服务接口

[ServiceContract]
public interface IQuickBooks
{
    [OperationContract]
    AuthenticateResponse authenticate(Authenticate authenticateSoapIn);
}

WCF 服务实现

public class QuickBooks : IQuickBooks
{
    public AuthenticateResponse authenticate(Authenticate authenticateSoapIn)
    {
        return new AuthenticateResponse
        {
            AuthenticateResult = new[] { "1", "none" }
        };
    }
}

请求

[DataContract(Name = "authenticate")]
public class Authenticate
{
    [DataMember(Name = "strUserName", IsRequired = true)]
    public string Username { get; set; }

    [DataMember(Name = "strPassword", IsRequired = true)]
    public string Password { get; set; }
}

回应

[DataContract(Name = "authenticateResponse")]
public class AuthenticateResponse
{
    [DataMember(Name = "authenticateResult", IsRequired = true)]
    public string[] AuthenticateResult { get; set; }
}

Here 你可以从 QuickBooks 和my WSDL 输出中找到 WSDL。请注意,我只实现了authenticate 方法进行测试。我猜wsdl:types 不匹配会导致错误。在来自 QuickBooks 的原始 WSDL 中,authenticatetype 有两种基本类型:usernamepassword

如何使用 QuickBooks Web 连接器实现 WCF 服务?我做错了什么?

其他信息

堆栈跟踪

The message with Action 'http://developer.intuit.com/authenticate' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver.  Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).
More info:
StackTrace =    at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   at QBWebConnector.localhost.WCWebServiceDoc.authenticate(String strUserName, String strPassword)
   at QBWebConnector.localhost.WCWebService.authenticate(String strUserName, String strPassword)
   at QBWebConnector.SOAPWebService.authenticate(String UserName, String Password)
   at QBWebConnector.WebService.do_authenticate(String& ticket, String& companyFileName)

【问题讨论】:

    标签: c# web-services wcf quickbooks connector


    【解决方案1】:

    此答案描述了如何使用 QuickBooks Web 连接器连接 WCF 服务(例如 authenticate 方法)。我不完全确定它是否是最好的实现,但它有效,我想帮助其他有类似问题的人。我们随时欢迎附魔和其他建议。

    1. 创建一个空的 ASP .NET Web 应用程序
    2. 添加 WCF 服务
    3. 定义服务合同
    4. 实现服务行为
    5. 定义必要的数据类型

    创建服务合同

    [ServiceContract(Namespace = QuickBooks.URL, Name = "QuickBooks")]
    public interface IQuickBooks
    {
        [OperationContract(Action = QuickBooks.URL + "authenticate")]
        AuthenticateResponse authenticate(Authenticate authenticateSoapIn);
    }
    

    创建服务行为

    [ServiceBehavior(Namespace = QuickBooks.URL)]
    public class QuickBooks : IQuickBooks
    {
        public const string URL = "http://developer.intuit.com/";
    
        public AuthenticateResponse authenticate(Authenticate authenticateSoapIn)
        {
            // Check if authenticateSoapIn is valid
    
            var authenticateResponse = new AuthenticateResponse();
            authenticateResponse.AuthenticateResult.Add(System.Guid.NewGuid().ToString());
            authenticateResponse.AuthenticateResult.Add(string.Empty);
    
            return authenticateResponse;
        }
    }
    

    实现请求和响应类型

    请求

    [DataContract(Name = "authenticate")]
    [MessageContract(WrapperName = "authenticate", IsWrapped = true)]
    public class Authenticate
    {
        [DataMember(Name = "strUserName", IsRequired = true)]
        [MessageBodyMember(Name = "strUserName", Order = 1)]
        public string Username { get; set; }
    
        [DataMember(Name = "strPassword", IsRequired = true)]
        [MessageBodyMember(Name = "strPassword", Order = 2)]
        public string Password { get; set; }
    
        public Authenticate()
        {
        }
    
        public Authenticate(string username, string password)
        {
            this.Username = username;
            this.Password = password;
        }
    }
    

    回应

    [DataContract(Name = "authenticateResponse")]
    [MessageContract(WrapperName = "authenticateResponse", IsWrapped = true)]
    public class AuthenticateResponse
    {
        [DataMember(Name = "authenticateResult", IsRequired = true)]
        [MessageBodyMember(Name = "authenticateResult", Order = 1)]
        public ArrayOfString AuthenticateResult { get; set; }
    
        public AuthenticateResponse()
        {
            this.AuthenticateResult = new ArrayOfString();
        }
    
        public AuthenticateResponse(ArrayOfString authenticateResult)
        {
            this.AuthenticateResult = authenticateResult;
        }
    }
    

    ArrayOfString 用于authenticateResponse

    [CollectionDataContractAttribute(Name = "ArrayOfString", Namespace = QuickBooks.URL, ItemName = "string")]
    public class ArrayOfString : List<string>
    {
    }
    

    此方案符合 SOAP 合同并允许数据交换。

    【讨论】:

      猜你喜欢
      • 2011-12-27
      • 2019-06-27
      • 2021-12-04
      • 1970-01-01
      • 2012-10-22
      • 2016-01-04
      • 2017-10-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多