【问题标题】:What can cause an object reference error when using BizTalk to consume a WCF endpoint?使用 BizTalk 使用 WCF 终结点时,什么会导致对象引用错误?
【发布时间】:2010-09-14 18:08:23
【问题描述】:

我是 BizTalk 2009 集成的另一方,我有一份相当简单的合同,看起来像这样:

[ServiceContract(Name = "ReceiverService", Namespace = "http://services.company.org/")]
public interface IReceiverService : ILoadBalanced
{
 [OperationContract]
 void FinishedRouting(long applicationId);

 [OperationContract]
 void ResponsePending(long applicationId, string stringId, short count);

 [OperationContract]
 void ReportException(long applicationId, string errorMessage, string stringId);

 [OperationContract]
 void SaveResponse(WebResponseDto decision);
}

但是,当 BizTalk 组尝试使用 WCF 服务使用向导时,它会阻塞并提供此堆栈跟踪:

[5096] System.NullReferenceException: Object reference not set to an instance of an object. 
[5096]    at Microsoft.BizTalk.Adapter.Wcf.Consuming.Exporters.BindingInfoExporter.CreatePrimaryTransport(ServiceEndpoint serviceEndpoint, Boolean custom) 
[5096]    at Microsoft.BizTalk.Adapter.Wcf.Consuming.Exporters.BindingInfoExporter.CreateSendPort(ServiceEndpoint endpoint, Port port, Boolean custom) 
[5096]    at Microsoft.BizTalk.Adapter.Wcf.Consuming.Exporters.BindingInfoExporter.Export(ServiceEndpointCollection endpoints, ServiceDescriptionCollection wsdlDocuments, Boolean custom) 
[5096]    at Microsoft.BizTalk.Adapter.Wcf.Consuming.Consumer.CreateBindingFiles(MetadataSet metadataSet, String serviceName) 

然后在这里:

[5096] System.NullReferenceException: Object reference not set to an instance of an object. 
[5096]    at Microsoft.BizTalk.Adapter.Wcf.Consuming.Implementation.ClientImplementation.AddFilesToProject(String schemaNamespace) 
[5096] System.NullReferenceException: Object reference not set to an instance of an object. 
[5096]    at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous) 
[5096]    at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args) 
[5096]    at Microsoft.BizTalk.Adapter.Wcf.Consuming.Consumer.Consume(ISynchronizeInvoke synchronizeInvoke, DTE dte, MetadataSet metadataSet, Project project, String importNamespace) 

有人知道从哪里开始看这个吗?

【问题讨论】:

    标签: wcf biztalk wcf-binding biztalk-2009


    【解决方案1】:

    可能类似于这些 - herehere,即:

    • 对 WCF 客户端使用 svcutil.exe 和/或 wsdl.exe,以确保非 BizTalk 客户端可以生成代理
    • 检查所有 WSDL 以确保所有元素都存在目标命名空间 - 在您的实例中,还记得检查您的基本合同 (ILoadBalanced) 和您的实体 (WebResponseDto)

    您能否确认您可以在一个普通的 WCF 服务上使用 WCF 使用向导(没有基本接口、一个操作、字符串输入和字符串返回)?如果没有,可能是你的 VS IDE 损坏了。

    FWIW void 返回似乎不是问题 - BTS 为 void 操作创建以下响应模式

      <xs:element name="GetDataResponse">
        <xs:complexType>
          <xs:sequence />
        </xs:complexType>
      </xs:element>
    

    并且将 Contract 和 Base Contract 接口放在不同的命名空间中也可以。

    但是,将不可序列化的属性添加到 DTO/实体时,svcutil 和 BizTalk WCF 向导都失败了

    HTH

    namespace WcfService1
    {
        [ServiceContract(Namespace = "http://someorl.org/ns1")]
        public interface IBase
        {
            [OperationContract]
            void SomeBaseMethod(int value);
        }
    
        [ServiceContract(Namespace = "http://someorl.org/ns2")]
        public interface IService1 : IBase
        {
    
            [OperationContract]
            void GetData(int value);
    
            [OperationContract]
            CompositeType GetDataUsingDataContract(CompositeType composite);
    
            // TODO: Add your service operations here
        }
    
    
        // Use a data contract as illustrated in the sample below to add composite types to service operations.
        [DataContract]
        public class CompositeType
        {
            bool boolValue = true;
            string stringValue = "Hello ";
    
            [DataMember]
            public bool BoolValue
            {
                get { return boolValue; }
                set { boolValue = value; }
            }
    
            [DataMember]
            public string StringValue
            {
                get { return stringValue; }
                set { stringValue = value; }
            }
    
            //[DataMember]
            //public XmlDocument NonSerializable
            //{
            //    get;
            //    set;
            //}
        }
    }
    

    【讨论】:

    • 感谢您的彻底回复!这最终使我得到了答案……深入研究 LoadBalanced 合同,有一个 WebGet 方法最终破坏了 BizTalk 的导入。 WCF 测试客户端可以很好地看到它,但确实在它旁边放了一个红色的感叹号......我猜 BizTalk 只是拒绝在这种情况下继续。
    【解决方案2】:

    WCF 客户端应用程序不能使用具有单向操作的服务协定将消息发送到您的 WCF 接收位置。客户端合约上的操作应使用 IsOneWay=false 和 ReplyAction=”*” 进行注释。唯一的例外是当您使用 NetMsmqBinding 时,在这种情况下,客户端合约上的所有操作都应该是单向的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-21
      • 1970-01-01
      • 2013-02-11
      • 1970-01-01
      相关资源
      最近更新 更多