【发布时间】:2013-01-14 05:29:11
【问题描述】:
我有以下代码:
返回以下异常:
ProtocolException was unhandled by user code
The remote server returned an unexpected response: (405) Method Not Allowed.
我尝试使用以下命令(在命令提示符中使用 Administrator):
C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation>ServiceModelReg.exe -i
然后出现以下内容:
Microsoft(R) Windows Communication Foundation Installation Utility
[Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.5420]
Copyright (c) Microsoft Corporation. All rights reserved.
Installing: Machine.config Section Groups and Handlers (WOW64)
Installing: Machine.config Section Groups and Handlers
Installing: System.Web Build Provider (WOW64)
Installing: System.Web Compilation Assemblies (WOW64)
Installing: HTTP Handlers (WOW64)
Installing: HTTP Modules (WOW64)
Installing: System.Web Build Provider
Installing: System.Web Compilation Assemblies
Installing: HTTP Handlers
Installing: HTTP Modules
Installing: Protocol node for protocol net.tcp (WOW64)
Installing: TransportConfiguration node for protocol net.tcp (WOW64)
Installing: ListenerAdapter node for protocol net.tcp
Installing: Protocol node for protocol net.tcp
Installing: TransportConfiguration node for protocol net.tcp
Installing: Protocol node for protocol net.pipe (WOW64)
Installing: TransportConfiguration node for protocol net.pipe (WOW64)
Installing: ListenerAdapter node for protocol net.pipe
Installing: Protocol node for protocol net.pipe
Installing: TransportConfiguration node for protocol net.pipe
Installing: Protocol node for protocol net.msmq (WOW64)
Installing: TransportConfiguration node for protocol net.msmq (WOW64)
Installing: ListenerAdapter node for protocol net.msmq
Installing: Protocol node for protocol net.msmq
Installing: TransportConfiguration node for protocol net.msmq
Installing: Protocol node for protocol msmq.formatname (WOW64)
Installing: TransportConfiguration node for protocol msmq.formatname (WOW64)
Installing: ListenerAdapter node for protocol msmq.formatname
Installing: Protocol node for protocol msmq.formatname
Installing: TransportConfiguration node for protocol msmq.formatname
Installing: HTTP Modules (WAS)
Installing: HTTP Handlers (WAS)
但是,异常仍然存在!
感谢任何建议。
(会不会是 .NET Framework 的原因?)
我尝试了以下方法:
C:\Windows\Microsoft.NET\Framework\v4.0.30319>ServiceModelReg.exe -i
但它返回给我以下内容:
[Error]Switch '-c' requires a component to be specified for installation or uninstallation. Please specify which components to install or uninstall.
感谢任何有用的建议。
添加信息
Customers.aspx.cs
public partial class Services_Customers : System.Web.UI.Page
{
private System.Data.DataTable countryDataTable = null;
protected void Page_Load(object sender, EventArgs e)
{
// Retrieve DataTable from cache
countryDataTable =
(System.Data.DataTable)Cache["Countries"];
}
protected void GetCountriesButton_Click(object sender, EventArgs e)
{
// Does cached item exist?
if (countryDataTable == null)
{
CustomersClient customersService = new CustomersClient();
// Retrieve DataTable from WCF Service
countryDataTable = customersService.GetCountries(StartingLettersTextBox.Text);
// Save DataTable to cache
Cache["Countries"] = countryDataTable;
}
// Set GridView DataSource
CustomersGridView.DataSource = countryDataTable;
CustomersGridView.DataBind();
}
}
web.config
以下代码在 web.config 文件中的<configuration> 内:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ICustomers" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:1112/Services/Customers.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICustomers" contract="CustomersService.ICustomers" name="BasicHttpBinding_ICustomers" />
</client>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
【问题讨论】:
-
你叫什么方法?你的绑定是什么?
-
请不要把你的标题和标签堆在一起,没有必要。
-
@Grumbler85,我在我的问题中添加了额外的信息。
-
因为它是一个HTTP请求,它可能使用POST或GET,但不允许这样做,但我不能告诉你为什么。这可能是各种配置问题。谷歌可能对此了解很多。
-
@Grumbler85,我刚刚找到答案,也许你能帮我复习一下我的答案?
标签: c# asp.net visual-studio-2010 wcf