string address = string.Format("http://{0}:82", ipAddr.ToString());
var config = new HttpSelfHostConfiguration(address);
config.Services.Replace(typeof(ITraceWriter), new sss());
config.Routes.MapHttpRoute(
"WebApi", "api/{controller}/{action}/{id}",
new { id = RouteParameter.Optional });
using (HttpSelfHostServer server = new HttpSelfHostServer(config))
{
server.OpenAsync().Wait();
//RegisterApis(server.Configuration);
Console.WriteLine("The server is running");
Console.ReadLine();
}
but the server crashed when i requet the server in my ios app
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
Marked as answer by xiaoweiyu on Jun 18, 2012 03:47 PM
xiaoweiyu
Member
3 Points
11 Posts
webapi rc self host crash when httpheader has special character
Jun 16, 2012 07:10 AM|LINK
string address = string.Format("http://{0}:82", ipAddr.ToString()); var config = new HttpSelfHostConfiguration(address); config.Services.Replace(typeof(ITraceWriter), new sss()); config.Routes.MapHttpRoute( "WebApi", "api/{controller}/{action}/{id}", new { id = RouteParameter.Optional }); using (HttpSelfHostServer server = new HttpSelfHostServer(config)) { server.OpenAsync().Wait(); //RegisterApis(server.Configuration); Console.WriteLine("The server is running"); Console.ReadLine(); }but the server crashed when i requet the server in my ios app
i find the reason is my http request had the httpheader where key is "User-Agent" and value is "大彩�? 1.0 ipod touch;iphone os 5.0.1;zh-cn"
so,when the httprequet header has special character,the web api server will be crash
how can i handle the error
imran_ku07
All-Star
45785 Points
7698 Posts
MVP
Re: webapi rc self host crash when httpheader has special character
Jun 17, 2012 06:00 PM|LINK
I was unable to reproduce this in Fiddler.
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
xiaoweiyu
Member
3 Points
11 Posts
Re: webapi rc self host crash when httpheader has special character
Jun 18, 2012 12:54 AM|LINK
the server will crash, "User-Agent"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
imran_ku07
All-Star
45785 Points
7698 Posts
MVP
Re: webapi rc self host crash when httpheader has special character
Jun 18, 2012 02:20 AM|LINK
Not crushing self host with these headers.
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
xiaoweiyu
Member
3 Points
11 Posts
Re: webapi rc self host crash when httpheader has special character
Jun 18, 2012 11:53 AM|LINK
my self host web api server crashed
os: windows 7 [chinese simple]
vs 2012 rc
xiaoweiyu
Member
3 Points
11 Posts
Re: webapi rc self host crash when httpheader has special character
Jun 18, 2012 12:18 PM|LINK
i think i find why my host crashed.
i changed my system Non Unicode application Language to english
the application will not crash
This may be a bug in unicode language operating system
when i changed my system Non Unicode application Language to chinese
the web api host will crash agein
xiaoweiyu
Member
3 Points
11 Posts
Re: webapi rc self host crash when httpheader has special character
Jun 18, 2012 12:59 PM|LINK
how can i handle this with out changing my syetem Non Unicode application Language
imran_ku07
All-Star
45785 Points
7698 Posts
MVP
Re: webapi rc self host crash when httpheader has special character
Jun 18, 2012 03:32 PM|LINK
According to HTTP Specification, these chrecters are invalid in header value. So, this is why you are getting this exception. This is definately a bug of web-api. Self host application running on Non-Unicode OS can be easily broken by sending a header value with invalid character.
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
xiaoweiyu
Member
3 Points
11 Posts
Re: webapi rc self host crash when httpheader has special character
Jun 18, 2012 03:48 PM|LINK
i got it,thanks for your help
xiaoweiyu
Member
3 Points
11 Posts
Re: webapi rc self host crash when httpheader has special character
Jun 20, 2012 01:32 AM|LINK
see my chinese blog http://www.cnblogs.com/xiaoweiyu/archive/2012/06/16/2551892.html