我正在尝试编写一个小型SOAP服务器,它连接到QuickBooks Web连接器,但是我找到正确的合同时遇到了一些麻烦。我总是得到以下错误:
网络连接器
由于ContractFilter,无法在接收方处理方法x EndpointDispatcher不匹配。这可能是因为a 合同不匹配(发送方和接收方之间不匹配的操作)或 发送方和接收方之间的绑定/安全性不匹配。 检查发件人和收件人是否具有相同的合同 绑定(包括安全要求,例如消息,传输, 无)。
我创建了一个空的ASP .NET Web应用程序并添加了一个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; }
}
响应
[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中,authenticate
type
有username
和password
两种基本类型。
如何使用QuickBooks Web Connector实现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)
答案 0 :(得分:3)
此答案描述了如何使用QuickBooks Web连接器(例如authenticate
方法)连接WCF服务。我不完全确定它是否是最好的实现,但它有效,我想帮助其他有类似问题的人。随时欢迎附魔和其他建议。
创建服务合同
[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;
}
}
authenticateResponse
[CollectionDataContractAttribute(Name = "ArrayOfString", Namespace = QuickBooks.URL, ItemName = "string")]
public class ArrayOfString : List<string>
{
}
此方案符合SOAP合同并允许数据交换。