刷新WCF服务元数据时出错?

时间:2017-11-02 11:07:51

标签: c# web-services wcf wsdl biztalk

我们在Windows服务应用程序中有一个自动托管的WCF Web服务。

从.NET winform应用程序和SoapUI生成并调用一个简单方法(在更改IP和设置身份验证标头之后)可以正常工作。

问题是当尝试将WSDL添加到BizTalk时,我们得到"错误消耗WCF服务元数据。对象引用未设置为对象的实例" 。仅此而已。

我有搜索互联网,有些人有同样的问题,他们正在谈论名称空间问题。我检查了生成的.NET winform代理,但没有警告或任何可能表明命名空间问题的东西?我在WSDL中注意到一些名称空间标签只有一个""值,但不确定这可能是一个问题。

有没有办法从Biztalk获取有关此大规模WSDL中错误可能位置的更多信息?

当从另一台计算机浏览WSDL时,它将使用localhost(而不是IP och DNS),因此我必须使用WSDL singelfile来生成代理,我必须手动将URL更改为客户端中的特定IP以获取它工作。然而,这应该不是问题。

以下是服务的启动方式:

_serviceHost = new ServiceHost(typeof(T), new Uri(baseEndpoint.Address));
    ServiceThrottlingBehavior throttleBehavior = new ServiceThrottlingBehavior
                {
                    MaxConcurrentCalls = 200,
                    MaxConcurrentInstances = 2147483647,
                    MaxConcurrentSessions = 2000,
                };
    _serviceHost.Description.Behaviors.Add(throttleBehavior);
    _serviceHost.Description.Behaviors.Add(smb.HttpGetEnabled = true);
    foreach (var endpointDescription in _additionalServiceEndpoints)
                {
                    var endpoint = new ServiceEndpoint(ContractDescription, endpointDescription.Binding, new EndpointAddress(endpointDescription.Address));
                    _endpointBehaviors.ForEach(c => endpoint.EndpointBehaviors.Add(c));
                    _serviceHost.AddServiceEndpoint(endpoint);
                }
    _serviceBehaviors.ForEach(c => _serviceHost.Description.Behaviors.Add(c));

    ServiceAuthorizationBehavior serviceAuthorizationBehavior = _serviceHost.Description.Behaviors.Find<ServiceAuthorizationBehavior>();
                if (serviceAuthorizationBehavior == null)
                {
                    _serviceHost.Description.Behaviors.Add(new ServiceAuthorizationBehavior());
                }
                if (_authorizationPolicies.Count > 0)
                {
                    serviceAuthorizationBehavior.ExternalAuthorizationPolicies = new ReadOnlyCollection<IAuthorizationPolicy>(_authorizationPolicies.ToArray());
                    serviceAuthorizationBehavior.PrincipalPermissionMode = PrincipalPermissionMode.Custom;
                    serviceAuthorizationBehavior.ServiceAuthorizationManager = new CustomServiceAuthorizationManager();
                }
                ((ServiceBehaviorAttribute)_serviceHost.Description.Behaviors[typeof(ServiceBehaviorAttribute)]).MaxItemsInObjectGraph = 2147483647;
                ((ServiceBehaviorAttribute)_serviceHost.Description.Behaviors[typeof(ServiceBehaviorAttribute)]).IncludeExceptionDetailInFaults = true;

    _serviceHost.Open();

2 个答案:

答案 0 :(得分:1)

您是否尝试过此论坛帖子中描述的解决方案:https://social.msdn.microsoft.com/Forums/en-US/19105b96-5ec4-40f1-972b-2e04f889061f/biztalk-2010-error-consuming-wcf-service-metadata-object-reference-not-set-to-an-instance-of-an?forum=biztalkgeneral

它指向位于此处的博文:https://blogs.msdn.microsoft.com/kerreybpi/2009/02/05/biztalk-error-wcf-service-consuming-wizard/

解决方案可能是(来自上面的链接):

1,使用svcutil工具生成WSDL和XSD文件

  

svcutil.exe / t:metadata http://yourservice

2,验证WSDL文件中的节点,确保该节点具有目标命名空间定义。使用什么属性值并不重要,可能只是看起来像http:// any。

3,选择元数据文件(WSDL和XSD)作为源

4,一切都应该没问题。

答案 1 :(得分:0)

当尝试使用.svc?singleWsdl时,我遇到了相同的错误。当我仅将.svc消费到“添加生成的项目”向导中时,它将起作用。