【问题标题】:Attachment data send from Soap UI is not received in WCF serviceWCF 服务未收到从 Soap UI 发送的附件数据
【发布时间】:2019-10-15 03:40:22
【问题描述】:

我有一个查找流数据的 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

在请求属性中启用了 MTOM

一些数据没有到达网络服务..上传服务中的日志打印是

-------------System.ServiceModel.Dispatcher.StreamFormatter+MessageBodyStream------------------------- -----

【问题讨论】:

    标签: c# wcf soapui soap-client mtom


    【解决方案1】:

    首先,我们不能直接将数据(调用服务)发布到Basichttpbinding创建的服务地址。这仅适用于 Webhttpbinding 创建的 WCF REST 样式服务。
    can't receive xml post request values in wcf c#

    http://xxxx:xx/service1.svc/upload

    如果我们使用Basichttpbinding创建服务,我们应该使用基地址来传递流数据,如文档中所述。
    https://www.soapui.org/docs/soap-and-wsdl/attachments.html
    我们利用内联文件来传递流参数。请看下面的截图。

    如果有什么我可以帮忙的,请随时告诉我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-28
      相关资源
      最近更新 更多