2016-06-30 22 views
1

このエラーを修正しようとしていますが、同じエラーで別の同様の質問がありますが、行はrequest.ContentLength = 0;私の例外を修正してください。修正方法:リモートサーバーからエラーが返されました:(400)Bad Request

これは私のイメージコードです:

public ActionResult Index() 
{ 
    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US"); 
    Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); 
    string serviceUrl = string.Format(@"http://localhost:61940/Service1.svc/GetPlayer/"); 

    HttpWebRequest request = (HttpWebRequest) WebRequest.Create(serviceUrl); 
    request.Method = "POST"; 
    request.ContentType = @"application/json; charset=utf-8"; 
    request.ContentLength = 0; 

    HttpWebResponse response = (HttpWebResponse) request.GetResponse(); 
    Stream stream = request.GetRequestStream(); 
    StreamWriter reader = new StreamWriter(stream); 
} 

と、これは私のweb.configファイル

<system.serviceModel> 
    <services> 
    <!-- This section is optional with the default configuration introduced 
     in .NET Framework 4. --> 
     <service name="WCF_Example.Service1" behaviorConfiguration="mexBehavior"> 
      <host> 
      <baseAddresses> 
       <add baseAddress="http://localhost:61940/"/> 
      </baseAddresses> 
      </host> 
      <endpoint address="WCF_ServiceExample" binding="basicHttpBinding" contract="WCF_Example.IService1" /> 
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     </service> 
    </services> 

    <bindings> 
     <basicHttpBinding>   
      <binding name="transportSecurity"> 
      <security mode="TransportWithMessageCredential"> 
       <message clientCredentialType="UserName" /> 
      </security> 
      </binding> 
     </basicHttpBinding> 
    </bindings> 

    <!--For debugging purposes set the includeExceptionDetailInFaults attribute to true--> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="mexBehavior"> 
      <serviceMetadata httpGetEnabled="True"/> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 

任意のヘルプですか?答えをありがとう。

、これが私の契約

[ServiceContract] 
public interface IService1 
{ 

    [OperationContract] 
    [WebInvoke(UriTemplate = "GetPlayer", ResponseFormat = WebMessageFormat.Json)] 
    Player GetPlayer(); 

    [OperationContract] 
    CompositeType GetDataUsingDataContract(CompositeType composite); 

    // TODO: Add your service operations here 
} 
+0

'リモートサーバからエラーが返されました:(400)Bad Request'これは、多くの理由が考えられます。あなたのエラーページのスクリーンショットを取ってOPに加えることができるなら、その方が優れています。今のところ私の推測はあなたのlocalhostアプリケーションの認証に関連するものでしょう。 –

答えて

0

あるweb.configファイルを右クリックして診断のオプションを有効にして、「編集WCFの設定」メニューを選択してください。

これにより、アプリケーションパスに2つのログファイルが作成されます。

「* _web_tracelog.svclog」ファイルを確認すると、そこに実際のエラーメッセージが表示されます。

0

googleを使用している間に私はいつもエラー400を取得し始めました。「翻訳する」ので、すべてのCookieを削除して履歴ETCを検索しました。最後のMONTHは2分かかった。 - 非常に科学的ではありませんが、 "翻訳"は再び機能します。

関連する問題