Ich versuche, diesen Fehler zu beheben, ich weiß, dass es andere ähnliche Fragen mit dem gleichen Fehler gibt, aber die Zeile: request.ContentLength = 0;
es nicht behebe meine Ausnahme.WIE ZU FIX: Der Remote-Server hat einen Fehler zurückgegeben: (400) Bad Request
Das ist mein Bild Code:
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);
}
und das ist mein 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>
jede mögliche Hilfe? Danke für die Antworten.
und dies ist mein Vertrag
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebInvoke(UriTemplate = "GetPlayer", ResponseFormat = WebMessageFormat.Json)]
Player GetPlayer();
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
// TODO: Add your service operations here
}
'Der Remote-Server hat einen Fehler zurückgegeben: (400) Ungültige Anforderung 'Dies kann verschiedene Ursachen haben. Es ist besser, wenn Sie einen Screenshot Ihrer Fehlerseite machen und zum OP hinzufügen können. Wie jetzt meine Vermutung wäre etwas im Zusammenhang mit der Authentifizierung Ihrer localhost-Anwendung. –