我在ASMX中有一个Web服务,我正在尝试创建一个侦听器,这就是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;
}
}
在我的outboun消息配置中,我像这样www.domain/webservice.asmx/Notification
调用此Web服务,但是在加载此服务时,我看到以下内容:
`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>`
这是我在Notification Object中所拥有的,这是根据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;
}
}
}
答案 0 :(得分:2)
因此,查看您的代码后,我发现在您的Web服务中,公共接口的实现被命名为错误,当我使用来自salesforce的WSDL生成Class时,它将创建该接口,其命名为INotificationBinding
而不是{ {1}}使我认为您没有从wsdl中正确创建类,在上面显示的示例中,您正在遵循的示例说要使用NotificationBinding
。
您是否使用wsdl.exe创建了上述类通知?如果是,您是否确定它使用的是wsdl.exe /serverInterface leads.wsdl
这个选项很重要(请参见下图),在salesforce上明确提到您需要实现一个类来调用通知接口处理不当会导致错误/serverInterface
请使用serverinterface选项重试。那应该解决问题。
答案 1 :(得分:-1)
我认为您无法达到此方法,因为您尝试传递一个对象:“ notifications n” 并使用GET请求。 您无法对此方法执行GET操作。 无论如何,您描述的异常似乎并不相关。它在您的代码中。 尝试共享您用来使用此服务的代码