我在 ASMX 中有一个网络服务,我正在尝试创建一个监听器,这是我在 webservice.cs 文件中拥有的内容
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;
/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
class MyNotificationListener : NotificationBinding
{
[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public notificationsResponse Notifications(notifications n)
{
Method.SendMail("info@domain.com", "test@domain.com", "Here I am ", "I am loaded ", "", "");// This is to see if it loaded
notificationsResponse r = new notificationsResponse();
r.Ack = true;
return r;
}
}
在我的出站消息配置中,我像这样调用此 Web 服务 www.domain/webservice.asmx/Notification
但是当我加载此服务时,我看到以下内容:
`System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Web.Services.Protocols.HttpServerType..ctor(Type type)
at System.Web.Services.Protocols.HttpServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)`
在我的配置文件中有以下内容
`<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
<add name="HttpSoap" />
</protocols>
</webServices>`
这是我在通知对象中的内容,它是按照 this 中的指示使用 wsdl.exe 从 WSDL 文件生成到类的例子。
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.7.3081.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://soap.sforce.com/2005/09/outbound")]
public partial class notifications
{
private string organizationIdField;
private string actionIdField;
private string sessionIdField;
private string enterpriseUrlField;
private string partnerUrlField;
private LeadNotification[] notificationField;
/// <remarks/>
public string OrganizationId {
get {
return this.organizationIdField;
}
set {
this.organizationIdField = value;
}
}
/// <remarks/>
public string ActionId {
get {
return this.actionIdField;
}
set {
this.actionIdField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
public string SessionId {
get {
return this.sessionIdField;
}
set {
this.sessionIdField = value;
}
}
/// <remarks/>
public string EnterpriseUrl {
get {
return this.enterpriseUrlField;
}
set {
this.enterpriseUrlField = value;
}
}
/// <remarks/>
public string PartnerUrl {
get {
return this.partnerUrlField;
}
set {
this.partnerUrlField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Notification")]
public LeadNotification[] Notification {
get {
return this.notificationField;
}
set {
this.notificationField = value;
}
}
}
最佳答案
因此,在查看您的代码后,我发现在您的 Web 服务中,公共(public)接口(interface)的实现被命名为错误,当我使用来自 salesforce 的 WSDL 生成类时,它创建了接口(interface)及其命名的 INotificationBinding
不是 NotificationBinding
,这让我认为您没有从 wsdl 正确创建类,在上面显示的示例中,您正在关注使用 wsdl.exe/serverInterface 线索。 wsdl
.
您是否使用 wsdl.exe 创建了上述类通知?如果是这样,您是否确保它使用的是 /serverInterface
选项,这很重要(见下图),在 salesforce 上它清楚地提到你需要实现一个调用通知接口(interface)的类,如果处理不当,它将给出 System.IndexOutOfRangeException
请使用服务器接口(interface)选项重试。那应该可以解决问题。
关于c# - SalesForce 出站消息监听器上的 System.IndexOutOfRangeException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55046970/