将文本文件的内容发送到 WCF Web 服务

发布于 2024-12-19 03:13:03 字数 1623 浏览 4 评论 0原文

我正在开发一个项目,其中涉及调用 WCF Web 服务将给定文件的内容上传到 WCF Web 服务。客户端是使用 Titanium Studio 编写的 iPad 应用程序。但我可以发送小于 8KB 的文件。但我发送的文件可能大于 8KB。当我发送大于 8KB 的文件时,Web 服务返回以下错误消息。

服务器在处理请求时遇到错误

客户端代码

下面给出的是调用数据使用 JSON 格式发送到 Web 服务的

        var readFile = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'log.txt');

        modifiedDate = readFile.modificationTimestamp();
        var payload ={dateTime: modifiedDate, fileName:'log.txt' , text:readFile};


    var xhrLog = Titanium.Network.createHTTPClient();
    var serviceUrl = 'http://192.168.134.134/webservice/viewerservice.svc/submitLogData/';

    xhrLog.open("POST", serviceUrl);
    xhrLog.setRequestHeader("Content-Type", "");
    xhrLog.setRequestHeader("Authentication-Token", "605b32dd");    
    xhrLog.onload = function() {
        Ti.API.info(this.responseText);
    },
    xhrLog.onerror = function() {

    }
    xhrLog.send(JSON.stringify(sendData));

。以下是 WCF Web 服务中用于检索数据的服务协定和数据协定。

[OperationContract]
        [WebInvoke(
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Bare,
            UriTemplate = "/SubmitLogData/")]
        bool SubmitLogData(List<LogData> log);

数据合约

[DataContract]
    public class LogData
    {
        [DataMember]
        public string dateTime { get; set; }

        [DataMember]
        public string fileName { get; set; }

        [DataMember]
        public string text { get; set; }
    }

I am working on a project where it involves calling a WCF web service to upload content of a given file to a WCF web service. client is a iPad application written using Titanium Studio. But i am allowed to send files which are less than 8KB in size. but files i am sending can be large in size than 8KB. when i send files which are larger than 8KB, web service return following error message.

The server encountered an error processing the request

Given below is the client code which call

Data is sent to the web service using JSON format.

        var readFile = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'log.txt');

        modifiedDate = readFile.modificationTimestamp();
        var payload ={dateTime: modifiedDate, fileName:'log.txt' , text:readFile};


    var xhrLog = Titanium.Network.createHTTPClient();
    var serviceUrl = 'http://192.168.134.134/webservice/viewerservice.svc/submitLogData/';

    xhrLog.open("POST", serviceUrl);
    xhrLog.setRequestHeader("Content-Type", "");
    xhrLog.setRequestHeader("Authentication-Token", "605b32dd");    
    xhrLog.onload = function() {
        Ti.API.info(this.responseText);
    },
    xhrLog.onerror = function() {

    }
    xhrLog.send(JSON.stringify(sendData));

Following is the service contract and data contract used in the WCF web service to retrive data.

[OperationContract]
        [WebInvoke(
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Bare,
            UriTemplate = "/SubmitLogData/")]
        bool SubmitLogData(List<LogData> log);

Data Contract

[DataContract]
    public class LogData
    {
        [DataMember]
        public string dateTime { get; set; }

        [DataMember]
        public string fileName { get; set; }

        [DataMember]
        public string text { get; set; }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紅太極 2024-12-26 03:13:03

您可能需要增加所有配额 - 消息大小示例 - 将如果您可以启用 WCF 服务器端跟踪并查看确切的错误消息,将会很有帮助!

更新:wsHttpBinding 的示例:

<binding name="wsHttp" maxReceivedMessageSize="2147483647">
  <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
    maxArrayLength="2147483647" maxBytesPerRead="2147483647"
    maxNameTableCharCount="2147483647" >
</binding>

You probably need to increase all the quotas - example of messagesize - would be helpfull if you could enable the WCF server-side tracing and see the exact error message!

UPDATE: example for a wsHttpBinding:

<binding name="wsHttp" maxReceivedMessageSize="2147483647">
  <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
    maxArrayLength="2147483647" maxBytesPerRead="2147483647"
    maxNameTableCharCount="2147483647" >
</binding>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文