- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我遇到了以下线程中列出的相同问题。
WSDL first WCF server where client does not send SOAPAction
我执行了同一线程中列出的步骤(如下所示)
1) 下载 Microsoft WCF 示例。将以下文件从 WF_WCF_Samples\WCF\Extensibility\Interop\RouteByBody\CS\service 添加到您的项目
DispatchByBodyOperationSelector.cs
DispatchByBodyBehaviorAttribute.cs
2) 将以下属性添加到您的界面(在您的 ServiceContract 旁边)
XmlSerializerFormat
DispatchByBodyBehavior
3) 将以下内容添加到您的服务接口(interface)
[OperationContract(Action = "")]
public void DoNothing()
{
}
4) 对于我的服务,所有消息的 WrapperName 和 Wrappernamespace 均为 null。我必须进入 DispatchByBodyBehaviorAttribute 并编辑 ApplyDispatchBehavior() 以添加以下行来检查这一点:
if (qname.IsEmpty) {
qname = new XmlQualifiedName(operationDescription.Messages[0].Body.Parts[0].Name, operationDescription.Messages[0].Body.Parts[0].Namespace);
}
现在,我收到一条错误消息“此消息无法支持该操作,因为它已被读取”。我打开跟踪并捕获堆栈跟踪(如下)。如果有人对如何解决这个问题有任何想法,如果您能发表一些评论,我将不胜感激。感谢您的帮助!
at System.ServiceModel.Channels.Message.GetReaderAtBodyContents()
at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)
at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRequest(Message message, Object[] parameters)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc)
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)
at System.ServiceModel.Dispatcher.ChannelHandler.DispatchAndReleasePump(RequestContext request, Boolean cleanThread, OperationContext currentOperationContext)
at System.ServiceModel.Dispatcher.ChannelHandler.HandleRequest(RequestContext request, OperationContext currentOperationContext)
at System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult result)
at System.ServiceModel.Dispatcher.ChannelHandler.OnAsyncReceiveComplete(IAsyncResult result)
at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously)
at System.Runtime.InputQueue`1.AsyncQueueReader.Set(Item item)
at System.Runtime.InputQueue`1.EnqueueAndDispatch(Item item, Boolean canDispatchOnThisThread)
at System.Runtime.InputQueue`1.EnqueueAndDispatch(T item, Action dequeuedCallback, Boolean canDispatchOnThisThread)
at System.ServiceModel.Channels.SingletonChannelAcceptor`3.Enqueue(QueueItemType item, Action dequeuedCallback, Boolean canDispatchOnThisThread)
at System.ServiceModel.Channels.HttpChannelListener.HttpContextReceived(HttpRequestContext context, Action callback)
at System.ServiceModel.Channels.SharedHttpTransportManager.OnGetContextCore(IAsyncResult result)
at System.ServiceModel.Channels.SharedHttpTransportManager.OnGetContext(IAsyncResult result)
at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.ListenerAsyncResult.WaitCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
</StackTrace>
class DispatchByBodyElementOperationSelector : IDispatchOperationSelector
{
Dictionary<XmlQualifiedName, string> dispatchDictionary;
public DispatchByBodyElementOperationSelector(Dictionary<XmlQualifiedName, string> dispatchDictionary)
{
this.dispatchDictionary = dispatchDictionary;
}
#region IDispatchOperationSelector Members
private Message CreateMessageCopy(Message message, XmlDictionaryReader body)
{
//Message copy = Message.CreateMessage(message.Version, message.Headers.Action, body);
//copy.Headers.CopyHeaderFrom(message, 0);
//copy.Properties.CopyProperties(message.Properties);
//return copy;
MessageBuffer buffer = message.CreateBufferedCopy(Int32.MaxValue);
Message copy = buffer.CreateMessage();
buffer.Close();
copy.Headers.CopyHeaderFrom(message, 0);
copy.Properties.CopyProperties(message.Properties);
return copy;
}
public string SelectOperation(ref System.ServiceModel.Channels.Message message)
{
XmlDictionaryReader bodyReader = message.GetReaderAtBodyContents();
XmlQualifiedName lookupQName = new XmlQualifiedName(bodyReader.LocalName, bodyReader.NamespaceURI);
message = CreateMessageCopy(message,bodyReader);
if (dispatchDictionary.ContainsKey(lookupQName))
{
return dispatchDictionary[lookupQName];
}
else
{
return null;
}
}
#endregion
}
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Interface)]
sealed class DispatchByBodyBehaviorAttribute : Attribute, IContractBehavior
{
#region IContractBehavior Members
public void AddBindingParameters(ContractDescription contractDescription, ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
{
// no binding parameters need to be set here
return;
}
public void ApplyClientBehavior(ContractDescription contractDescription, ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
{
// this is a dispatch-side behavior which doesn't require
// any action on the client
return;
}
public void ApplyDispatchBehavior(ContractDescription contractDescription, ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.DispatchRuntime dispatchRuntime)
{
// We iterate over the operation descriptions in the contract and
// record the QName of the request body child element and corresponding operation name
// to the dictionary to be used for dispatch
Dictionary<XmlQualifiedName,string> dispatchDictionary = new Dictionary<XmlQualifiedName,string>();
foreach( OperationDescription operationDescription in contractDescription.Operations )
{
XmlQualifiedName qname =
new XmlQualifiedName(operationDescription.Messages[0].Body.WrapperName, operationDescription.Messages[0].Body.WrapperNamespace);
if (qname.IsEmpty)
{
qname = new XmlQualifiedName(operationDescription.Messages[0].Body.Parts[0].Name, operationDescription.Messages[0].Body.Parts[0].Namespace);
}
dispatchDictionary.Add(qname, operationDescription.Name);
}
// Lastly, we create and assign and instance of our operation selector that
// gets the dispatch dictionary we've just created.
dispatchRuntime.OperationSelector =
new DispatchByBodyElementOperationSelector(dispatchDictionary);
}
public void Validate(ContractDescription contractDescription, ServiceEndpoint endpoint)
{
//
}
#endregion
}
最佳答案
您应该使用MessageBuffer.CreateMessage
:
The body of a
Message
instance can only be consumed or written once. If you wish to consume a Message instance more than once, you should use theMessageBuffer
class to completely store an entireMessage
instance into memory.
http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.messagebuffer.aspx
我当前项目的代码:
public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
{
MessageBuffer buffer = reply.CreateBufferedCopy(Int32.MaxValue);
reply = buffer.CreateMessage();
Message m = buffer.CreateMessage();
LogMessage(m, " Response => ");
}
为 Message
参数添加 ref
并返回新消息。
private Message CreateMessageCopy(ref Message message, XmlDictionaryReader body)
{
...
message = buffer.CreateMessage();
关于wcf - 错误 "This message cannot support the operation because it has been read",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11039434/
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎离题,因为它缺乏足够的信息来诊断问题。 更详细地描述您的问题或include a minim
家庭作业 必须同时重载 operator>(istream &in, Complex &value); public: // constructor Compl
这个问题在这里已经有了答案: What are the basic rules and idioms for operator overloading? (8 个答案) 关闭 5 年前。 有什么区别
这是文档中一个不清楚的示例,使用此运算符:http://package.elm-lang.org/packages/elm-lang/core/3.0.0/Json-Decode#at 最佳答案 请注
我不明白这种行为: > sort([1,2,3,4]) ~~ sort([1,2,3,4]) False 你能给我解释一下吗? 为什么这两个列表(显然是相等的)根据 Perl 6 不相等。 更新 有趣
我正在尝试将 Ø 设为逻辑否定运算符。 ¬ True; multi sub prefix: ($n) { return not $n; } 当我运行上面的程序时,它返回以下错误: $
class Port { private: char * brand; char style[20]; // i.e., tawny, ruby, vintage int bo
早上好。我有一些问题。我有这些字段: name: "Mike", city: "NY", address: "something", pets: ["dog", "cat"] 我创建了索引 db.pe
我有以下代码使用 Javascript Webcrypto-API 解密 AES 加密数据,但它会导致“OperationError”并显示消息“操作因操作特定原因而失败”: function loa
我制作了一个自定义 Airflow 操作符,这个操作符接受一个输入,这个操作符的输出在 XCOM 上。 我想要实现的是使用一些定义的输入调用运算符,将输出解析为可在分支运算符内部调用的 Python,
int a = 1; a += ++a; cout << a << endl; // 4 int a = 1; a += a++; cout << a << endl; // 3 为什么这两个例子有不
我有这个队列的实现: #include using namespace std; template struct elem_q { T inf; elem_q* link; }; template
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
我对 C++ 中的运算符重载有疑问。我有代表复数的结构,我正在重载运算符,所以我可以用复数进行计算。Visual Studio 2012 给我这个错误:1 IntelliSense:没有运算符“!=”
我正在尝试创建一个 BoolArray 类,它表示一个 bool 值数组,而不是为每个 bool 变量保存 1 个 bool 值。它使用 1 个字符变量来表示使用位的 8 个 bool 值,并节省内存
我类有 2 个运算符有点问题。 我的类(class)宣布: template class MyMap{ keyType keys[MAX]; valueType values[MAX
我有类的迭代器模板和用于 for 语句的类。 template class Itr2 { public: Itr2() { } ~Itr2() { } typedef t
Section 7.2 Enumeration declarations 没有说明任何关于 operator!=() 和作用域的 operator==()枚举。但是下面的代码可以编译。 #includ
我需要将一个 int 序列化到本地文件并将其读入内存。这是代码 #include "stdafx.h" #include #include using namespace std; int _tm
operator += 这样定义对吗?! void operator +=(const BigNumber& other) { *this=(*this) + other; } 在这样的类中:
我是一名优秀的程序员,十分优秀!