2015-06-09 3 views
1

Я пытаюсь написать небольшой SOAP-сервер, который подключается к QuickBooks Web Connector, но у меня есть некоторые проблемы с поиском правильных контрактов. Я всегда получаю следующую ошибку:Подходящий контракт между WCF Service и QuickBooks Web Connector

Web Connector

Method x 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).

Я создал пустое веб-приложение ASP .NET и добавил службу WCF. Здесь вы найдете фрагмент из authenticate метода: Интерфейс

службы 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; } 
} 

Response

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

Here вы можете найти WSDL из QuickBooks и my WSDL-выход. Обратите внимание, что я применил только метод authenticate для тестирования. Я предполагаю, что ошибка wsdl:types вызывает ошибку. В исходном WSDL из QuickBooks authenticatetype имеет два примитивных типа для username и password.

Как я могу реализовать службу WCF с веб-коннектором QuickBooks? Что я не так?

Дополнительная информация

StackTrace

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) 

ответ

2

Этот ответ описывает, как подключить службы WCF с QuickBooks веб-коннектору (е. Г. authenticate метод). Я не совсем уверен, что это лучшая реализация, но она работает, и я хотел бы помочь другим людям с подобными проблемами. Чары и дополнительные предложения всегда приветствуются.

  1. Создать пустой ASP.NET Web Application
  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; 
    } 
} 

Response

[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 и позволяет осуществлять обмен данными.

Смежные вопросы