Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Salesforce出站消息的合同首个WCF_C#_Wcf_Salesforce - Fatal编程技术网

C# Salesforce出站消息的合同首个WCF

C# Salesforce出站消息的合同首个WCF,c#,wcf,salesforce,C#,Wcf,Salesforce,我正在考虑为Salesforce出站消息实现侦听器应用程序 使用不推荐使用的ASMX web服务实现它。代码是使用wsdl.exe和/serverInterface开关生成的 以下是Salesforce出站消息传递的wsdl <?xml version="1.0" encoding="UTF-8"?> <definitions targetNamespace="http://soap.sforce.com/2005/09/outbound" xmlns="http://

我正在考虑为Salesforce出站消息实现侦听器应用程序

使用不推荐使用的ASMX web服务实现它。代码是使用wsdl.exe和/serverInterface开关生成的

以下是Salesforce出站消息传递的wsdl

<?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>

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

提供了一个带有VS集成的契约优先工具。

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

只需确保所有外部WSDL都可供svcutil解析即可。我在上面的WSDL文本中看到了几个导入语句


顺便说一句,WSCF.Blue不太适合它,不幸的是,它已经有几个月没有更新了,将来也不太可能更新。不幸的是,主要开发者去年死于车祸(是的,真的。)

你可能不喜欢我的建议,但我相信这实际上是你的最佳选择。使用ASMX。我有三个OM监听器,它们在4.0下都能正常工作

我不知道是谁传播了这些关于一些.NET2.0技术的错误信息,但它们中的很多肯定不会仅仅因为开发者社区被新奇事物迷恋而被淘汰;ASMX就是其中之一(Linq2SQL等也是)。简单地说,WCF尚未完成,它不完全兼容WS,这给salesforce集成带来了很多麻烦(最痛苦的是WCF不支持salesforce保存会话信息的soap头)


有关为什么asmx没有过时的更多信息,请参见此处:

我曾经历过同样的痛苦,试图让我的OBM侦听器使用WCF。我最初只为notifications方法设置了OperationContract。在部署之后,我很快意识到需要建立一个数据契约,但由于时间限制,我不能完全确定这是否是我所需要做的全部,我只是切换到一个可以工作的asmx web服务。

我找到了一个简单的方法,使用内置的Visual Studio从Salesforce WSDL生成WCF接口工具。我从Salesforce下载了WSDL并将其保存到我的桌面上。在VisualStudio中,转到某个项目中的“添加服务引用”菜单(无论在何处,您都要删除此项)。对于Url,键入您在本地下载的WSDL的路径(即C:\Users\yourusername\Desktop\notification.WSDL)

这将为服务加载数据。单击“确定”创建引用,现在在“服务引用”文件夹中,双击刚刚创建的引用。这将向您显示对象浏览器,并突出显示您刚刚创建的服务引用的名称空间。双击此命名空间内的任何类,它将打开visual studio生成的相关reference.cs

将名称空间声明中的所有内容复制到您选择的文件中,使用您决定的名称空间。如果您计划处理多个出站消息,也可以重命名该接口(默认值应为NotificationPort)。接口将引用您构建它时使用的名称空间,但您可以删除文件中的所有名称空间,因为它引用的所有类都在同一个文件中

创建新的WCF服务类。删除使用svc文件自动创建的接口,并将接口名称更改为刚刚复制到新文件的名称

默认情况下,VisualStudio创建了一些异步方法,当我尝试实现它时,该方法会抛出错误。我只是从界面上删除了它,并使用了标准的通知方法


我在VS2013中这样做了,但在2010年和2012年也应该是一样的。确保您使用的是“添加服务引用”,而不是“添加Web引用”。不要忘记删除生成的引用,因为您不会使用它。

可能的重复:我相信在WCF中,生成的客户端接口与服务器接口基本相同。嗯,这对我来说意味着什么?使用svcuti为您的消息传递类生成shell。无论您编写的是客户端还是服务器,它们基本上都是一样的。现在对您帮助不大,但WCF 4.5将重新引入这一丢失的功能。我已经说过,WSCF不提供Salesforce出站消息wsdl中可用的服务器端存根。@mob1Junkie:我觉得您应该将此作为错误报告提交给WSCF.blue以提供帮助改进它。它是一个很棒的工具,而且似乎正在为契约优先的SOA进行一场孤军奋战。它需要我们的支持。对于原型应用程序,我使用了ASMX。它很容易开发并且工作良好。那么为什么不将它用于生产类侦听器呢?为什么坚持使用WCF?我们一直使用WCF,因此为了保持一致性,我们希望将WCF用于OM listener plus Microsoft建议“现在应该使用Windows Communication Foundation创建XML Web服务和XML Web服务客户端”。MS在询问此类问题之前,首先必须学会如何与其他孩子一起玩。否则,这个建议就会变得相当自我中心。构建一个互操作性平台并不是要实现最好的标准化技术,而是要实现所有这些技术。虽然您的回答没有回答我的合同第一部分WCF问题,但它确实回答了Salesforce出站消息部分。此外,您还提供了有关为什么ASMX未被禁用的详细信息。因此,我决定将赏金授予你。
/// <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);
}
[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);
}