2011-08-23 54 views
0

我有一个WCF客户端正在调用一个任意SOAP端点,其中端点返回一个Soap消息(System.ServiceModel.Channels.Message)。如果这个消息是错误的,是否有任何内置的.NET类将它反序列化为SoapFault或FaultException,或者我只需要手动解析消息?是否有内置的方法来解析.NET中的消息中的错误?

原始信息如下:

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"> 
    <s:Header> 
    <a:Action s:mustUnderstand="1">http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher/fault</a:Action> 
    <a:RelatesTo>urn:uuid:59da9d2e-2b96-4fc8-8105-1907a0ce6584</a:RelatesTo> 
    </s:Header> 
    <s:Body> 
    <s:Fault> 
     <s:Code> 
     <s:Value>s:Receiver</s:Value> 
     <s:Subcode> 
      <s:Value xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</s:Value> 
     </s:Subcode> 
     </s:Code> 
     <s:Reason> 
     <s:Text xml:lang="en-US">Something is Amiss!</s:Text> 
     </s:Reason> 
     <s:Detail> 
     <ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> 
      <HelpLink i:nil="true" /> 
      <InnerException i:nil="true" /> 
      <Message>Something is Amiss!</Message> 
      <StackTrace> at Rhino.Mocks.Expectations.AbstractExpectation.ReturnOrThrow(IInvocation invocation, Object[] args) 
    at Rhino.Mocks.Impl.ReplayMockState.DoMethodCall(IInvocation invocation, MethodInfo method, Object[] args) 
    at Rhino.Mocks.Impl.ReplayMockState.MethodCall(IInvocation invocation, MethodInfo method, Object[] args) 
    at Rhino.Mocks.MockRepository.MethodCall(IInvocation invocation, Object proxy, MethodInfo method, Object[] args) 
    at Rhino.Mocks.Impl.Invocation.Actions.RegularInvocation.PerformAgainst(IInvocation invocation) 
    at Rhino.Mocks.Impl.RhinoInterceptor.Intercept(IInvocation invocation) 
    at Castle.DynamicProxy.AbstractInvocation.Proceed() 
    at Castle.Proxies.MockXCARespondingGatewayProxyde8c39af35f14e839b4be7dfba3abf0f.CrossGatewayQuery(Message request) 
    at SyncInvokeCrossGatewayQuery(Object , Object[] , Object[]) 
    at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]&amp; outputs) 
    at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp; rpc) 
    at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc) 
    at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc&amp; rpc) 
    at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&amp; rpc) 
    at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp; rpc) 
    at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&amp; rpc) 
    at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc&amp; rpc) 
    at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc&amp; rpc) 
    at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&amp; rpc) 
    at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</StackTrace> 
      <Type>System.Exception</Type> 
     </ExceptionDetail> 
     </s:Detail> 
    </s:Fault> 
    </s:Body> 
</s:Envelope> 

回答

1

您可以尝试喂消息MessageFault.CreateFault - 根据this它可以分析故障出在给定的消息......

+0

真棒,感谢叶海亚。如果我知道在哪里寻找,我想出了一些必须存在的东西。 – Tedford

相关问题