首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Salesforce出站消息的合同优先WCF

Salesforce出站消息的合同优先WCF
EN

Stack Overflow用户
提问于 2012-02-07 08:58:17
回答 5查看 3.2K关注 0票数 17

我正在考虑为Salesforce Outbound Messaging实现侦听器应用程序。

walk through 使用过时的ASMX web服务实现它。代码是使用带有/serverInterface开关的wsdl.exe生成的。

下面是Salesforce出站消息的wsdl。

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>

<definitions targetNamespace="http://soap.sforce.com/2005/09/outbound"
   xmlns="http://schemas.xmlsoap.org/wsdl/"
   xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
   xmlns:tns="http://soap.sforce.com/2005/09/outbound"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns:ent="urn:enterprise.soap.sforce.com"
   xmlns:ens="urn:sobject.enterprise.soap.sforce.com">
<types>

    <schema elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:enterprise.soap.sforce.com">
        <!-- Our simple ID Type -->
        <simpleType name="ID">
            <restriction base="xsd:string">
                <length value="18"/>
                <pattern value='[a-zA-Z0-9]{18}'/>
            </restriction>
        </simpleType>
    </schema>

    <schema elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:sobject.enterprise.soap.sforce.com">
        <import namespace="urn:enterprise.soap.sforce.com" />
        <!-- Base sObject (abstract) -->
        <complexType name="sObject">
            <sequence>
                <element name="fieldsToNull" type="xsd:string" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
                <element name="Id" type="ent:ID" nillable="true" />
            </sequence>
        </complexType>

        <complexType name="AggregateResult">
            <complexContent>
                <extension base="ens:sObject">
                    <sequence>
                        <any namespace="##targetNamespace" minOccurs="0" maxOccurs="unbounded" processContents="lax"/>
                    </sequence>
                </extension>
            </complexContent>
        </complexType>

        <complexType name="Contact">
            <complexContent>
                <extension base="ens:sObject">
                    <sequence>
                    <element name="Email" nillable="true" minOccurs="0" type="xsd:string"/>
                    <element name="FirstName" nillable="true" minOccurs="0" type="xsd:string"/>
                    <element name="LastName" nillable="true" minOccurs="0" type="xsd:string"/>
                    </sequence>
                </extension>
            </complexContent>
        </complexType>
    </schema>

    <schema elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://soap.sforce.com/2005/09/outbound">
        <import namespace="urn:enterprise.soap.sforce.com" />
        <import namespace="urn:sobject.enterprise.soap.sforce.com" />

        <element name="notifications">
            <complexType> 
                <sequence> 
                    <element name="OrganizationId" type="ent:ID" />
                    <element name="ActionId" type="ent:ID" />
                    <element name="SessionId" type="xsd:string" nillable="true" />
                    <element name="EnterpriseUrl" type="xsd:string" />
                    <element name="PartnerUrl" type="xsd:string" />
                    <element name="Notification" maxOccurs="100" type="tns:ContactNotification" />
                </sequence> 
            </complexType> 
        </element>

        <complexType name="ContactNotification">
            <sequence>
                <element name="Id" type="ent:ID" />
                <element name="sObject" type="ens:Contact" />
            </sequence>
        </complexType>

        <element name="notificationsResponse">
            <complexType>
                <sequence>
                    <element name="Ack" type="xsd:boolean" />
                </sequence>
            </complexType>
        </element>
    </schema>
</types>


<!-- Method Messages -->   
<message name="notificationsRequest">
    <part element="tns:notifications" name="request"/>
</message>
<message name="notificationsResponse">
    <part element="tns:notificationsResponse" name="response"/>
</message>

<!-- PortType -->
<portType name="NotificationPort">
    <operation name="notifications">
        <documentation>Process a number of notifications.</documentation>
        <input  message="tns:notificationsRequest"/>
        <output message="tns:notificationsResponse"/>
    </operation>
</portType>

<!-- Binding 
     You need to write a service that implements this binding to receive the notifications
 -->
<binding name="NotificationBinding" type="tns:NotificationPort">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

    <operation name="notifications">
        <soap:operation soapAction=""/>
        <input>
            <soap:body use="literal"/>
        </input>
        <output> 
            <soap:body use="literal"/>
        </output>
    </operation>
</binding>

<!-- Service Endpoint -->
<service name="NotificationService">
    <documentation>Notification Service Implementation</documentation>
    <port binding="tns:NotificationBinding" name="Notification">
        <soap:address location="http://www.myserver.com/salesforceoutboundprototype/notificationport.svc"/>
    </port>
</service>    
</definitions>

tldr是我需要实现NotificationBinding,以便Salesforce可以在他们的系统上发生事件时调用我的when服务。

后来我意识到svcutil本身并不支持合同优先的开发。

根据Contract-First SOA with WCF,我使用WSCF.Blue从Salesforce wsdl生成服务器端存根。当代码编译由我的服务生成的wsdl时,它没有所需的通知操作。

我想知道我出了什么问题?

所以我设法使用wsdl.exe和/serverInterface快速实现了Salesforce wsdl,看起来基于asmx的应用程序生成的wsdl与基于wcf的应用程序有很大的不同。

这是使用/serverInterface的wsdl.exe创建的接口

代码语言:javascript
复制
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
[System.Web.Services.WebServiceBindingAttribute(Name="NotificationBinding", Namespace="http://soap.sforce.com/2005/09/outbound")]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(sObject))]
public interface INotificationBinding {

    /// <remarks/>
    [System.Web.Services.WebMethodAttribute()]
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]
    [return: System.Xml.Serialization.XmlElementAttribute("notificationsResponse", Namespace="http://soap.sforce.com/2005/09/outbound")]
    notificationsResponse notifications([System.Xml.Serialization.XmlElementAttribute("notifications", Namespace="http://soap.sforce.com/2005/09/outbound")] notifications notifications1);
}

这是由WSCF.Blue创建的接口

代码语言:javascript
复制
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://soap.sforce.com/2005/09/outbound", ConfigurationName="INotificationPort")]
public interface INotificationPort
{

    // CODEGEN: Generating message contract since the operation notifications is neither RPC nor document wrapped.
    [System.ServiceModel.OperationContractAttribute(Action="", ReplyAction="*")]
    [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
    [System.ServiceModel.ServiceKnownTypeAttribute(typeof(sObject))]
    notificationsResponse1 notifications(notificationsRequest request);
}

它们看起来非常相似,所以我不知道为什么这些应用程序生成的wsdl会如此不同?添加wsdls是否值得(我不想再提出这个问题了)?

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2012-02-16 05:46:27

你可能不喜欢我的建议,但我相信这对你来说是最好的选择。使用ASMX。我有三个OM监听器,它们在4.0以下都工作得很好

我不知道是谁散布了这些关于.NET2.0技术的错误信息,但它们中的许多肯定不会因为开发社区被新奇的拜物教所困扰而过时;ASMX就是其中之一( Linq2SQL也是如此)。简单地说,WCF还没有完成,它不完全兼容WS,这给salesforce集成带来了很多麻烦(最痛苦的是,WCF不支持salesforce保存会话信息的soap头)。

有关asmx为何不过时的更多信息,请参阅此处:Does .net 4.0 still support asmx

票数 5
EN

Stack Overflow用户

发布于 2012-02-15 10:10:29

使用svcutil生成客户端代理,只需删除客户端代理实现,并保留服务/数据契约。从客户端/服务器的角度来看,服务契约是对称的。我在大量合同优先的项目中工作,发现这是完全足够的。

只需确保您拥有svcutil要解析的所有外部WSDL即可。我在上面的WSDL文本中看到了几个import语句。

顺便说一句,不幸的是,WSCF.Blue不太适合它,因为它已经几个月没有更新了,而且在未来也不太可能更新。可悲的是,主要开发人员在去年的一场车祸中丧生(是的,真的)。

票数 1
EN

Stack Overflow用户

发布于 2013-02-18 22:46:14

我经历了同样的痛苦,试图让我的OBM侦听器与WCF一起工作。我最初只为通知方法设置了一个OperationContract。部署后,我很快意识到需要建立一个数据契约,我确实这样做了,但由于时间限制,并且不完全确定这是否是我需要做的全部,我简单地切换到了一个可以工作的asmx web服务。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9169643

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档