VS2005(C#)编写Web Service 运行在客户那边偶尔出现IIS错误,现在不知道问题,希望得到高手的指点
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VS2005(C#)编写Web Service 运行在客户那边偶尔出现IIS错误,现在不知道问题,希望得到高手的指点相关的知识,希望对你有一定的参考价值。
错误信息如下:
- <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
- <System>
<Provider Name="ASP.NET 2.0.50727.0" />
<EventID Qualifiers="49152">1334</EventID>
<Level>2</Level>
<Task>0</Task>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2013-05-17T23:31:47.000Z" />
<EventRecordID>8023</EventRecordID>
<Channel>Application</Channel>
<Computer>SLS-TMS.SLI-SLS.LOCAL</Computer>
<Security />
</System>
- <EventData>
<Data>An unhandled exception occurred and the process was terminated. Application ID: /LM/W3SVC/1/ROOT/WebTMS Process ID: 5760 Exception: System.Net.WebException Message: Unable to connect to the remote server StackTrace: at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context) at System.Net.HttpWebRequest.GetRequestStream() at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) at WebTMS.WebServiceServer.Logout(String sessionID, String interfaceType) at WebUpdateTimer.WebTranEnquiryThread(Object stateInfo) at System.Threading._TimerCallback.TimerCallback_Context(Object state) at System.Threading.ExecutionContext.runTryCode(Object userData) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading._TimerCallback.PerformTimerCallback(Object state) InnerException: System.Net.Sockets.SocketException Message: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond StackTrace: at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)</Data>
</EventData>
</Event>
C#使用SOAP调用Web Service
using System.IO;
using System.Net;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//构造soap请求信息
StringBuilder soap = new StringBuilder();
soap.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
soap.Append("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">");
soap.Append("<soap:Body>");
soap.Append("<getWeather xmlns=\"http://WebXml.com.cn/\">");
soap.Append("<theCityCode>2210</theCityCode>");
soap.Append("<theUserID></theUserID>");
soap.Append("</getWeather>");
soap.Append("</soap:Body>");
soap.Append("</soap:Envelope>");
//发起请求
Uri uri = new Uri("http://www.webxml.com.cn/WebServices/WeatherWS.asmx");
WebRequest webRequest = WebRequest.Create(uri);
webRequest.ContentType = "text/xml; charset=utf-8";
webRequest.Method = "POST";
using (Stream requestStream = webRequest.GetRequestStream())
{
byte[] paramBytes = Encoding.UTF8.GetBytes(soap.ToString());
requestStream.Write(paramBytes, 0, paramBytes.Length);
}
//响应
WebResponse webResponse = webRequest.GetResponse();
using (StreamReader myStreamReader = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8))
{
Console.WriteLine(myStreamReader.ReadToEnd());
}
Console.ReadKey();
}
}
}
返回结果:
感冒指数:将有一次强降温过程,且空气湿度较大,极易发生感冒,请特别注意增加衣服保暖防寒。
晨练指数:有阵雨,较不宜晨练,若坚持室外锻炼,请携带雨具。建议年老体弱人群适当减少晨练时间。
洗车指数:不宜洗车,未来24小时内有雨,如果在此期间洗车,雨水和路上的泥水可能会再次弄脏您的爱车。
晾晒指数:偶尔的降雨可能会淋湿晾晒的衣物,不太适宜晾晒。请随时注意天气变化。
旅游指数:有阵雨,温度适宜,在细雨中游玩别有一番情调,可不要错过机会呦!但记得出门要携带雨具。
路况指数:有小雨,路面潮湿,车辆易打滑,请小心驾驶。
舒适度指数:白天不太热也不太冷,风力不大,相信您在这样的天气条件下,应会感到比较清爽和舒适。</string><string>1月21日 阵雨转小雨</string><string>12℃/19℃</string><string>无持续风向微风</string><string>3.gif</string><string>7.gif</string><string>1月22日 小雨</string><string>9℃/14℃</string><string>无持续风向微风</string><string>7.gif</string><string>7.gif</string><string>1月23日 小雨</string><string>8℃/12℃</string><string>无持续风向微风</string><string>7.gif</string><string>7.gif</string><string>1月24日 阴</string><string>12℃/17℃</string><string>无持续风向微风</string><string>2.gif</string><string>2.gif</string><string>1月25日 多云</string><string>13℃/18℃</string><string>无持续风向微风</string><string>1.gif</string><string>1.gif</string></getWeatherResult></getWeatherResponse></soap:Body></soap:Envelope>
ASP版
Dim xmlHttp,soap
soap = soap & "<?xml version=""1.0"" encoding=""utf-8""?>"
soap = soap & "<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">"
soap = soap & "<soap:Body>"
soap = soap & "<getWeather xmlns=""http://WebXml.com.cn/"">"
soap = soap & "<theCityCode>2210</theCityCode>"
soap = soap & "<theUserID></theUserID>"
soap = soap & "</getWeather>"
soap = soap & "</soap:Body>"
soap = soap & "</soap:Envelope>"
Set xmlHttp = CreateObject("MSXML2.XMLHTTP")
xmlHttp.Open "post","http://www.webxml.com.cn/WebServices/WeatherWS.asmx",false
xmlHttp.SetRequestHeader "Content-Type","text/xml; charset=utf-8"
‘曾见过Java的ws要求一定要有SOAPAction,否则报错no SOAPAction header!
xmlHttp.SetRequestHeader "SOAPAction","http://WebXml.com.cn/getWeather"
xmlHttp.Send(soap)
If xmlHttp.Status = 200 Then
Response.Write(xmlHttp.responseXML.xml)
End If
Set xmlHttp = Nothing
%>
带SoapHeader的Web Service调用
using System.IO;
using System.Net;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//构造soap请求信息
StringBuilder soap = new StringBuilder();
soap.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
soap.Append("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">");
soap.Append("<soap:Header>");
soap.Append("<MySoapHeader xmlns=\"http://www.mzwu.com/\" soap:mustUnderstand=\"1\">");//mustUnderstand=1,接收者必须能处理此SoapHeader信息,否则返回错误
soap.Append("<UserName>admin</UserName>");
soap.Append("<UserPass>admin888</UserPass>");
soap.Append("</MySoapHeader>");
soap.Append("</soap:Header>");
soap.Append("<soap:Body>");
soap.Append("<Hello xmlns=\"http://www.mzwu.com/\">");
soap.Append("<name>dnawo</name>");
soap.Append("</Hello>");
soap.Append("</soap:Body>");
soap.Append("</soap:Envelope>");
//发起请求
Uri uri = new Uri("http://localhost:39674/Service1.asmx");
WebRequest webRequest = WebRequest.Create(uri);
webRequest.ContentType = "text/xml; charset=utf-8";
webRequest.Method = "POST";
using (Stream requestStream = webRequest.GetRequestStream())
{
byte[] paramBytes = Encoding.UTF8.GetBytes(soap.ToString());
requestStream.Write(paramBytes, 0, paramBytes.Length);
}
//响应
WebResponse webResponse = webRequest.GetResponse();
using (StreamReader myStreamReader = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8))
{
Console.WriteLine(myStreamReader.ReadToEnd());
}
Console.ReadKey();
}
}
}
小技巧
在浏览器中查看Web Service时,有详细的SOAP请求和响应示例:
参考资料
·SOAP教程:http://www.w3school.com.cn/soap/index.asp
·简单对象访问协议:http://zh.wikipedia.org/zh-cn/SOAP
·SOAP调用Web Service:http://book.51cto.com/art/200906/129733.htm
·关于朗新WEBSERVER接口问题:http://fpcfjf.blog.163.com/blog/static/5546979320081069223827/
以上是关于VS2005(C#)编写Web Service 运行在客户那边偶尔出现IIS错误,现在不知道问题,希望得到高手的指点的主要内容,如果未能解决你的问题,请参考以下文章
treeview中的checkbox如何全部选中呢?(c#,web,vs2005)
求将dataset数据集导出到excel文件的方法(vs2005 c#)
vs2005新建项目中没有ASP.NET WEB应用程序,如何建立?