gpt4 book ai didi

asp.net - 调试IIS中托管的asp.net WCF服务

转载 作者:行者123 更新时间:2023-12-03 22:23:18 25 4
gpt4 key购买 nike

我已经使用以下模板创建了WCF服务:

http://visualstudiogallery.msdn.microsoft.com/fbc7e5c1-a0d2-41bd-9d7b-e54c845394cd

该服务具有以下方法:

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

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

}

}

我已经在IIS上托管了此服务,方法的url是:

http://[本地]主机/通知/RecordingCompleted/

当我在地址栏中键入该地址时,我得到:
Method not allowed. Please see the service help page for constructing valid requests to the service.

我正在尝试使用以下代码使用此Web服务:

字符串serviceBaseUrl =“http://[本地] host/Notifications/RecordingCompleted/”;
        string resourceUrl = "";
string method = "POST";
//string jsonText = "}";
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;
}

我正在尝试调试服务方法,但我不知道该怎么做。请建议我输入时为什么出现错误
地址栏中的http://[local]主机/Notifications/RecordingCompleted/。以及如何调试本地主机上托管的服务?

问候,
阿西夫·哈米德(Asif Hameed)

最佳答案

在调试之前,您必须将dll和pdb部署到IIS目录。接下来,在VS中,单击debug-> Attach to process。“确保检查所有用户的显示过程”和“在所有 session 中显示过程”,现在应该在可用过程列表中看到W3WP过程。选择W3WP,然后单击附加。

现在,您应该能够调试WCF服务了。请引用以下博客以获取更多调试提示

http://dhawalk.blogspot.com/2007/07/debugging-tips-in-c.html
http://anilsharmadhanbad.blogspot.com/2009/07/debugging-wcf-service-hosted-in-local.html

关于asp.net - 调试IIS中托管的asp.net WCF服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15809865/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com