English 中文(简体)
WCF 请求机构有时是一流,有时是缓冲?
原标题:WCF Request body is sometimes a stream and sometimes buffered?

我拥有一个WCF网络服务。 在接到请求时,我试图进行一些伐木,在收割后活动中执行电文和伐木。

出于某种原因,每当我向网上服务机构发出使用WCF 试验Client的请求。 一切都得 fine。 该信息被封不动,请求按正常程序处理。

但是,当我向网络服务机构发出使用SOAPUI作为客户的请求时,制作请求书的复印件使该机构只能显示<代码><人与人”......溪流......</人与人>,并且后来为了验证而未能装上XML文件。

我猜测,世界渔委会提出的一项请求。 收到了一个缓冲信息机构,并收到了SOAPUI作为主流机构提出的请求? 如何做到这一点?

  • 我是否可以写一些能够安全地复制这两种版本的法典? 我尚未说明如何安全地复制一流版本,因为“创造机会”显然没有做到这一点。

  • 或者,我是否能够召集世界文化论坛,以便永远建立一个缓冲信息机构,从来不是一种流子?

这里是我用来记录和复制请求通知的守则:

object IDispatchMessageInspector.AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
{
    try
    {

        MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue);
        request = buffer.CreateMessage();

        Message copy = buffer.CreateMessage();

        LogRequest(copy);

        ValidateMessage(ref request);
    }
    catch (Exception e)
    {
        throw new FaultException<>()...
    }
    return null;
}

请求函文的复印件在ValidateMessage(ValidateMessage)方法中未能装入XML文件,如果该信息来自一个流体的SOAPUI。 如果来自世界渔委会的《禁试》文件,它就能够装上XML文件。 拥有一个缓冲机构。

void validateMessage(ref System.ServiceModel.Channels.Message message)
{
    XmlDocument bodyDoc = new XmlDocument();
    //This load throws exception if request came from SOAPUI with streamed body...
    bodyDoc.Load(message.GetReaderAtBodyContents());
    ...
}

The exception thrown by the Load() method is:

System.InvalidOperationException {"The specified node cannot be inserted as the valid child of this node, because the specified node is the wrong type."}

at System.Xml.XmlDocument.AppendChildForLoad(XmlNode newChild, XmlDocument doc) at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc) at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at ...

问题回答

I believe that SOAPUI always sends the message requests it builds as Stream. I do not know for sure if this is something you can modify, either by code on your SOAPUI test or some SOAPUI configuration option/file on SOAPUI.

Ckeck the TransferMode property of your binding as explained here and here. You could possibly have multiple endpoints using different custom bindings for clients that send you buffered request and stremed requests.

Hope this helps.

What s the exception being thrown? The reader returned by GetReaderAtBodyContents() is positioned at the first element inside the body, not on the body tag itself. So the way you re loading your message is incorrect because the body could contain more than one node and in that case it will fail.

仅检查一下,你是否可以使用以下代码验证整个电文(副本)的内容,并且看该机构在从社会调查局寄出时是否含有同样的内容?


using (MemoryStream stream = new MemoryStream())
{
    using (XmlWriter writer = XmlWriter.Create(stream))
    {
        message.WriteMessage(writer);
        writer.Flush();
        stream.Position = 0;
    }
}

如果你想要在身体内的所有节点,那么你就不得不成立一个机构。

“GetReaderAtBodyContents()”方法在身体封闭部分和肥皂封的封闭部分之间恢复了任何特性。 XmlReader在读过本机构关闭部分之前就没有例外。

More here: http://www.katlaconsulting.co.uk/blog/wcfxmlschemavalidation





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签