2013-01-14 72 views
0

我有以下代碼:遠程服務器返回了意外的響應:(405)不允許的方法

這回我以下異常:

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框架?)

我試過如下:

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> 
+0

你叫什麼方法? 什麼是你的綁定? – TGlatzer

+0

請不要用標籤堆疊標題,這不是必需的。 – slugster

+0

@ Grumbler85,我在我的問題中增加了額外的信息。 – Jack

回答

1

嘗試將以下行添加到您的web.config中。

<webHttpBinding> 
    <binding name="crossDomain" crossDomainScriptAccessEnabled="true" /> 
    </webHttpBinding> 

,最終的結果如下:

<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> 
+0

嗯 - 我不知道錯誤可能是這樣的。 – TGlatzer

+0

@ Grumbler85,是的,我也覺得很奇怪。通過只添加代碼,錯誤消息消失,但出現一個新的錯誤消息,如下所示 - http://stackoverflow.com/questions/14314556/could-not-load-file-or-assembly-app-web-1btizmpz – Jack

1

錯誤是不允許的方法。我沒有看到代碼中的任何地方,您在代理上設置用戶名/密碼組合...可能就是這樣嗎?

相關問題