具有流服务的JAX-WS MTOM的WCF客户端

时间:2013-03-19 14:12:54

标签: wcf jax-ws

我们有这样的JAX-WS Web服务:

public class NamedDataHandlerContainer {
    public String options; // format is option1_name=option1_value;option2_name=option2_value
    @XmlMimeType("application/octet-stream") public DataHandler dataHandler;
}

@WebService
public interface mtomserver {
    @WebMethod public int saveFile(String name,
    @XmlMimeType("application/octet-stream") List<NamedDataHandlerContainer> contents,
    @XmlMimeType("application/octet-stream") @WebParam(mode = WebParam.Mode.OUT) Holder<List<NamedDataHandlerContainer>> results);
}

当使用.NET 4.0的SvcUtil处理该Web服务的WSDL时,它会为NamedDataHandlerContainer.dataHandler生成byte []类型:

public partial class namedDataHandlerContainer;
{
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = 0)]
    public string options;

    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, DataType = "base64Binary", Order = 1)]
    public byte[] dataHandler;
}

但是,在App.config中它会生成Mtom工件:

<basicHttpBinding>
    <binding name="mtomserverImplPortBinding" messageEncoding="Mtom" maxReceivedMessageSize="1000000000" />
</basicHttpBinding>

(我们添加了maxReceivedMessageSize以允许大量的attacghments)。事实上,WCF客户端向服务发送MTOM附件 - 我们正在转储HTTP有效负载并确认:

--uuid:394d798b-e43e-47cc-82dd-64e32ef51edd+id=1
Content-ID: <http://tempuri.org/0>
Content-Transfer-Encoding: 8bit
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><saveFile xmlns="http://wsserver.mtomtest/"><arg0 xmlns="">myfile.bin</arg0><arg1 xmlns=""><options>my options from .NET</options><dataHandler><xop:Include href="cid:http://tempuri.org/1/634993057692269386" xmlns:xop="http://www.w3.org/2004/08/xop/include"/></dataHandler></arg1></saveFile></s:Body></s:Envelope>
--uuid:394d798b-e43e-47cc-82dd-64e32ef51edd+id=1
Content-ID: <http://tempuri.org/1/634993057692269386>
Content-Transfer-Encoding: binary
Content-Type: application/octet-stream

<binary content goes here>

JAX-WS可以成功地将流应用于此类有效负载。但是,有没有办法在.NET端实现流媒体?我已经阅读过MSDN,其中明确指出只有一个启用了流的参数可能存在。但是,有没有办法让自定义消息序列化程序(或自定义的东西,我不是WCF的专家),仍然避免将整个有效负载加载到内存中。

1 个答案:

答案 0 :(得分:0)

WCF具有启用流式传输的配置。您无需编写任何其他代码即可实现此目的。

<basicHttpBinding>
    <binding name="mtomserverImplPortBinding" messageEncoding="Mtom" maxReceivedMessageSize="1000000000" transferMode="Streamed"/>
</basicHttpBinding>

来源:http://msdn.microsoft.com/en-us/library/ms789010.aspx