我有一个寻找流数据的wcf服务
[MessageContract]
public class NextService : INextService
{
[WebInvoke(Method = "POST", UriTemplate = "*")]
public void Upload(Stream data)
{
try
{
_log.InfoFormat("-------------{0}------------------------------", data);
var request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
_log.InfoFormat(request.Method + " ");// + request.UriTemplateMatch.RequestUri.AbsolutePath);
foreach (string headerName in headers.AllKeys)
{
_log.InfoFormat(headerName + ": " + headers[headerName]);
}
if (File.Exists(@"c:\\test\\ViewDocumentOp.pdf"))
File.Delete(@"c:\\test\\ViewDocumentOp.pdf");
using (FileStream fs = new FileStream(@"c:\\test\\ViewDocumentOp.pdf", FileMode.CreateNew, FileAccess.Write))
{
CopyStream(data, fs);
}
StreamReader bodyReader = new StreamReader(data);
string bodyString = bodyReader.ReadToEnd();
int length = bodyString.Length;
_log.InfoFormat("-------------------------------------------------------");
}
catch (Exception ex)
{
_log.ErrorFormat(" Error in UploadDoc {0} Message : {1}", ex.StackTrace, ex.Message);
}
}
下面是界面
[ServiceContract]
public interface INextService
{
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare)]
void Upload(Stream data);
}
我在绑定中添加了带有MTOM详细信息的webconfig
<basicHttpBinding>
<binding name="Encode" messageEncoding="Mtom" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
transferMode="Streamed">
</binding>
</basicHttpBinding>
<service behaviorConfiguration="NextServiceBehavior" name="SupportingDocsFacade.NextService">
<endpoint address="/Upload" binding="basicHttpBinding" bindingConfiguration="Encode"
name="Basic" contract="SupportingDocsFacade.INextGenService" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
我正在使用Soap UI来称呼它也有附件。 SoapUI中显示的原始数据具有边界数据我已按照以下SoapDoc
在request属性中启用MTOM某些数据未到达网络服务的方式。上载服务中的日志打印为
------------- System.ServiceModel.Dispatcher.StreamFormatter + MessageBodyStream -------------------------- ----
首先,我们无法将数据(调用服务)直接发布到Basichttpbinding创建的服务地址。这仅适用于由Webhttpbinding创建的WCF休息样式服务。can't receive xml post request values in wcf c#
如果我们使用Basichttpbinding创建服务,则应使用基地址来传递流数据,如文档中所述。https://www.soapui.org/docs/soap-and-wsdl/attachments.html我们利用内联文件来传递stream参数。请参见下面的屏幕截图。请随时告诉我是否有什么我可以帮助的。