0

我想从我的 Windows Phone 应用程序将字节数组传递给 WCF 服务。网址如下所示

"http://serviceurl/Service1.svc/saverecord3?firstarray="

我怎样才能做到这一点?

4

1 回答 1

0

这是我的代码的一部分,我用它来将发布数据发送到我的服务器

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http:/serviceurl/Service1.svc/saverecord3");
                req.Method = "POST";

                req.ContentType = "text/xml; charset=utf-8"; //if your data is different, use a content type accordingly
                string postData = @"firstarray=thedatatosend";

                int length = arrayData.Length;

                // Convert the string into a byte array.
                byte[] byteArray = Encoding.UTF8.GetBytes(arrayData);
                req.Headers[HttpRequestHeader.ContentLength] = byteArray.Length.ToString();

                req.BeginGetRequestStream(ar =>
                {
                    using (var requestStream = req.EndGetRequestStream(ar))
                    {
                        // Write the body of your request here
                        requestStream.Write(byteArray, 0, length);
                    }

                    req.BeginGetResponse(a =>
                    {
                        try
                        {
                            var response = req.EndGetResponse(a);
                            var responseStream = response.GetResponseStream();

                            using (var streamRead = new StreamReader(responseStream))
                            {
                                // Get the response message here
                                string responseString = streamRead.ReadToEnd();
                                //Do whatever you want here, with the response
                            }
                        }
                        catch (Exception e)
                        {

                        }

                    }, null);

                }, null);
于 2013-04-04T08:25:28.020 回答