远程服务器返回错误:(504)网关超时

时间:2013-04-05 12:01:12

标签: asp.net wcf web-services wcf-data-services

我使用http://visualstudiogallery.msdn.microsoft.com/fbc7e5c1-a0d2-41bd-9d7b-e54c845394cd创建了一项网络服务。我在我的IIS上托管它并创建了一个部署在IIS上的测试应用程序,它可以工作。现在,我托管了这个WCF服务,并试图从localhost使用/使用它,但它在以下行中出错:

var response = request.GetResponse()as HttpWebResponse;

,错误是

The remote server returned an error: (504) Gateway Timeout.

在小提琴手中显示:

Fiddler] ReadResponse()失败:服务器未返回此请求的响应。

request header in fiddler is:

POST /Notifications/RecordingCompleted HTTP/1.1

Entity:

Content-Length: 792
Content-Type: application/json

Transport
Connection: Keep-Alive
Expect: 100-continue

代码是:

string serviceBaseUrl = serviceurlhere         string conversationId = 2342423         string resourceUrl =“”;         string method =“POST”;         string jsonText =“JSON here”;

       string success = UseHttpWebApproach(serviceBaseUrl, resourceUrl, method, jsonText);

 private string UseHttpWebApproach(string serviceUrl, string resourceUrl, string method, string requestBody)
        {
            string responseMessage = null;
            var request = WebRequest.Create(string.Concat(serviceUrl, resourceUrl)) as HttpWebRequest;
            if (request != null)
            {
                request.ContentType = "application/json";
                request.Method = method;                 
            }

            //var objContent = HttpContentExtensions.CreateDataContract(requestBody);
            if (method == "POST" && requestBody != null)
            {
                byte[] requestBodyBytes = ToByteArrayUsingJsonContractSer(requestBody);
                request.ContentLength = requestBodyBytes.Length;
                using (Stream postStream = request.GetRequestStream())
                    postStream.Write(requestBodyBytes, 0, requestBodyBytes.Length);

            }

            if (request != null)
            {
                var response = request.GetResponse() as HttpWebResponse;
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    Stream responseStream = response.GetResponseStream();
                    if (responseStream != null)
                    {
                        var reader = new StreamReader(responseStream);

                        responseMessage = reader.ReadToEnd();
                    }
                }
                else
                {
                    responseMessage = response.StatusDescription;
                }
            }
            return responseMessage;
        }

private static byte[] ToByteArrayUsingJsonContractSer(string requestBody)
{
    byte[] bytes = null;
    var serializer1 = new DataContractJsonSerializer(typeof(string));
    var ms1 = new MemoryStream();
    serializer1.WriteObject(ms1, requestBody);
    ms1.Position = 0;
    var reader = new StreamReader(ms1);
    bytes = ms1.ToArray();
    return bytes;
}

服务代码是:

 [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]    
    public class RecordingCompleted
    {

        [WebInvoke(UriTemplate = "", Method = "POST")]
        public string ProcessCall(string JsonData)
        {

return string result
}

}

0 个答案:

没有答案