一些上下文:我们有一个自定义XSD,并使用WSCF.blue生成WSDL和C#代码.客户端使用ChannelFactory< T>并共享包含WSCF.blue添加的所有属性的接口,以匹配XSD中的内容.

我正在尝试实现IErrorHandler.ProvideFault,它提供了一个通用的FaultException< T>,但在客户端我得到了一个非通用的FaultContract.这就是我的ProvideFault方法的样子:

public void ProvideFault(Exception error,MessageVersion version,ref Message fault)
{
    if (!(error is FaultException))
    {
        FaultException faultException = FaultExceptionFactory.CreateFaultException(error);
        MessageFault messageFault = faultException.CreateMessageFault();
        fault = Message.CreateMessage(version,messageFault,faultException.Action);
    }
}

在每个服务方法中,如果我使用throwExceptionFactory.CreateFaultException(ex)执行try / catch,它按预期工作,所以我认为[FaultContract],factory,bindings等都是正确的.以防万一,这就是工厂的工作原理:

BusinessRuleFaultExceptionType businessRuleFaultException = new BusinessRuleFaultExceptionType();
BusinessRuleFaultException.Code = exception.Code.ToString();
BusinessRuleFaultException.Reason = exception.Message;
return new FaultException<BusinessRuleFaultExceptionType>(
    businessRuleFaultException,exception.Message,new FaultCode(exception.Code.ToString())
);

我认为问题在于如何在IErrorHandler中创建消息,可能在CreateMessageFault()中.我已经读过,操作应该是faultException.Action而不是null,但实际上faultException.Action为null.也许这导致了这个问题.我可以在工厂设置一个动作,但是动作应该是什么,为什么不会出现手动抛出?

我还有什么其他的想法可能会遗漏?

编辑:
我检查了WSDL并找到了我调用的具体操作及其操作:

<wsdl:operation name="MyMethod">
<wsdl:fault wsaw:Action="http://myNamespace/MyMethodBusinessRuleFaultExceptionTypeFault" name="BusinessRuleFaultExceptionTypeFault" message="tns:..."/>

我试着硬编码的操作:Message.CreateMessage(…,“HTTP://了myNameSpace / MyMethodBusinessRuleFaultExceptionTypeFault”),并在出厂前将其设置为.Action但仍然没有奏效.

编辑2:
throw / catch生成以下XML,允许在客户端上捕获泛型异常:

<s:Fault>
    <faultcode xmlns="">s:-100</faultcode>
    <faultstring xml:lang="en-US" xmlns="">xxx</faultstring>
    <detail xmlns="">
        <BusinessRuleFaultExceptionType xmlns="http://myNamespace/Services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <Code xmlns="http://myNamespace/Entitites">-100</Code>
            <Reason xmlns="http://myNamespace/Entitites">xxx</Reason>
        </BusinessRuleFaultExceptionType>
    </detail>
</s:Fault>

IHttpErrorHandler生成以下内容,转到非泛型FaultException:

<s:Fault>
    <faultcode xmlns="">s:-100</faultcode>
    <faultstring xml:lang="en-US" xmlns="">xxx</faultstring>
    <detail xmlns="">
        <BusinessRuleFaultExceptionType xmlns="http://schemas.datacontract.org/2004/07/My.Dot.Net.Namespace" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <codeField>-100</codeField>
            <reasonField>xxx</reasonField>
        </BusinessRuleFaultExceptionType>
    </detail>
</s:Fault>

编辑3:
如果我将[DataContract]和[DataMember]添加到BusinessRuleFaultExceptionType,那么我得到几乎正确的XML:

<s:Fault>
    <faultcode xmlns="">s:-100</faultcode>
    <faultstring xml:lang="en-US" xmlns="">xxx</faultstring>
    <detail xmlns="">
        <BusinessRuleFaultExceptionType xmlns="http://myNamespace/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <Code>-100</Code>
            <Reason>xxx</Reason>
        </BusinessRuleFaultExceptionType>
    </detail>
</s:Fault>

它缺少Code和Reason的命名空间.至少我认为这会缩小它.常规序列化使用[XmlType]和[XmlElement],而IErrorHandler使用[DataContract]和[DataMember].不幸的是[DataMember]不允许你设置命名空间,所以我认为现在的问题是如何在IErrorHandler中使用XMLSerializer.这描述了我的问题,但由于上述原因,修复将不起作用:http://twenty6-jc.blogspot.com/2011/05/ierrorhandlerprovidefault-serialization.html

编辑4:
我部分地发现了这个问题.我们正在使用XmlSerializer,但由于IErrorHandler不在操作范围内,因此它将恢复为默认的DataContractSerializer.解决方案是更改您的服务以在任何地方使用DataContractSerializer,或在创建故障时手动选择XmlSerializer.这两篇文章提供了我需要的东西:

http://twenty6-jc.blogspot.com/2011/05/ierrorhandlerprovidefault-serialization.html
http://zamd.net/2008/08/15/serializing-faults-using-xmlserializer/

这让我非常接近.它与工作XML相同,只是缺少异常类型的命名空间:

<s:Fault>
    <faultcode xmlns="">s:-100</faultcode>
    <faultstring xml:lang="en-US" xmlns="">xxx</faultstring>
    <detail xmlns="">
        <BusinessRuleFaultExceptionType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <Code xmlns="http://myNamespace/Entitites">-100</Code>
            <Reason xmlns="http://myNamespace/Entitites">xxx</Reason>
        </BusinessRuleFaultExceptionType>
    </detail>
</s:Fault>

我假设它没有添加xmlns =“http:// myNamespace / Services”,因为它没有请求的上下文.该命名空间在接口中定义,但不是数据协定.我是否真的会被迫留在请求的上下文中(希望IOperationInvoker工作),而不是使用IHttpHandler?

解决方法

我对WSCF.blue没有任何经验,因此我尝试使用标准WCF客户端和服务器创建示例应用程序来演示工作方案.也许它可以帮助您找到缺少的连接,使您的方案工作.

我使用了BusinessRuleFaultExceptionType和Code和Reason属性. BusinessRuleFaultExceptionType是WCF错误契约.

我有点懒,并在一个控制台应用程序中实现了所有代码. Wcf客户端使用与Wcf服务相同的Datacontracts和ICalculator接口.对不起代码.这将是一个很长的帖子.

首先是Datacontracts和服务接口

using System;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.dispatcher;

[ServiceContract(Namespace = "http://UE.ServiceModel.Samples")]
public interface ICalculator
{
    [OperationContract(IsOneWay = false)]
    [FaultContract(typeof(BusinessRuleFaultExceptionType))]
    double Add(double n1,double n2);

    [OperationContract(IsOneWay = false)]
    [FaultContract(typeof(BusinessRuleFaultExceptionType))]
    double Subtract(double n1,double n2);

    [OperationContract(IsOneWay = false)]
    [FaultContract(typeof(BusinessRuleFaultExceptionType))]
    double Multiply(double n1,double n2);

    [OperationContract(IsOneWay = false)]
    [FaultContract(typeof(BusinessRuleFaultExceptionType))]
    double Divide(double n1,double n2);
}

/// <summary>
/// General fault structure. 
/// </summary>
[DataContract(Namespace = "http://someurl.temp")]
public sealed class BusinessRuleFaultExceptionType
{
    [DataMember]
    public int Code { get; set; }

    [DataMember]
    public string Reason { get; set; }
}

现在,服务实现:

[ErrorBehavior(typeof(MyErrorHandler))]
public class CalculatorService : ICalculator
{
    public double Add(double n1,double n2)
    {
        double result = n1 + n2;
        Console.WriteLine("Received Add({0},{1})",n1,n2);
        Console.WriteLine("Return: {0}",result);
        throw new ArgumentException("My exception");
        return result;
    }

    public double Subtract(double n1,double n2)
    {
        double result = n1 - n2;
        Console.WriteLine("Received Subtract({0},result);
        return result;
    }

    public double Multiply(double n1,double n2)
    {
        double result = n1 * n2;
        Console.WriteLine("Received Multiply({0},result);
        return result;
    }

    public double Divide(double n1,double n2)
    {
        double result = n1 / n2;
        Console.WriteLine("Received Divide({0},result);
        return result;
    }
}

和客户端实施:

public class Client : ClientBase<ICalculator>,ICalculator
{

    public double Add(double n1,double n2)
    {
        try
        {
            return base.Channel.Add(n1,n2);
        }
        catch (FaultException<BusinessRuleFaultExceptionType> ex)
        {
            Console.WriteLine("This is my Code: {0}. This is the reason: {1}",ex.Detail.Code,ex.Detail.Reason);
        }
        catch (Exception ex)
        {
            throw;
        }
        return 0;
    }

    public double Subtract(double n1,double n2)
    {
        throw new NotImplementedException();
    }

    public double Multiply(double n1,double n2)
    {
        throw new NotImplementedException();
    }

    public double Divide(double n1,double n2)
    {
        throw new NotImplementedException();
    }
}

主程序来演示这个例子

internal class Program
{
    private static void Main(string[] args)
    {
        ServiceHost myServiceHost = new ServiceHost(typeof(CalculatorService));

        // Open the ServiceHostBase to create listeners and start listening for messages.
        myServiceHost.open();

        // The service can Now be accessed.
        Console.WriteLine("The service is ready.");
        Console.WriteLine("Press <ENTER> to terminate service.");
        Console.WriteLine();

        Console.ReadLine();

        Console.WriteLine("Sending data from client to service.");
        Client c = new Client();
        var res = c.Add(1,2);

        Console.ReadLine();
    }

}

错误处理的实现:

/// <summary>
/// Helper class for exception repackaging.
/// </summary>
internal class MyExceptionHandler
{
    /// <summary>
    /// Handles thrown exception into internal exceptions that are being sent over to client.
    /// </summary>
    /// <param name="error">Exception thrown.</param>
    /// <returns>Repackaged exception.</returns>
    internal static Exception HandleError(Exception error)
    {
        // Could do something here.
        return error;
    }
}

#region BehavIoUr
/// <summary>
/// Control the fault message returned to the caller and optionally perform custom error processing such as logging.
/// </summary>
public sealed class MyErrorHandler : IErrorHandler
{
    /// <summary>
    /// Provide a fault. The Message fault parameter can be replaced,or set to null to suppress reporting a fault.
    /// </summary>
    /// <param name="error">The <see cref="Exception"/> object thrown in the course of the service operation.</param>
    /// <param name="version">The SOAP version of the message.</param>
    /// <param name="fault">The <see cref="System.ServiceModel.Channels.Message"/> object that is returned to the client,or service,in the duplex case.</param>
    public void ProvideFault(Exception error,ref Message fault)
    {
        //If it's a FaultException already,then we have nothing to do
        if (error is FaultException)
            return;

        error = MyExceptionHandler.HandleError(error);

        var serviceDebug = OperationContext.Current.Endpointdispatcher.Channeldispatcher.IncludeExceptionDetailInFaults;

        BusinessRuleFaultExceptionType f = new BusinessRuleFaultExceptionType
        {
            Code = -100,Reason = "xxx"
        };

        FaultException<BusinessRuleFaultExceptionType> faultException = new FaultException<BusinessRuleFaultExceptionType>(f,error.Message);
        MessageFault faultMessage = faultException.CreateMessageFault();
        fault = Message.CreateMessage(version,faultMessage,faultException.Action);
    }

    /// <summary>
    /// Enables error-related processing and returns a value that indicates whether the dispatcher aborts the session and the instance context in certain cases.
    /// </summary>
    /// <param name="error">The exception thrown during processing.</param>
    /// <returns>true if Windows Communication Foundation (WCF) should not abort the session (if there is one) and instance context if the instance context is not Single; otherwise,false. The default is false.</returns>
    public bool HandleError(Exception error)
    {
        // Could use some logger like Nlog but as an example it will do.
        Console.WriteLine("Error occured. {0}",error);

        return true;
    }
}

/// <summary>
/// This attribute is used to install a custom error handler for a service
/// </summary>
public sealed class ErrorBehaviorAttribute : Attribute,IServiceBehavior
{
    /// <summary>
    /// Type of component to which this error handled should be bound
    /// </summary>
    private readonly Type errorHandlerType;

    /// <summary>
    /// Initializes a new instance of the ErrorBehaviorAttribute class.
    /// </summary>
    /// <param name="errorHandlerType">Type of component to which this error handled should be bound</param>
    public ErrorBehaviorAttribute(Type errorHandlerType)
    {
        this.errorHandlerType = errorHandlerType;
    }

    /// <summary>
    /// Type of component to which this error handled should be bound
    /// </summary>
    public Type ErrorHandlerType
    {
        get { return errorHandlerType; }
    }

    /// <summary>
    /// Provides the ability to inspect the service host and the service description to confirm that the service can run successfully.
    /// </summary>
    /// <param name="description">
    /// <para>Type: <see cref="System.ServiceModel.Description.ServiceDescription"/></para>
    /// <para>The service description.</para>
    /// </param>
    /// <param name="serviceHostBase">
    /// <para>Type: <see cref="System.ServiceModel.ServiceHostBase"/></para>
    /// <para>The service host that is currently being constructed.</para>
    /// </param>
    void IServiceBehavior.Validate(ServiceDescription description,ServiceHostBase serviceHostBase)
    {
    }

    /// <summary>
    /// Provides the ability to pass custom data to binding elements to support the contract implementation.
    /// </summary>
    /// <param name="description">
    /// <para>Type: <see cref="System.ServiceModel.Description.ServiceDescription"/></para>
    /// <para>The service description.</para>
    /// </param>
    /// <param name="serviceHostBase">
    /// <para>Type: <see cref="System.ServiceModel.ServiceHostBase"/></para>
    /// <para>The host of the service.</para>
    /// </param>
    /// <param name="endpoints">
    /// <para>Type: <see cref="System.Collections.ObjectModel.Collection&lt;ServiceEndpoint&gt;"/></para>
    /// <para>The service endpoints.</para>
    /// </param>
    /// <param name="parameters">
    /// <para>Type: <see cref="System.ServiceModel.Channels.BindingParameterCollection"/></para>
    /// <para>Custom objects to which binding elements have access.</para>
    /// </param>
    void IServiceBehavior.AddBindingParameters(ServiceDescription description,ServiceHostBase serviceHostBase,System.Collections.ObjectModel.Collection<ServiceEndpoint> endpoints,BindingParameterCollection parameters)
    {
    }

    /// <summary>
    /// Provides the ability to change run-time property values or insert custom extension objects such as error handlers,message or parameter interceptors,security extensions,and other custom extension objects.
    /// </summary>
    /// <param name="description">
    /// <para>Type: <see cref="System.ServiceModel.Description.ServiceDescription"/></para>
    /// <para>The service description.</para>
    /// </param>
    /// <param name="serviceHostBase">
    /// <para>Type: <see cref="System.ServiceModel.ServiceHostBase"/></para>
    /// <para>The host that is currently being built.</para>
    /// </param>
    void IServiceBehavior.ApplydispatchBehavior(ServiceDescription description,ServiceHostBase serviceHostBase)
    {
        IErrorHandler errorHandler;

        try
        {
            errorHandler = (IErrorHandler)Activator.CreateInstance(errorHandlerType);
        }
        catch (MissingMethodException e)
        {
            throw new ArgumentException("The errorHandlerType specified in the ErrorBehaviorAttribute constructor must have a public empty constructor.",e);
        }
        catch (InvalidCastException e)
        {
            throw new ArgumentException("The errorHandlerType specified in the ErrorBehaviorAttribute constructor must implement System.ServiceModel.dispatcher.IErrorHandler.",e);
        }

        foreach (ChanneldispatcherBase channeldispatcherBase in serviceHostBase.Channeldispatchers)
        {
            Channeldispatcher channeldispatcher = channeldispatcherBase as Channeldispatcher;
            channeldispatcher.ErrorHandlers.Add(errorHandler);
        }
    }
}

#endregion

我的控制台应用程序的app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <system.serviceModel>
    <client>
      <endpoint address="http://localhost:12345/service/calc" binding="basicHttpBinding" contract="ConsoleApplication2.ICalculator" >
      </endpoint>
    </client>
    <services>
      <service name="ConsoleApplication2.CalculatorService" behaviorConfiguration="service">
        <endpoint address="http://localhost:12345/service/calc" binding="basicHttpBinding" contract="ConsoleApplication2.ICalculator" >
        </endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:12345/service/calc" />
          </baseAddresses>
        </host>
      </service>

    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="service">
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

我使用WCF测试客户端发送此请求:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://UE.ServiceModel.Samples/ICalculator/Add</Action>
  </s:Header>
  <s:Body>
    <Add xmlns="http://UE.ServiceModel.Samples">
      <n1>0</n1>
      <n2>1</n2>
    </Add>
  </s:Body>
</s:Envelope>

得到了这个回应:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header />
  <s:Body>
    <s:Fault>
      <faultcode>s:Client</faultcode>
      <faultstring xml:lang="sk-SK">My exception</faultstring>
      <detail>
        <BusinessRuleFaultExceptionType xmlns="http://someurl.temp" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
          <Code>-100</Code>
          <Reason>xxx</Reason>
        </BusinessRuleFaultExceptionType>
      </detail>
    </s:Fault>
  </s:Body>
</s:Envelope>

我打电话的时候

Client c = new Client();
var res = c.Add(1,2);

我发现了FaultException< BusinessRuleFaultExceptionType>我记录到控制台的ex

Console.WriteLine("This is my Code: {0}. This is the reason: {1}",ex.Detail.Reason);

编辑:我在BusinessRuleFaultExceptionType中更改了名称空间,并将解决方案设置为使用[XmlSerializerFormat(SupportFaults = true)].

更改了界面,数据交换和服务实现:

[ServiceContract(Namespace = "http://UE.ServiceModel.Samples")]
[XmlSerializerFormat(SupportFaults = true)]
public interface ICalculator
{
    [OperationContract(IsOneWay = false)]
    [FaultContract(typeof(BusinessRuleFaultExceptionType))]
    double Add(double n1,double n2);
}

/// <summary>
/// General fault structure. 
/// </summary>
[DataContract(Name = "BusinessRuleFaultExceptionType",Namespace = "http://someurl.temp")]
[XmlType("BusinessRuleFaultExceptionType",Namespace = "http://someurl.temp")]
public sealed class BusinessRuleFaultExceptionType
{
    //[DataMember]
    [XmlElement(IsNullable = false,Namespace = "http://namespaces2.url")]
    public int Code { get; set; }

    [XmlElement(IsNullable = false,Namespace = "http://namespaces2.url")]
    public string Reason { get; set; }
}

[ErrorBehavior(typeof(MyErrorHandler))]
public class CalculatorService : ICalculator
{
    public double Add(double n1,result);

        throw new FaultException<BusinessRuleFaultExceptionType>(new BusinessRuleFaultExceptionType()
        {
            Code = -100,Reason = "xxx"
        });
        //throw new ArgumentException("My exception");
        return result;
    }

    public double Subtract(double n1,result);
        return result;
    }
}

我找到了一篇关于there are problems在IErrorHandler中使用XmlSerializer的原因的文章.因此,我已经更改了服务实现,以在方法实现中抛出FaultException,并且不依赖于IErrorHandler.

我还发现了另一篇(相对较旧的)文章how to use XmlSerializer in IErroHandler,经过一段时间我甚至可以从IErrorHandler进行序列化.我将trown异常更改回ArgumentException.
以下是更改(我继续前面的示例,因此可能不需要所有代码和属性):

[DataContract(Name = "BusinessRuleFaultExceptionType",Namespace = "http://someurl.temp")]
[XmlRoot("BusinessRuleFaultExceptionType",Namespace = "http://namespaces2.url")]
    public string Reason { get; set; }
}

public class XmlSerializerMessageFault : MessageFault
{
    FaultCode code;
    FaultReason reason;

    object details;

    public XmlSerializerMessageFault(FaultCode code,FaultReason reason,object details)
    {
        this.details = details;
        this.code = code;
        this.reason = reason;
    }

    public override FaultCode Code
    {
        get { return code; }
    }

    public override bool HasDetail
    {
        get { return (details != null); }
    }

    protected override void OnWriteDetailContents(System.Xml.XmlDictionaryWriter writer)
    {
        var ser = new XmlSerializer(details.GetType());
        ser.Serialize(writer,details);
        writer.Flush();
    }

    public override FaultReason Reason
    {
        get { return reason; }
    }
}

/// <summary>
/// Control the fault message returned to the caller and optionally perform custom error processing such as logging.
/// </summary>
public sealed class MyErrorHandler : IErrorHandler
{
    /// <summary>
    /// Provide a fault. The Message fault parameter can be replaced,ref Message fault)
    {

        BusinessRuleFaultExceptionType f = new BusinessRuleFaultExceptionType
        {
            Code = -100,Reason = "xxx"
        };

        // create a fault message containing our FaultContract object
        FaultException<BusinessRuleFaultExceptionType> faultException = new FaultException<BusinessRuleFaultExceptionType>(f,error.Message);
        MessageFault faultMessage = faultException.CreateMessageFault();

        var msgFault = new XmlSerializerMessageFault(faultMessage.Code,faultMessage.Reason,f);

        fault = Message.CreateMessage(version,msgFault,error);

        return true;
    }
}

在这两种情况下,序列化故障是:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header />
  <s:Body>
    <s:Fault>
      <faultcode>s:Client</faultcode>
      <faultstring xml:lang="sk-SK">My exception</faultstring>
      <detail>
        <BusinessRuleFaultExceptionType xmlns="http://someurl.temp" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
          <Code xmlns="http://namespaces2.url">-100</Code>
          <Reason xmlns="http://namespaces2.url">xxx</Reason>
        </BusinessRuleFaultExceptionType>
      </detail>
    </s:Fault>
  </s:Body>
</s:Envelope>

c# – WCF:在IErrorHandler中提供通用的FaultException的更多相关文章

  1. Swift获取命名空间(namespace),动态加载类

    1.tips1.1在swift中,类名的组成格式是namespace.类名.比如我们在任意一个控制器的viewDidLoad()方法中打印self,打印结果是:打印结果.png1.2.namespace默认是项目名称,同一个命名空间全局共享2.怎么查看namespacenamespace在info.plist对应的是CFBundleExecutable,我们可以在info.plist中任意右击一行

  2. android – 如何实现消息读取状态,如whatsapp蓝色刻度?

    我正在开发一个应用程序,聊天是一个模块,聊天我正在使用xmpp.当我发送消息时,我使用DeliveryReceiptManager获取该消息传递状态.但我需要表明该消息是用户READ或NOTwhatsApp蓝色tickmark,任何人都可以帮助我,我被击中了.如何实现此消息读取概念.提前致谢.解决方法创建自定义数据包扩展类当进入聊天列表时发送具有相同包ID的消息标签其中mConnection是xm

  3. 从Android应用程序中消耗WCF Web服务?

    我想从Android应用程序中使用WCFWeb服务.我曾经使用过.asmxweb服务,但我不知道如何在Android应用程序中使用SCFWeb服务.我用谷歌搜索它但没有找到任何东西.如果有人做过,请帮助我.提前致谢.解决方法Hereisanarticleexplaininghowtoconsumewebservicewithandroidingeneral当涉及到WCF并且可以与您想要小心的jav

  4. 基于JavaScript 下namespace 功能的简单分析

    前些天在剥离 百度随心听 的播放器引擎时,看到了一个namespace方法,觉得新奇,当然只是对于我自己而言,我入门js不久,经验尚浅

  5. PHP命令空间namespace及use的用法小结

    命名空间一个最明确的目的就是解决重名问题,PHP中不允许两个函数或者类出现相同的名字,否则会产生一个致命的错误。这篇文章主要介绍了PHP命令空间namespace及use的用法实践总结,需要的朋友可以参考下

  6. php中namespace及use用法分析

    这篇文章主要介绍了php中namespace及use用法,结合实例形式分析了php中namespace及use的功能与具体使用方法,需要的朋友可以参考下

  7. javascript 面向对象,实现namespace,class,继承,重载

    这几天老大天天嚷嚷要重构我们写的javascript,抱怨代码太混乱,可读性差,维护困难,要求javascript也按面对象的模型来重构。

  8. PHP命名空间实现自动加载引入文件

    php的namespace命名空间仅仅提供了一个逻辑上的类的隔离空间,我们在引用类时,仍要自己实现自动载入。思路就是使用一个未引入的类时,php自动触发spl_autoload_register这个方法,然后就会根据命名空间的结构解析为文件路径,引入相关的类文件

  9. PHP命名空间(namespace)原理与用法详解

    这篇文章主要介绍了PHP命名空间(namespace)原理与用法,结合实例形式详细分析了PHP命名空间的概念、原理、用法及相关操作注意事项,需要的朋友可以参考下

  10. PHP命名空间namespace及use的简单用法分析

    这篇文章主要介绍了PHP命名空间namespace及use的简单用法,结合实例形式分析了php命名空间的功能、使用方法及相关操作注意事项,需要的朋友可以参考下

随机推荐

  1. c# – (wpf)Application.Current.Resources vs FindResource

    所以,我正在使用C#中的WPF创建一个GUI.它看起来像这样:它现在还没有完成.这两行是我尝试制作一种数据表,它们在XAML中是硬编码的.现在,我正在C#中实现添加新的水果按钮功能.我在XAML中有以下样式来控制行的背景图像应该是什么样子:因此,在代码中,我为每列col0,col1和col2创建一个图像,如果我使用以下代码,它添加了一个如下所示的新行:如你所见,它不太正确……为什么一个似乎忽略了一些属性而另一个没有?

  2. c# – 绑定DataGridTemplateColumn

    似乎我已经打了个墙,试图在DataGrid上使用DataTemplates.我想要做的是使用一个模板来显示每个单元格的两行文本.但是似乎无法以任何方式绑定列.以下代码希望显示我想做的事情.注意每个列的绑定:模板列没有这样的东西,因此,这个xaml不可能工作.我注定要将整个DataTemplate复制到每个列,只是对每个副本都有不同的约束?解决方法我不完全确定你想要做什么,但如果您需要获取整行的DataContext,可以使用RelativeSource绑定来移动视觉树.像这样:

  3. c# – 学习设计模式的资源

    最近我来到了这个设计模式的概念,并对此感到非常热情.你能建议一些帮助我深入设计模式的资源吗?

  4. c# – 是否有支持嵌入HTML页面的跨操作系统GUI框架?

    我想开发一个桌面应用程序来使用跨系统,是否有一个GUI框架,允许我为所有3个平台编写一次代码,并具有完全可脚本化的嵌入式Web组件?我需要它有一个API来在应用程序和网页之间进行交流.我知道C#,JavaScript和一些python.解决方法Qt有这样的事情QWebView.

  5. c# – 通过字符串在对象图中查找属性

    我试图使用任意字符串访问嵌套类结构的各个部分.给出以下(设计的)类:我想要从Person对象的一个实例的“PersonsAddress.HousePhone.Number”获取对象.目前我正在使用反思来做一些简单的递归查找,但是我希望有一些忍者有更好的想法.作为参考,这里是我开发的(crappy)方法:解决方法您可以简单地使用标准的.NETDataBinder.EvalMethod,像这样:

  6. c# – 文件下载后更新页面

    FamilyID=0a391abd-25c1-4fc0-919f-b21f31ab88b7&displaylang=en&pf=true它呈现该页面,然后使用以下元刷新标签来实际向用户提供要下载的文件:你可能需要在你的应用程序中做类似的事情.但是,如果您真的有兴趣在文件完全下载后执行某些操作,那么您的运气不佳,因为没有任何事件可以与浏览器进行通信.执行此操作的唯一方法是上传附件时使用的AJAXupload.

  7. c# – 如何在每个机器应用程序中实现单个实例?

    我必须限制我的.net4WPF应用程序,以便每台机器只能运行一次.请注意,我说每个机器,而不是每个会话.我使用一个简单的互斥体实现单实例应用程序,直到现在,但不幸的是,这样一个互斥是每个会话.有没有办法创建机器互连,还是有其他解决方案来实现每个机器应用程序的单个实例?

  8. c# – WCF和多个主机头

    我的雇主网站有多个主机名,都是同一个服务器,我们只是显示不同的皮肤来进行品牌宣传.不幸的是,在这种情况下,WCF似乎不能很好地工作.我试过overridingthedefaulthostwithacustomhostfactory.这不是一个可以接受的解决方案,因为它需要从所有主机工作,而不仅仅是1.我也看过thisblogpost,但是我无法让它工作,或者不是为了解决我的问题.我得到的错误是“这

  9. c# – ASP.NET MVC模型绑定与表单元素名称中的虚线

    我一直在搜索互联网,试图找到一种方式来容纳我的表单元素的破折号到ASP.NET的控制器在MVC2,3或甚至4中的默认模型绑定行为.作为一名前端开发人员,我更喜欢在我的CSS中使用camelCase或下划线进行破折号.在我的标记中,我想要做的是这样的:在控制器中,我会传入一个C#对象,看起来像这样:有没有办法通过一些正则表达式或其他行为来扩展Controller类来适应这种情况?我讨厌这样的事实,我必须这样做:甚至这个:思考?

  10. c# – 用户界面设计工具

    我正在寻找一个用户界面设计工具来显示文档中可能的GUI.我不能生成代码.我知道MicrosoftVisio提供了一个功能.但有什么办法吗?您使用哪种软件可视化GUI?

返回
顶部