WCF REST 托管在 IIS 6 中,无法在客户端上使用它
我在 IIS6 中托管了 WCF REST 服务。但是当我尝试使用任何方法时,它会给我一个错误 400。
但是,当我在 IE 中使用相同的 url 时,就实现了所需的响应。为什么我不能在我的客户端中使用它,而我可以直接在 IE 中点击它。
以下是客户端代码:
string xmlInputValue = XMLUtility<string>.GetDataContractXml("Testing", null);
WebClient wc = new WebClient();
wc.Headers["Content-Type"] = "application/octet-stream";
xmlInputValue = string.Empty;
byte[] buf = new byte[0x10000];
wc.UploadString(new Uri(@"http://localhost/FileUpload/UploadData/PingTest/?123"), "POST", "4567");
I have hosted my WCF REST Service in IIS6. But when I try to consume any method, it gives me an error 400.
However when I use the same url in IE, the desired response is achieved. How come I can't consume it in my client while I can hit it directly in IE.
Following is the Client code :
string xmlInputValue = XMLUtility<string>.GetDataContractXml("Testing", null);
WebClient wc = new WebClient();
wc.Headers["Content-Type"] = "application/octet-stream";
xmlInputValue = string.Empty;
byte[] buf = new byte[0x10000];
wc.UploadString(new Uri(@"http://localhost/FileUpload/UploadData/PingTest/?123"), "POST", "4567");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
得到答案了。使用 IIS 托管服务时,端点地址应为空
Got the answer. While using IIS for hosting the service, endpoint address should be blank
一个简单的问题是,为什么将 Content-type 设置为“application/octet-stream”?您确定服务绑定需要相同的内容类型吗?无论如何,我会捕获 IE 的 Fiddler 跟踪(使用 fiddler 工具:http://fiddler2.com)(成功场景)并检查 IE 发送的请求如何被服务接受,并与客户端应用程序发送的请求进行比较。
哈特哈,
阿米特
One quick question, why are you setting Content-type as "application/octet-stream"? are you sure service binding is expecting the same content-type. Anyways, I'd capture Fiddler trace (using fiddler tool: http://fiddler2.com) for IE (success scenario) and check how request is sent by IE which is accepted by service and compare with request sent by client application.
HTH,
Amit