远程服务器返回了意外的响应:(405)不允许的方法 [英] The remote server returned an unexpected response: (405) Method Not Allowed
问题描述
我有以下的code:
这回我以下异常:
的ProtocolException是由用户code未处理远程服务器返回了意外的响应:(405)不允许的方法。
我试着用下面的命令(在命令提示符下使用管理
)
C:\\ WINDOWS \\ Microsoft.NET \\框架\\ 3.0 \\ Windows通讯基础> ServiceModelReg.exe -i
和以下出现:
微软(R)Windows通信基础安装实用程序
[微软(R)的Windows(R)通信基金会,版本3.0.4506.5420]
版权所有(c)Microsoft公司。版权所有。
安装:Machine.config中科组和处理程序(WOW64)安装:Machine.config中科组和处理程序安装:System.Web程序构建提供商(WOW64)安装:System.Web程序编译组件(WOW64)安装:HTTP处理程序(WOW64)安装:HTTP模块(WOW64)安装:System.Web程序构建提供安装:System.Web程序编译组件安装:HTTP处理程序安装:HTTP模块安装:协议节点协议的net.tcp(WOW64)安装:用于协议的net.tcp TransportConfiguration节点(WOW64)安装:用于协议的net.tcp ListenerAdapter节点安装:协议节点协议的net.tcp安装:用于协议的net.tcp TransportConfiguration节点安装:协议节点协议net.pipe(WOW64)安装:用于协议net.pipe TransportConfiguration节点(WOW64)安装:用于协议net.pipe ListenerAdapter节点安装:协议节点协议net.pipe安装:用于协议net.pipe TransportConfiguration节点安装:协议节点协议net.msmq(WOW64)安装:用于协议net.msmq TransportConfiguration节点(WOW64)安装:用于协议net.msmq ListenerAdapter节点安装:协议节点协议net.msmq安装:用于协议net.msmq TransportConfiguration节点安装:协议节点协议msmq.formatname(WOW64)安装:用于协议msmq.formatname TransportConfiguration节点(WOW64)安装:用于协议msmq.formatname ListenerAdapter节点安装:协议节点协议msmq.formatname安装:用于协议msmq.formatname TransportConfiguration节点安装:HTTP模块(WAS)安装:HTTP处理程序(WAS)
不过,例外还是有的!
鸭preciate任何建议。
(难道是因为.NET框架?)
我试过如下:
C:\\ WINDOWS \\ Microsoft.NET \\框架\\ v4.0.30319> ServiceModelReg.exe -i
但它返回我下面的:
[错误]开关-c需要安装或卸载到指定的组件。请指定要安装或卸载的组件。
鸭preciate任何有帮助的建议。
附加信息
Customers.aspx.cs
公共部分类Services_Customers:System.Web.UI.Page
{ 私人System.Data.DataTable countryDataTable = NULL; 保护无效的Page_Load(对象发件人,EventArgs的发送)
{
//从缓存中获取数据表
countryDataTable =
(System.Data.DataTable)高速缓存[国家]; }
保护无效GetCountriesButton_Click(对象发件人,EventArgs的发送)
{ //缓存项目确实存在?
如果(countryDataTable == NULL)
{ CustomersClient customersService =新CustomersClient();
//从WCF服务数据表
countryDataTable = customersService.GetCountries(StartingLettersTextBox.Text); //保存数据表缓存
缓存[国家] = countryDataTable; } //设置GridView控件的DataSource
CustomersGridView.DataSource = countryDataTable;
CustomersGridView.DataBind();
}
}
的web.config
以下code是在<结构>
在web.config文件:
< system.serviceModel>
<&绑定GT;
<&basicHttpBinding的GT;
<绑定名称=BasicHttpBinding_ICustomerscloseTimeout =00:01:00openTimeout =00:01:00receiveTimeout =00:10:00的SendTimeout =00:01:00allowCookies =false的bypassProxyOnLocal =假hostNameComparisonMode =StrongWildcardMAXBUFFERSIZE =65536maxBufferPoolSize =524288maxReceivedMessageSize =65536messageEncoding =文本textEncoding =UTF-8transferMode =缓冲useDefaultWebProxy =真>
< readerQuotas MAXDEPTH =32maxStringContentLength =8192maxArrayLength =16384maxBytesPerRead =4096maxNameTableCharCount =16384/>
<安全模式=无>
<运输clientCredentialType =无proxyCredentialType =无的境界=/>
<消息clientCredentialType =用户名algorithmSuite =默认/>
< /安全>
< /&结合GT;
< / basicHttpBinding的>
< /绑定>
<客户端>
<端点地址=HTTP://本地主机:1112 /服务/ Customers.svc绑定=basicHttpBinding的bindingConfiguration =BasicHttpBinding_ICustomers合同=CustomersService.ICustomersNAME =BasicHttpBinding_ICustomers/>
< /客户>
< serviceHostingEnvironment aspNetCompatibilityEnabled =真/>
< /system.serviceModel>
尝试添加以下行到您的web.config。
<&的WebHttpBinding GT;
<绑定名称=跨域crossDomainScriptAccessEnabled =真/>
< /&的WebHttpBinding GT;
的最终结果将是如下:
< system.serviceModel>
<&绑定GT;
<&的WebHttpBinding GT;
<绑定名称=跨域crossDomainScriptAccessEnabled =真/>
< /&的WebHttpBinding GT;
<&basicHttpBinding的GT;
<绑定名称=BasicHttpBinding_ICustomerscloseTimeout =00:01:00openTimeout =00:01:00receiveTimeout =00:10:00的SendTimeout =00:01:00allowCookies =false的bypassProxyOnLocal =假hostNameComparisonMode =StrongWildcardMAXBUFFERSIZE =65536maxBufferPoolSize =524288maxReceivedMessageSize =65536messageEncoding =文本textEncoding =UTF-8transferMode =缓冲useDefaultWebProxy =真>
< readerQuotas MAXDEPTH =32maxStringContentLength =8192maxArrayLength =16384maxBytesPerRead =4096maxNameTableCharCount =16384/>
<安全模式=无>
<运输clientCredentialType =无proxyCredentialType =无的境界=/>
<消息clientCredentialType =用户名algorithmSuite =默认/>
< /安全>
< /&结合GT;
< / basicHttpBinding的>
< /绑定>
<客户端>
<端点地址=HTTP://本地主机:1112 /服务/ Customers.svc绑定=basicHttpBinding的bindingConfiguration =BasicHttpBinding_ICustomers合同=CustomersService.ICustomersNAME =BasicHttpBinding_ICustomers/>
< /客户>
< serviceHostingEnvironment aspNetCompatibilityEnabled =真/>
< /system.serviceModel>
I have the following code:
which return me the following exception:
ProtocolException was unhandled by user code
The remote server returned an unexpected response: (405) Method Not Allowed.
I tried using the following command (Using Administrator
in a Command Prompt):
C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation>ServiceModelReg.exe -i
and the following appear:
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)
However, the exception is still there!
Appreciate any advices.
(Could it be due to .NET Framework?)
I tried the following:
C:\Windows\Microsoft.NET\Framework\v4.0.30319>ServiceModelReg.exe -i
but it return me the following:
[Error]Switch '-c' requires a component to be specified for installation or uninstallation. Please specify which components to install or uninstall.
Appreciate any helpful advices.
Added Information
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
The following code is inside the <configuration>
in the web.config file:
<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>
Try adding the following line into your web.config.
<webHttpBinding>
<binding name="crossDomain" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
The final result will be as follows:
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="crossDomain" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
<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>
这篇关于远程服务器返回了意外的响应:(405)不允许的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!