WCF服务时,尝试在ASP.NET Web站点托管异常错误 [英] WCF Service exception error when try to host in ASP.NET Web Site

查看:301
本文介绍了WCF服务时,尝试在ASP.NET Web站点托管异常错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图浏览我的.svc文件时,会出现以下错误。

The following error occurs when trying to browse my .svc file.

An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.NullReferenceException: Object reference not set to an instance of an object.
   at System.ServiceModel.Description.WsdlExporter.CreateWsdlBindingAndPort(ServiceEndpoint endpoint, XmlQualifiedName wsdlServiceQName, Port& wsdlPort, Boolean& newBinding, Boolean& bindingNameWasUniquified)
   at System.ServiceModel.Description.WsdlExporter.ExportEndpoint(ServiceEndpoint endpoint, XmlQualifiedName wsdlServiceQName)
   at System.ServiceModel.Description.WsdlExporter.ExportEndpoints(IEnumerable`1 endpoints, XmlQualifiedName wsdlServiceQName)
   at System.ServiceModel.Description.ServiceMetadataBehavior.MetadataExtensionInitializer.GenerateMetadata()
   at System.ServiceModel.Description.ServiceMetadataExtension.EnsureInitialized()
   at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.InitializationData.InitializeFrom(ServiceMetadataExtension extension)
   at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.GetInitData()
   at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.TryHandleDocumentationRequest(Message httpGetRequest, String[] queries, Message& replyMessage)
   at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.ProcessHttpRequest(Message httpGetRequest)
   at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.Get(Message message)
   at SyncInvokeGet(Object , Object[] , Object[] )
   at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

下面是我的web.config配置:

Here is my web.config configuration:

  <system.serviceModel>
    <services>
      <service name="WcfServiceLib.WcfService"
               behaviorConfiguration="Default">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/WebService"/>
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="" binding="wsHttpBinding" contract="WcfServiceContractLib.IWcfContract"/>
        <endpoint address="web" binding="webHttpBinding" contract="WcfServiceContractLib.IWcfContract"
                  behaviorConfiguration="web"/>
        <endpoint address="webJson" binding="webHttpBinding" contract="WcfServiceContractLib.IWcfContract"
                behaviorConfiguration="webJson"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp defaultOutgoingResponseFormat="Xml" helpEnabled="true"/>
        </behavior>
        <behavior name="webJson">
          <webHttp defaultOutgoingResponseFormat="Json" helpEnabled="true"/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="Default">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled ="true" />
  </system.serviceModel>

任何人只要有这种类似的情况?

Anyone with this similar situation?

我要指出,当这是设在一个控制台应用程序,我用它来运行测试,一切都很好。

试图加载该服务在一个控制台应用程序时,会出现同样的错误。不显示WCF的Web页面,您可以看到WSDL信息等...

Same error occurs when trying to load the service in a console app. Not showing the WCF web page where you can see the wsdl info etc...

推荐答案

如果您使用的是.NET 4.0,并试图主办SOAP,XML和JSON端点togeather,你会得到异常。只是commment出任何你的Json或XML端点,这应该很好地工作。

If you are using .NET 4.0 and trying to host SOAP, Xml and Json endpoints togeather you would get the exception. Just commment out either your Json or Xml endpoint and that should work fine.

这是我所提出的<一个一个已知的问题href="https://connect.microsoft.com/wcf/feedback/details/711802/hosting-multiple-endpoints-soap-xml-and-json-causes-an-exception-when-accessing-the-service">Microsoft连接和MS的开发团队已经关闭了它作为将无法修复。

This is a known issue which I have raised on Microsoft Connect and the MS dev team has closed it out as won't fix.

为了同时支持JSON和的Xml如果客户端通过只是所需的Accept报头中,如application / xml进行或应用程序/ JSON的要求的框架autoamtically处理它,并发送回适当的格式的响应。

In order to support both Json and Xml if the client passes just the required Accept header in the request like "application/xml" or "application/json" the framework autoamtically handles it and sends back the response in appropriate format.

这篇关于WCF服务时,尝试在ASP.NET Web站点托管异常错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆